text: user16902: I have generated several FASTQ files and I would like to know the amount of reads for each of them.
  I am planning to run FastQC on the files which I know would give me the number of reads per sample but it would be a lot easier for me if I could get one text file with the file name and number of reads for all samples together.
  When I check for one file I normally do zcat filename_R1.fastq.gz | wc -l and then divide by 4.
  Is there a way to do it for all my files at once and get a text file with the file name and reads at the end?
  For example I will have 71 R1.fastq.gz files and I would like to output the amount of reads to a text file. I just meant that I would prefer to use one command instead of having to use the command I mentioned above for each file.
  
  user14180: You can replace gunzip -c with zcat.
  #USAGE: script.sh /runFolder
  for i in $1/*.1.fastq.gz
  do
     echo "$i" $(gunzip -c $i | echo `wc -l`/4 | bc -l)
  done
  
  #OR in the current folder, do this:
  for i in ./*.1.fastq.gz
  do
     echo "$i" $(gunzip -c $i | echo `wc -l`/4 | bc -l)
  done
  
  
  user10775: One way would be to use seqkit stats, which can be installed using conda:
  conda install -c bioconda seqkit
  
  It has a number of useful options, including ways to parallelize the counting, using -j, --threads (default 4), and to skip errors using -e, --skip-err. The latter can be especially useful if you have a larger number of FASTQ files with millions of reads and you'd like to run the command overnight for example. There's also an option to produce a machine-friendly tabular output, using -T, --tabular which would allow you to parse the output without much effort. I'd be tempted to just write the output to a file using the -o, --out-file option:
  seqkit stats -To stats.tsv *.fastq.gz
  
  Example results:
  $ cat stats.tsv 
  file    format  type    num_seqs    sum_len min_len avg_len max_len
  PHB_Rep1_R1.fastq.gz    FASTQ   RNA 118571  11857100    100 100.0   100
  PHB_Rep1_R2.fastq.gz    FASTQ   RNA 118571  11857100    100 100.0   100
  PHB_Rep2_R1.fastq.gz    FASTQ   RNA 144826  14482600    100 100.0   100
  PHB_Rep2_R2.fastq.gz    FASTQ   RNA 144826  14482600    100 100.0   100
  PHB_Rep3_R1.fastq.gz    FASTQ   RNA 129786  12978600    100 100.0   100
  PHB_Rep3_R2.fastq.gz    FASTQ   RNA 129786  12978600    100 100.0   100
  PUH_Rep1_R1.fastq.gz    FASTQ   RNA 227392  22739200    100 100.0   100
  PUH_Rep1_R2.fastq.gz    FASTQ   RNA 227392  22739200    100 100.0   100
  PUH_Rep2_R1.fastq.gz    FASTQ   RNA 162373  16237300    100 100.0   100
  PUH_Rep2_R2.fastq.gz    FASTQ   RNA 162373  16237300    100 100.0   100
  PUH_Rep3_R1.fastq.gz    FASTQ   RNA 185442  18544200    100 100.0   100
  PUH_Rep3_R2.fastq.gz    FASTQ   RNA 185442  18544200    100 100.0   100
  
  And then just parse the output to get what you need, if or when you need it. For your specific requirements, you could just use AWK to skip the header line and print the first and fourth columns:
  awk 'BEGIN {FS=OFS="\t" } NR>1 { print $1, $4 }' stats.tsv
  
  Results:
  PHB_Rep1_R1.fastq.gz    118571
  PHB_Rep1_R2.fastq.gz    118571
  PHB_Rep2_R1.fastq.gz    144826
  PHB_Rep2_R2.fastq.gz    144826
  PHB_Rep3_R1.fastq.gz    129786
  PHB_Rep3_R2.fastq.gz    129786
  PUH_Rep1_R1.fastq.gz    227392
  PUH_Rep1_R2.fastq.gz    227392
  PUH_Rep2_R1.fastq.gz    162373
  PUH_Rep2_R2.fastq.gz    162373
  PUH_Rep3_R1.fastq.gz    185442
  PUH_Rep3_R2.fastq.gz    185442
  
  
original_text: 16902: <p>I have generated several FASTQ files and I would like to know the amount of reads for each of them.
  I am planning to run <a href="https://www.bioinformatics.babraham.ac.uk/projects/fastqc/" rel="nofollow noreferrer">FastQC</a> on the files which I know would give me the number of reads per sample but it would be a lot easier for me if I could get one text file with the file name and number of reads for all samples together.</p>
  <p>When I check for one file I normally do <code>zcat filename_R1.fastq.gz | wc -l</code> and then divide by 4.
  Is there a way to do it for all my files at once and get a text file with the file name and reads at the end?</p>
  <p>For example I will have 71 R1.fastq.gz files and I would like to output the amount of reads to a text file. I just meant that I would prefer to use one command instead of having to use the command I mentioned above for each file.</p>
   14180: <p>You can replace <code>gunzip -c</code> with <code>zcat</code>.</p>
     
  <pre class="lang-bash prettyprint-override"><code>#USAGE: script.sh /runFolder
  for i in <span class="math-container">$1/*.1.fastq.gz
  do
     echo "$</span>i&quot; <span class="math-container">$(gunzip -c $</span>i | echo `wc -l`/4 | bc -l)
  done
  
  #OR in the current folder, do this:
  for i in ./*.1.fastq.gz
  do
     echo &quot;<span class="math-container">$i" $</span>(gunzip -c $i | echo `wc -l`/4 | bc -l)
  done
  </code></pre>
   10775: <p>One way would be to use <a href="https://bioinf.shenwei.me/seqkit/usage/#stats" rel="noreferrer"><code>seqkit stats</code></a>, which can be installed using <code>conda</code>:</p>
  <pre><code>conda install -c bioconda seqkit
  </code></pre>
  <p>It has a number of useful options, including ways to parallelize the counting, using <code>-j</code>, <code>--threads</code> (default 4), and to skip errors using <code>-e</code>, <code>--skip-err</code>. The latter can be especially useful if you have a larger number of FASTQ files with millions of reads and you'd like to run the command overnight for example. There's also an option to produce a machine-friendly tabular output, using <code>-T</code>, <code>--tabular</code> which would allow you to parse the output without much effort. I'd be tempted to just write the output to a file using the <code>-o</code>, <code>--out-file</code> option:</p>
  <pre><code>seqkit stats -To stats.tsv *.fastq.gz
  </code></pre>
  <p>Example results:</p>
  <pre><code>$ cat stats.tsv 
  file    format  type    num_seqs    sum_len min_len avg_len max_len
  PHB_Rep1_R1.fastq.gz    FASTQ   RNA 118571  11857100    100 100.0   100
  PHB_Rep1_R2.fastq.gz    FASTQ   RNA 118571  11857100    100 100.0   100
  PHB_Rep2_R1.fastq.gz    FASTQ   RNA 144826  14482600    100 100.0   100
  PHB_Rep2_R2.fastq.gz    FASTQ   RNA 144826  14482600    100 100.0   100
  PHB_Rep3_R1.fastq.gz    FASTQ   RNA 129786  12978600    100 100.0   100
  PHB_Rep3_R2.fastq.gz    FASTQ   RNA 129786  12978600    100 100.0   100
  PUH_Rep1_R1.fastq.gz    FASTQ   RNA 227392  22739200    100 100.0   100
  PUH_Rep1_R2.fastq.gz    FASTQ   RNA 227392  22739200    100 100.0   100
  PUH_Rep2_R1.fastq.gz    FASTQ   RNA 162373  16237300    100 100.0   100
  PUH_Rep2_R2.fastq.gz    FASTQ   RNA 162373  16237300    100 100.0   100
  PUH_Rep3_R1.fastq.gz    FASTQ   RNA 185442  18544200    100 100.0   100
  PUH_Rep3_R2.fastq.gz    FASTQ   RNA 185442  18544200    100 100.0   100
  </code></pre>
  <p>And then just parse the output to get what you need, if or when you need it. For your specific requirements, you could just use AWK to skip the header line and print the first and fourth columns:</p>
  <pre><code>awk 'BEGIN {FS=OFS=&quot;\t&quot; } NR&gt;1 { print $1, $4 }' stats.tsv
  </code></pre>
  <p>Results:</p>
  <pre><code>PHB_Rep1_R1.fastq.gz    118571
  PHB_Rep1_R2.fastq.gz    118571
  PHB_Rep2_R1.fastq.gz    144826
  PHB_Rep2_R2.fastq.gz    144826
  PHB_Rep3_R1.fastq.gz    129786
  PHB_Rep3_R2.fastq.gz    129786
  PUH_Rep1_R1.fastq.gz    227392
  PUH_Rep1_R2.fastq.gz    227392
  PUH_Rep2_R1.fastq.gz    162373
  PUH_Rep2_R2.fastq.gz    162373
  PUH_Rep3_R1.fastq.gz    185442
  PUH_Rep3_R2.fastq.gz    185442
  </code></pre>
  