Boz has asked for the wisdom of the Perl Monks concerning the following question:
Hi i'm a new initiate seeking absolution about concatenating to keys within a hash. I have read that this is not allowed therefore i would ask the revered monks what approach i should take. I have been trying to understand hash referencing but this seems division one whilst i'm still playing Sunday league.
The hash %bact contains sequences as values and unique identifiers as keys. I am trying to add subsets to the unique identifiers in the keys and counts to the subsets
e.g. keys :- UniqueID_set1_0001, UniqueID_set1_0002, UniqueID_set1_0003, UniqueID_set2_0001.............Perhaps someone could suggest a simpler way to do it or point me in the right direction about "hard referencing" . The documentation goes off on some very confusing tangents about this for a newbie.
I get no substitutions taking place either with "Use of uninitialized value in substitution (s///) error messages". I have tried searching the web .. this seems to be a common error message caused by many things and after spending hours trying to understand what's wrong i became a convert and decided to turn to the monastery for enlightenment. For any help gratefully received i would be truly thankful. Amen
#! /usr/bin/perl -w use strict; $set1count=000; $set2count=000; $set3count=000; $set4count=000; $set5count=000; foreach my $id (keys %bact) { if (($bact{$id} =~ m/^CAGGTGGCAT/)) { s/^CAGGTGGCAT//; $id .='_set1_'; $set1count++; $id .=$set1count; } elsif (($bact{$id} =~ m/^CATTGAAGCT/)) { s/^CATTGAAGCT//; $id .='_set2_'; $set2count++; $id .=$set2count; } elsif (($bact{$id} =~ m/^CTAAGTTCAG/)) { s/^CTAAGTTCAG//; $id .='_set3_'; $set3count++; $id .=$set3count; } elsif (($bact{$id} =~ m/^CTAAGAACGT/)) +{ s/^CTAAGAACGT//; $id .='_set4_'; $set4count++; $id .=$set4count; } else { s/^CTGGAGGACT//; $id .='_set5_'; $set5count++; $id .=$set5count; } } print "------------------------------------------------------ +---------\n"; print "-------- ABUNDANCE OF SEQUENCES WTHIN EACH SUBGROUP - +---------\n"; print "number of sequences in set 1 CAGGTGGCAT sub group = $se +t1count \n"; print "number of sequences in set 2 CATTGAAGCT sub group = $se +t2count \n"; print "number of sequences in set 3 CTAAGTTCAG sub group = $se +t3count \n"; print "number of sequences in set 4 CTAAGAACGT sub group = $se +t4count \n"; print "number of sequences in set 5 CTGGAGGACT sub group = $se +t5count \n"; ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Concatenate to keys in a hash whilst doing substitution on values
by kennethk (Abbot) on Feb 11, 2010 at 20:41 UTC | |
|
Re: Concatenate to keys in a hash whilst doing substitution on values
by leocharre (Priest) on Feb 11, 2010 at 21:08 UTC |