AWallBuilder has asked for the wisdom of the Perl Monks concerning the following question:
Dear all, I am familiar with how to read in a table, parse the columns and create hashes holding the data . However, now I am dealing with input files where related variables are contained in subsequent rows as opposed to in the same column. Now, I am having a seemingly simple problem that my parsing logic doesn't seem to work anymore. It might be an error to do with when I initialize my variables, or what? Any help is appreciated.
sample input data
# UNIQUE-ID - GJDZ-5046 TYPES - BC-4 TYPES - Unclassified-Genes COMMON-NAME - STM14_5042 ACCESSION-1 - STM14_5042 CENTISOME-POSITION - 90.96536 COMPONENT-OF - CHROMOSOME-1-100 COMPONENT-OF - TUJDZ-2494 COMPONENT-OF - CHROMOSOME-1 LEFT-END-POSITION - 4430254 PRODUCT - GJDZ-5046-MONOMER RIGHT-END-POSITION - 4430427 TRANSCRIPTION-DIRECTION - - // UNIQUE-ID - GJDZ-1101 TYPES - BC-4 TYPES - Unclassified-Genes COMMON-NAME - focA ACCESSION-1 - STM14_1100 CENTISOME-POSITION - 20.85712 COMPONENT-OF - CHROMOSOME-1-23 COMPONENT-OF - TUJDZ-587 COMPONENT-OF - CHROMOSOME-1 LEFT-END-POSITION - 1015797 PRODUCT - GJDZ-1101-MONOMER RIGHT-END-POSITION - 1016774 TRANSCRIPTION-DIRECTION - - //
snippet of code that gives wrong results
my %Ho14Loc2GeNm; while(my $lines=<IN>){ my $cycID14; my $cycLoc14;my $cycNm14; next unless (($lines =~/^UNIQUE-ID/) || ($lines=~/^ACCESSION-1 +/)|| ($lines=~/^COMMON-NAME/)); chomp $lines; if ($lines =~ /^UNIQUE-ID/){ $lines=~/(GJDZ-[0-9]+)/; $cycID14=$1; } if ($lines =~ /^COMMON-NAME/){ $lines=~/COMMON-NAME - (\S+)/; $cycNm14=$1; } if ($lines =~ /^ACCESSION-1/){ $lines=~/(STM14_[0-9]+)/; $cycLoc14=$1; } if (defined($cycLoc14)){ $Ho14Loc2GeNm{$cycLoc14}=$cycNm14; } } print Dumper(%Ho14Loc2GeNm); close(IN);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing line by line
by Eily (Monsignor) on Jan 14, 2015 at 14:02 UTC | |
by AWallBuilder (Beadle) on Jan 14, 2015 at 14:53 UTC | |
|
Re: Parsing line by line
by choroba (Cardinal) on Jan 14, 2015 at 13:57 UTC | |
by AWallBuilder (Beadle) on Jan 14, 2015 at 14:42 UTC | |
|
Re: Parsing line by line
by hdb (Monsignor) on Jan 15, 2015 at 10:49 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |