Answers.Body: <p>If you have paired-end reads, this solution keeps the two files in-sync (i.e. discard pairs where one of the two reads is shorter than 259). Also, it uses only Unix tools without requiring external programs:</p>
  
  <pre><code>paste &lt;(zcat S1_L001_R1_001.fastq.gz | paste - - - -) &lt;(zcat S1_L001_R2_001.fastq.gz | paste - - - -) \
  | awk -v FS='\t' 'length($2) &gt;= 259 &amp;&amp; length($6) &gt;= 259' \
  | tee &gt;(cut -f 1-4 | tr '\t' '\n' | gzip &gt; r1.fq.gz) \
  | cut -f 5-8 | tr '\t' '\n' | gzip &gt; r2.fq.gz
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-11T08:17:27.123Z
Answers.LastActivityDate: 2018-09-11T08:17:27.123Z
Answers.UserDisplayName: dariober
Answers.Body: <p>You need to use variable <code>$seq</code>. For example:</p>
  
  <pre><code>bioawk -cfastx 'length($seq)&gt;=259{print "@"$name"\n"$seq"\n+\n"$qual}' test.fq.gz
  </code></pre>
  
  <p>There are also more convenient tools like <a href="https://github.com/lh3/seqtk" rel="nofollow noreferrer">seqtk</a> and <a href="https://github.com/shenwei356/seqkit" rel="nofollow noreferrer">seqkit</a>. With those, you may</p>
  
  <pre><code>seqtk seq -L260 test.fq.gz
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-09T00:21:08.497Z
Answers.LastActivityDate: 2018-09-09T00:21:08.497Z
Answers.UserDisplayName: user172818
Body: <p>I tried to filter out FASTQ reads which are shorter than 259 bp with </p>
  
  <pre><code>bioawk -cfastx 'length() &gt;= 259 {print "@" " " "\n""\n+\n"}' good/SZ005_NoIndex_L002_R1_009.good.fq.gz \
    | gzip &gt;  good-filtered/SZ005_NoIndex_L002_R1_009.good-filtered.fq.gz`. 
  </code></pre>
  
  <p>Unfortunately, the output was wrong:</p>
  
  <pre><code>@ 
  
  +
  
  @ 
  
  +
  
  @ 
  </code></pre>
  
  <p>What did I miss?</p>
  
  <p>Thank you in advance,</p>
  
Tags: <fastq><bioawk>
Title: filter out FASTQ reads which are shorter
ThreadText: # filter out FASTQ reads which are shorter
  
  (Asked by: username_0 on 2018-09-08)
  
  I tried to filter out FASTQ reads which are shorter than 259 bp with
  
  ```
  bioawk -cfastx 'length() >= 259 {print "@" " " "\n""\n+\n"}' good/SZ005_NoIndex_L002_R1_009.good.fq.gz \
    | gzip >  good-filtered/SZ005_NoIndex_L002_R1_009.good-filtered.fq.gz`. 
  
  ```
  
  Unfortunately, the output was wrong:
  
  ```
  @ 
  
  +
  
  @ 
  
  +
  
  @ 
  
  ```
  
  What did I miss?
  
  Thank you in advance,
  
  **Tags:** fastq, bioawk
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-09-11. Score: 0 | Accepted answer
  
  If you have paired-end reads, this solution keeps the two files in-sync (i.e. discard pairs where one of the two reads is shorter than 259). Also, it uses only Unix tools without requiring external programs:
  
  ```
  paste <(zcat S1_L001_R1_001.fastq.gz | paste - - - -) <(zcat S1_L001_R2_001.fastq.gz | paste - - - -) \
  | awk -v FS='\t' 'length($2) >= 259 && length($6) >= 259' \
  | tee >(cut -f 1-4 | tr '\t' '\n' | gzip > r1.fq.gz) \
  | cut -f 5-8 | tr '\t' '\n' | gzip > r2.fq.gz
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2018-09-09. Score: 3
  
  You need to use variable `$seq`. For example:
  
  ```
  bioawk -cfastx 'length($seq)>=259{print "@"$name"\n"$seq"\n+\n"$qual}' test.fq.gz
  
  ```
  
  There are also more convenient tools like [seqtk](https://github.com/lh3/seqtk) and [seqkit](https://github.com/shenwei356/seqkit). With those, you may
  
  ```
  seqtk seq -L260 test.fq.gz
  
  ```
  
  
  ---
  
  