Take the 2-minute tour ×
Biology Stack Exchange is a question and answer site for biology researchers, academics, and students. It's 100% free, no registration required.

I have a list of ENA accession numbers and a start and end position in each sequence. In the end I want to align all those sequences, but first I have to fetch them and the list is too long to do that manually.

Is there any existing tool or script that can fetch all those entries from a database and extract the correct subset of the sequence?

share|improve this question
    
Could you show us a sample of the file? What's the format like? What operating system are you using? You will probably need to download each sequence and then extract the subsequence, all of which is easy enough but the details depend on how your information is formatted and the system you are using. –  terdon Feb 15 at 14:32

2 Answers 2

up vote 3 down vote accepted

I will edit this if you update your question with more information, but for the moment I am assuming you have access to a Linux/Unix system and that your file of accessions looks like this:

A00145.1 123  456

Where the first column is the accession and the next two are the start and end of the region of interest. So, using the same basic approach as WYSIWIG's answer, you can combine this with fastasubseq from the exonerate suite of tools (on Debian based systems, which include Ubuntu and Mint, you can install by runnning sudo apt-get install exonerate). Just copy/paste this into your terminal:

while read acc start end; do 
  wget -q -O "$acc".fa "http://www.ebi.ac.uk/ena/data/view/$acc&display=fasta" &&
  fastasubseq "$acc".fa $start $end > $acc.$start-$end.fa
  rm "$acc".fa 
done < list.txt

With the example above, this command will create a file called A00145.1.123-456.fa which contains the subsequence of A00145.1 from positions 123 to 456. Since it first needs to download the entire sequence, it also creates the temporary file A00145.1.fa which is deleted by rm "$acc".fa. If you want to keep the file, just remove the rm line.

If you can't install exonerate, you can also extract the subsequence manually but that's a bit more complex:

while read acc start end; do 
 wget -q -O "$acc".fa "http://www.ebi.ac.uk/ena/data/view/$acc&display=fasta" && 
awk -v st=$start -v end=$end '{
                               if($1~/>/){print}else{s=s$0}}END{print substr(s,st,end)
                              }'  $acc.fa | 
 fold -w 60 > "$acc.$start-$end.fa" && rm "$acc".fa 
done < list.txt 

I think explaining these scriptlets in detail is not in scope here but I'd be happy to do so if you post a question over on unix & linux.

share|improve this answer

From ENA

To retrieve results by a single identifier for all records other than Taxon and Project please, use the following URL syntax:

http://www.ebi.ac.uk/ena/data/view/

For example, the following URL returns the EMBL-Bank entry with accession number A00145 in HTML format: http://www.ebi.ac.uk/ena/data/view/A00145

Check this.

If you use a *nix system (such as Linux, Unix, or OSX) then you can do this:

[ if list.txt contains all your ids ]

for i in `cat list.txt`; do wget -q -O $i".fa" "http://www.ebi.ac.uk/ena/data/view/"$i"&display=fasta"; done

OR ELSE

Download the entire database and pick up sequences based on your identifiers, offline. You can use your favorite programming language to retrieve sequences. [i prefer awk but python is also good]

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.