Answers.Body: <blockquote>
  <p>which, conveniently enough, have their IDs in a range</p>
  </blockquote>
  <p>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.</p>
  <p>I would suggest avoiding <code>sra</code> and <code>fastq(er)-dump</code> altogether and use <a href="https://www.ebi.ac.uk/ena/browser/home" rel="nofollow noreferrer">ena</a> instead.</p>
  <p>In your case, it seems you want the runs in project PRJDB7736. From here <a href="https://www.ebi.ac.uk/ena/browser/view/PRJDB7736" rel="nofollow noreferrer">https://www.ebi.ac.uk/ena/browser/view/PRJDB7736</a> you can get a tabular file (see link in <em>Download report ... TSV</em>) with the sample characteristics. Column <code>fastq_ftp</code> gives you the ftp link to the fastq files that you can pass to <code>wget</code> or <code>curl</code>.</p>
  <p>You can also get the same report programmatically with:</p>
  <pre><code>curl -s -X GET &quot;https://www.ebi.ac.uk/ena/portal/api/filereport?accession=PRJDB7736&amp;fields=run_accession,sample_description,library_name,library_layout,fastq_ftp&amp;result=read_run&quot; &gt; ena.tsv
  </code></pre>
  <p>You should edit the <code>fields=...</code> list to suite your needs. The fields available are those from:</p>
  <pre><code>curl -X GET &quot;https://www.ebi.ac.uk/ena/portal/api/returnFields?dataPortal=ena&amp;result=read_run&quot;
  </code></pre>
  <p>I don't know what you think... I find this route much more useful and transparent than sra's.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-10T16:02:54.917Z
Answers.LastActivityDate: 2020-08-10T16:08:14.737Z
Answers.LastEditDate: 2020-08-10T16:08:14.737Z
Answers.UserDisplayName: dariober
Answers.Body: <p>You have an obvious error in your shell script that should have given you an error message:</p>
  <pre><code>sra_code = &quot;DRR163&quot;&quot;$i&quot;
  </code></pre>
  <p>Should be:</p>
  <pre><code>sra_code=&quot;DRR163&quot;&quot;$i&quot;
  </code></pre>
  <p>You cannot have spaces around the <code>=</code> sign in a variable assignment. The line <code>sra_code = &quot;DRR163&quot;&quot;$i&quot;</code> means &quot;run the command <code>sra_code</code> with the arguments <code>= &quot;DRR163&quot;&quot;$i&quot;</code>. Since there is no such command, you see an error.</p>
  <p>Here's a working version of your command:</p>
  <pre><code>for i in {256..345}; do 
      sra_code=&quot;DRR163<span class="math-container">$i"
      fasterq-dump "$</span>sra_code&quot; -p -v --outdir ./output/ -e 8
  done
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-05T10:25:33.053Z
Answers.LastActivityDate: 2020-08-05T13:51:11.723Z
Answers.LastEditDate: 2020-08-05T13:51:11.723Z
Answers.UserDisplayName: terdon
Body: <p>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:</p>
  <pre><code>for i in {256..345};do
      sra_code = &quot;DRR163&quot;&quot;<span class="math-container">$i"
  fasterq-dump "$</span>sra_code&quot; -p -v --outdir ./output/ -e 8 
  
  done
  <span class="math-container">```</span>
  </code></pre>
  
Tags: <bash><sratoolkit><fastq-dump>
Title: Using variables with fasterq-dump?
ThreadText: # Using variables with fasterq-dump?
  
  (Asked by: username_0 on 2020-08-05)
  
  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
  ```
  
  ```
  
  **Tags:** bash, sratoolkit, fastq-dump
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-08-05. Score: 5 | Accepted answer
  
  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
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2020-08-10. Score: 0
  
  > 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](https://www.ebi.ac.uk/ena/browser/home) 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.
  
  
  ---
  
  