Click here to get back home

find a first column value ...

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
find a first column value ... BD 05-19-2006
Posted by BD on May 19, 2006, 12:54 pm
Please log in for more thread options


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.


Posted by Brian McCauley on May 19, 2006, 1:22 pm
Please log in for more thread options



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,"\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


Posted by Dr.Ruud on May 19, 2006, 4:36 pm
Please log in for more thread options


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 ( <DATA> )
{
/ ^ (\d+) .* [ ]GB[|] $ [ ] /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."



Posted by BD on May 23, 2006, 1:20 pm
Please log in for more thread options



Thanks :)


Similar ThreadsPosted
Find Missing Column and Extra Column March 12, 2007, 6:33 am
Win32::ODBC Find Primary Key Column February 6, 2005, 8:21 pm
Everything but the column: win32::OLE Excel fun June 7, 2006, 9:07 pm
HTML::TableExtract with headers constraint, exluding right-most column May 15, 2005, 3:31 pm
Cant find pmtools December 9, 2004, 8:11 pm
What is endian.h? and How can I find it? February 15, 2005, 12:50 pm
Can't find loadable object November 19, 2004, 1:05 pm
Help: "find command in windows" July 23, 2005, 1:25 pm
File::Find on Solaris v8-10 August 1, 2005, 11:06 am
WWW::Mechanize cannot find the form. February 14, 2006, 9:04 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap