Re: find a first column value ...




BD wrote:
203252 GB|AI461105 GB|AI900630 GB|AI900894 GB|AI901187
203253 GB|AI736220 GB|AW780891 GB|BE806781 GB|BG157087
203254 GB|AI440899 GB|AW185396 GB|AW185458 GB|AW152990
203255 GB|AI416923 GB|AI437726 GB|AI437966 GB|AI438062
203256 GB|AI441714 GB|AI930592 GB|AI855868 GB|AI856032

I am new with perl and my problam is if I give any accession no like
AW780891
than it should find the first column value like 203253.
IS any Module there to do this type of work ?

What "type of work"? You mean parse a file and build an index? That's
rather general. So general that the interface to the module would be
close in complexity to a general programming language. But you apready
have a general purpose prgramming language - Perl. So just do it.

Actually for more complex parrsing tasks there are numerous modules to
help you, but even implementing the simplest grammar in, say,
Parse::RecDescent is orders of mangnitude more complex than your
starting problem.

Of course your problem is badly underspecified - what for example is
the significance of the string 'GB|'? Is the mapping many-to-one or
many-to-many? Where is the data comining from? Are you going to do one
look up or several?

use strict;
use warnings;

my %accession_index;

while (<DATA>) {
chomp;
my ($number, @accessions) = split;
$accession_index{$_}=$number for @accessions;
}

my $accession_number='AW780891';

print $accession_index{'GB|'.$accession_number},"\n";

__DATA__
203252 GB|AI461105 GB|AI900630 GB|AI900894 GB|AI901187
203253 GB|AI736220 GB|AW780891 GB|BE806781 GB|BG157087
203254 GB|AI440899 GB|AW185396 GB|AW185458 GB|AW152990
203255 GB|AI416923 GB|AI437726 GB|AI437966 GB|AI438062
203256 GB|AI441714 GB|AI930592 GB|AI855868 GB|AI856032

.