This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How do you get rid of reads with matching pattern in fastq

I need to get rid of all the reads with 3' prime A in a fastq file and get the new fastq without them. How ccould you acheive this ?

fastq

Just to be clear you are only talking about discarding reads where the last base is A. Can you modify the answers from your question yesterday to start thinking about how you can do this: Command to count reads in fastq file with last bases

Curious as to why you want to do this.

  1. Why do you want that ; I am really curious!

  2. By that, do you mean you don't want reads like these

    AAAGTACGATCACTACTACATC

    AAGTACGATTAACTACTACATC

    AGTGTACGGGGATCACTACTAC

But these will be okay?

AAAGTACGATCACTACTACATC
AAGTACGATTAACTACTACATC
AGTGTACGGGGATCACTACTAC

I want reads like: AATTTATATGGGAGCCAC But not: GATTAGGGCCGCGGGATA

I need to analyze small RNA structures so need to do this with reads not ending with A

2 answers

See if this does the trick:

cat your.fastq | paste - - - - | awk -F '\t' '{if ($2 !~/A$/){ print $0}}'| tr "\t" "\n" > filtered.fastq

This is lovely, wish I had known this construct much earlier: cat your.fastq | paste - - - -

@Pierre uses it often. I would not be surprised if he is the creator.

@cshu181 was asking about the cat | paste construct.

Ending it with | tr "\t" "\n" is kind of an important part too.

@ MAPK Posting example data and expected output would help people better answer your query.

try seqkit grep -vsrip "a$" example.fastq. Seqkit can be downloaded from here

Log in to answer this question.