0
$\begingroup$

I am trying to download multiple fastq files from the SRA NCBI database which, conveniently enough, have their IDs in a range. Building a simple loop doesn't seem to do the trick, as bash appears to interpret my variable as an additional command? Help would be appreciated. This is what I have for now:

for i in {256..345};do
    sra_code = "DRR163""$i"
fasterq-dump "$sra_code" -p -v --outdir ./output/ -e 8 

done
```
$\endgroup$
5
$\begingroup$

You have an obvious error in your shell script that should have given you an error message:

sra_code = "DRR163""$i"

Should be:

sra_code="DRR163""$i"

You cannot have spaces around the = sign in a variable assignment. The line sra_code = "DRR163""$i" means "run the command sra_code with the arguments = "DRR163""$i". Since there is no such command, you see an error.

Here's a working version of your command:

for i in {256..345}; do 
    sra_code="DRR163$i"
    fasterq-dump "$sra_code" -p -v --outdir ./output/ -e 8
done
| improve this answer | |
$\endgroup$
0
$\begingroup$

which, conveniently enough, have their IDs in a range

I think it's a bit risky to rely on that - for this particular case they are not going to change but you may need to download more samples in the future.

I would suggest avoiding sra and fastq(er)-dump altogether and use ena instead.

In your case, it seems you want the runs in project PRJDB7736. From here https://www.ebi.ac.uk/ena/browser/view/PRJDB7736 you can get a tabular file (see link in Download report ... TSV) with the sample characteristics. Column fastq_ftp gives you the ftp link to the fastq files that you can pass to wget or curl.

You can also get the same report programmatically with:

curl -s -X GET "https://www.ebi.ac.uk/ena/portal/api/filereport?accession=PRJDB7736&fields=run_accession,sample_description,library_name,library_layout,fastq_ftp&result=read_run" > ena.tsv

You should edit the fields=... list to suite your needs. The fields available are those from:

curl -X GET "https://www.ebi.ac.uk/ena/portal/api/returnFields?dataPortal=ena&result=read_run"

I don't know what you think... I find this route much more useful and transparent than sra's.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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