in reply to Re^4: Compare hash with arrays and print
in thread Compare hash with arrays and print
I want to write the complete header line (starting with '>') in my output files. Can I use the split function ...?
Sure you can use the split function, but if you just want to print the header line as is (i.e. copy it from the input), you wouldn't need to split up the record. As you have it, the header would be printed already without further ado. Think of it this way: $_ holds an entire record, with the leading '>' removed (to more easily handle the edge cases that result from the way the input is being split by $/). For example, for the first record, $_ would hold the string (including the newlines)
"aw1.a1 bhi|tn|56564 pairs:40098 ATGCTAGATGCTAGCTAGCTAGCACTGAT CGATGCTAGCGTAGTCAGCTGATGCTGTA CGATGCTAGTCGTACG "
You can do with it whatever you like before you print it out, e.g. take it apart using split or via regex captures, perform regex substitutions on it, etc.
Some more notes: The key for the hash is extracted via regex capture
my ($name) = /^(\w+)/;
which would extract "aw1" in this case, because \w+ stops matching at the dot. In case you'd need to extract keys as "aw1.a1" (or some such — I'm no fasta expert), you could modify the regex to also capture the dots
my ($name) = /^([\w.]+)/;
or up until the first whitespace char in the line
my ($name) = /^(\S+)/;
Or in case you'd want to print the headers only (which I'm not quite sure from your description), you could extract it similarly with a regex
my ($header) = /^([^\n]+)/;
or by splitting on newlines
my ($header) = split /\n/;
And so on...
Hope this gives you some starting points to tailor it to your specific requirements.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Compare hash with arrays and print
by ad23 (Acolyte) on Jul 13, 2010 at 17:56 UTC | |
by almut (Canon) on Jul 13, 2010 at 18:23 UTC | |
by ad23 (Acolyte) on Jul 13, 2010 at 19:00 UTC | |
by almut (Canon) on Jul 13, 2010 at 19:25 UTC | |
by ad23 (Acolyte) on Jul 13, 2010 at 21:19 UTC | |
by ad23 (Acolyte) on Jul 14, 2010 at 13:32 UTC |