I'm trying to write a perl program that will split up a fasta header:
gi|4140243|dbj|AB022087.1|_Xenopus_laevis_mRNA_for_cytochrome_P450,_complete_cds,_clone_MC1
Into it's |
seperated parts:
gi
4140243
dbj
AB022087.1
_Xenopus_laevis_mRNA_for_cytochrome_P450,_complete_cds,_clone_MC1
I can do this using split
:
my @hits = split(/\|/, $hits);
my ($gi, $number, $gb, $id, $name);
foreach (@hits) {
$gi.= "$hits[0]\n";
$number .= "$hits[1]\n";
$gb .= "$hits[2]\n";
$id .= "$hits[3]\n";
$name .= "$hits[4]\n";
}
my @gi = split('\n', $gi);
my @number = split('\n', $number);
my @gb = split('\n', $gb);
my @id = split('\n', $id);
my @name = split('\n', $name);
Now each part of each header (contained in $hits
) is an element in an individual array. What I want to do next is print back each element of each array so that I can produce a list of element[0] for each array, element[1] for each array...
I'm unsure as to whether this will require a hash of hashes or array of arrays.
I'm fairly new to perl so any suggestions would be greatly helpful.
I'm also aware that the above might not be the slickest way of achieving what I want - again any comments would be great!