Hi everyone,
I'm trying to write a perl programme that will split up a .fasta header:
gi|4140243|dbj|AB022087.1|_Xenopus_laevis_mRNA_for_cytochrome_P450,_complete_cds,_clone_MC1
Into its constituent parts:
gi
4140243
dbj
AB022087.1
_Xenopus_laevis_mRNA_for_cytochrome_P450,_complete_cds,_clone_MC1
This is easily achieved using:
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 element[0] for each array so that I can reproduce the original $hits (which I then want to modify).
I'm unsure as to whether this will require a hash of hashes or array of arrays.
I'm fairly new to perl to 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!
Many thanks,
N
I'm trying to write a perl programme that will split up a .fasta header:
gi|4140243|dbj|AB022087.1|_Xenopus_laevis_mRNA_for_cytochrome_P450,_complete_cds,_clone_MC1
Into its constituent parts:
gi
4140243
dbj
AB022087.1
_Xenopus_laevis_mRNA_for_cytochrome_P450,_complete_cds,_clone_MC1
This is easily achieved using:
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 element[0] for each array so that I can reproduce the original $hits (which I then want to modify).
I'm unsure as to whether this will require a hash of hashes or array of arrays.
I'm fairly new to perl to 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!
Many thanks,
N
Comment