erio has asked for the wisdom of the Perl Monks concerning the following question:
If both data types exist for a species, I would like to append the morph data to the dna data. If a species is missing one of the data types, I would like to append as many "?"s as there are elements in the missing data partition:File#1 dna: species_1 ACCATGATACGATG species_2 GGTTTCGACGCAGA species_3 GGACTCAGCGACTA File#2 morph: species_1 001001010201001001 species_2 002010200210120201 species_4 001001110000000101 species_5 111001001001000201
I am completely new to Perl. What is the best strategy here? I tried constructing an hash of anonymous array refs:species_1 ACCATGATACGATG001001010201001001 species_2 GGTTTCGACGCAGA002010200210120201 species_3 GGACTCAGCGACTA?????????????????? species_4 ??????????????001001110000000101 species_5 ??????????????111001001001000201
Here, I couldn't figure out how to recognize if one of the partitions is missing and fill it with "?"s. My hash of de-refed arrays looked like this:open IN, "dnamorph.txt" or die $!; my %data; my $taxon; while (<IN>) { if (/(^\w+)(\t+)(\w+)/) { $taxon = $1; push @{ $data{$taxon} }, $3; } }
I also tried to make a hash of hashes for each data partition, eg:species_1 ACCATGATACGATG001001010201001001 species_2 GGTTTCGACGCAGA002010200210120201 species_3 GGACTCAGCGACTA species_4 001001110000000101 species_5 111001001001000201
My data looks likes this:open DNAA, "dna.nxs" or die $!; my %ddata; while (<DNAA>) { if (/(^\w+)(\t+)(\w+)/) { $ddata{ $1} = { dna => $3, }; } }
Here, I can't figure out how to combine the 2 hashes of hashrefs without clobbering some values. Any help would be much apreciated, eriospecies_six: dna=TTGGGACAGCCGAGGCACGA species_two: dna=AAAATCGGGCGGCGCTTTTC species_five: dna=TTCCAGGACATCGGCATACG species_three: dna=GGGGCCCCAATATCGATACG species_four: dna=GGGGAGGACGTAGATATTAT species_one: dna=ACTGTTTCGTAGGGCTAGGA species_two: morph=111101011011011 species_five: morph=111101011011011 species_three: morph=012111011011011 species_four: morph=112111011011011 species_one: morph=110111011011111
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Combining hashes of hahses?
by GrandFather (Saint) on Nov 07, 2007 at 00:37 UTC | |
by erio (Initiate) on Nov 07, 2007 at 18:38 UTC | |
by GrandFather (Saint) on Nov 07, 2007 at 19:53 UTC | |
by erio (Initiate) on Nov 08, 2007 at 01:03 UTC | |
by convenientstore (Pilgrim) on Nov 07, 2007 at 21:48 UTC | |
by GrandFather (Saint) on Nov 07, 2007 at 22:09 UTC | |
by convenientstore (Pilgrim) on Nov 07, 2007 at 22:20 UTC | |
|
Re: Combining hashes of hahses?
by tuxz0r (Pilgrim) on Nov 07, 2007 at 17:22 UTC | |
by erio (Initiate) on Nov 07, 2007 at 18:41 UTC |