find a first column value ...

find a first column value ...

am 19.05.2006 18:54:00 von BD

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 ?
Thanks.

Re: find a first column value ...

am 19.05.2006 19:22:21 von nobull67

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 () {
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

Re: find a first column value ...

am 19.05.2006 22:36:38 von rvtol+news

BD schreef:

> if I give any accession no like AW780891
> than it should find the first column value like 203253.

If you only need to find one value per run:

#!/usr/bin/perl
use strict;
use warnings;

while ( )
{
/ ^ (\d+) .* [ ]GB[|] ${ARGV[0]} [ ] /x
and print "$1\n" and exit(0)
}
exit(1)

__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


--
Affijn, Ruud

"Gewoon is een tijger."