Question: Bash Script To Bp_Fetch A List Of Cds Acession Numbers
0
gravatar for eddie.im
5.4 years ago by
eddie.im130
Brazil
eddie.im130 wrote:

Hello,

I'm trying to write a bash script to use bioperl bash command bp_fetch and return a CDS list in fasta format. I have installed bioperl and bp_fetch works as intended: xxxx@xxxx:~/Documents$ bp_fetch net::embl:AAA24658.1

AAA24658 Escherichia coli hypothetical protein ATGGAACGTTGCGGCTGGGTGAGTCAGGACCCGCTTTATATTGCCTACCATGATAATGAG TGGGGCGTGCCTGAAACTGACAGTAAAAAACTGTTCGAAATGATCTGCCTTGAAGGGCAG CAGGCTGGATTATCGTGGATCACCGTCCTCAAAAAACGCGAAAACTATCGCGCCTGCTTT CATCAGTTCGATCCGGTGAAGGTCGCAGCAATGCAGGAAGAGGATGTCGAAAGACTGGTA CAGGACGCCGGGATTATCCGCCATCGAGGGAAAATTCAGGCAATTATTGGTAATGCGCGG GCGTACCTGCAAATGGAACAGAACGGCGAACCGTTTGTCGACTTTGTCTGGTCGTTTGTA AATCATCAGCCACAGGTGACACAAGCCACAACGTTGAGCGAAATTCCCACATCTACGTCC GCCTCCGACGCCCTATCTAAGGCACTGAAAAAACGTGGTTTTAAGTTTGTCGGCACCACA ATCTGTTACTCCTTTATGCAGGCATGTGGGCTGGTGAATGATCATGTGGTTGGCTGCTGT TGCTATCCGGGAAATAAACCATGA

The problem is that i have a file with long list of acession numbers, and i'm trying to do a bash script to run "bp_fetch net::" with every line of the file (each line has an acession number) and output the list of FASTA CDS's in a txt file. I have tried something like:

for line in $file do bp_fetch net::$line

But i'm having no sucess. Can i get some help? Thanks in advance.

cds bioperl bash • 1.8k views
ADD COMMENTlink modified 4.6 years ago by Biostar ♦♦ 20 • written 5.4 years ago by eddie.im130
1
gravatar for Frédéric Mahé
5.4 years ago by
France, Montpellier, CIRAD
Frédéric Mahé2.9k wrote:

You can try something like that (assuming the accessions are listed in the file accessions.list):

while read accession_number ; do bp_fetch net::${accession_number} ; done < accessions.list > results.txt

Note that you can inject the list of accessions at the end of the while loop (< accessions.list), and collect the results in a new file (> results.txt).

ADD COMMENTlink written 5.4 years ago by Frédéric Mahé2.9k

Hey Frédéric, thanks a lot! Your script worked flawlessly! :)

ADD REPLYlink written 5.4 years ago by eddie.im130
1
gravatar for lh3
5.4 years ago by
lh331k
United States
lh331k wrote:
cat accessions.list | xargs -i echo bp_fetch net::{} | sh > results.txt

I use the above command line more often as I can check whether the command line is correct before feeding is to sh. The shorter version is:

xargs -i bp_fetch net::{} < accessions.list > results.txt

I believe you can also give bp_fetch multiple accessions in the command line. In that case:

cat accessions.list | sed s,^,net::, | xargs bp_fetch > results.txt
ADD COMMENTlink modified 5.4 years ago • written 5.4 years ago by lh331k
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: 743 users visited in the last hour