Question: Extract Out The Row Containing Accession Number
0
gravatar for bhojpuri song download
6.4 years ago by
bhojpuri song download10 wrote:

I have accession numbers like this

AT2G41490
AT3G57220
AT2G39630
AT4G16710
AT4G18230
AT1G20575
AT1G74340
AT1G48140
AT1G16570
AT1G78800
AT2G40190
AT5G07630
AT2G47760
AT1G16900
AT1G02145
AT5G38460
AT2G44660

ant my table look like this

APK_ORTHOMCL3128    10    7    arabidopsis brachy grapevine maize poplar rice sorghum    AT2G41490 AT3G57220 Bradi1g18800 GRMZM2G137707 GRMZM5G827205 GSVIVG00033552001 LOC_Os07g46640 POPTR_0006s04420 POPTR_0016s04160 Sb02g041960
APK_ORTHOMCL3129    10    7    arabidopsis brachy grapevine maize poplar rice sorghum    AT2G42130 AT3G58010 Bradi5g25350 GRMZM2G124466 GRMZM2G371944 GSVIVG00033499001 LOC_Os04g57020 POPTR_0006s20660 POPTR_0016s04520 Sb06g032010
APK_ORTHOMCL3130    10    6    arabidopsis brachy maize poplar rice sorghum    AT2G42310 AT3G57785 Bradi4g33650 GRMZM2G132748 GRMZM2G137139 LOC_Os09g31260 POPTR_0006s05570 POPTR_0016s05190 Sb02g028260 Sb07g027870

I want to extract out the all row containing the accession numbers. Folllowing perl script is working fine for single accession number but I want to modify it for batch queries. plzz help me

    #!/usr/bin/perl


$filename = "apk.txt";

open FILE,"<$filename" or die "Cannot read the file $filename: $!\n";

while ($line = <FILE>)
{
    if ($line =~ m/AT2G41490/)
    {
        print $line;
    }
}
sequence • 1.3k views
ADD COMMENTlink modified 6.4 years ago by Vivek2.3k • written 6.4 years ago by bhojpuri song download10
1

Additionally to Pierre's answer check this question Extract according to row .
And your question is more programming related than bioinformatics so for similar code line problems, I suggest asking for help at http://stackoverflow.com/ (for example: http://stackoverflow.com/questions/11490036/fast-alternative-to-grep-f).

ADD REPLYlink modified 6.4 years ago • written 6.4 years ago by PoGibas4.8k

Thanks for everyone for answers and suggestion. Since I am a window lover therefore I found another easy solution to do that. I used FINDSTR command to perform this job.

ADD REPLYlink written 6.4 years ago by bhojpuri song download10
0
gravatar for Pierre Lindenbaum
6.4 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum123k wrote:

the anwser is not in perl but in sort and join

duplicate of How to join text files by a certain column (accession id)

ADD COMMENTlink written 6.4 years ago by Pierre Lindenbaum123k
0
gravatar for Vivek
6.4 years ago by
Vivek2.3k
Denmark
Vivek2.3k wrote:

Can't a simple grep do the job instead of a perl script?

for acc_no in `cat accessions.txt`;do grep -w $acc_no table.txt;done
ADD COMMENTlink written 6.4 years ago by Vivek2.3k

Unless table.txt is very small, you'd be re-reading this file for each line in it. Setting up a hash/lookup table with Perl/Python/etc. is usually within reach of modern workstations and will calculate a solution much, much faster.

ADD REPLYlink modified 6.4 years ago • written 6.4 years ago by Alex Reynolds29k

A solution would be grep -w -F -f accessions.txt table.txt

ADD REPLYlink written 6.4 years ago by Frédéric Mahé3.0k

Well, I'm most likely lazy enough to use a one-liner.

ADD REPLYlink modified 6.4 years ago • written 6.4 years ago by Vivek2.3k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2343 users visited in the last hour