I've got FASTQ files from a sequencing run and I'm trying to remove the sequence of the second indexing primer with Unix. Below are the first few lines of the FASTQ file. I'm trying to remove +AGCGCGAT from the first line, +AGCTCGCG from the fifth line, etc. Essentially, it's removing a plus sign and any eight characters (A, C, G, T, or N) following it. Thanks in advance for your help.

@NS500663:433:HGFVKBGX2:1:11101:2828:1039 1:N:0:CGAGTGCT+AGCGCGAT
@NS500663:433:HGFVKBGX2:1:11101:8765:1039 1:N:0:ATCACGAT+AGCTCGCG
  • 1
    Would it be correct to say you'd like to remove all text from the + onwards on all lines that start with @ in the whole file? Or do you just want to remove these two specific strings from these two specific lines? – Kusalananda Feb 18 '17 at 21:46
$ sed 's/^\(@.*\)+.*$/\1/' file.fastq >new-file.fastq

This will remove the primer sequence and the + from those lines.

It will find all lines starting with @ and containing a + sign. It will replace the line with only the bit before the + sign, and drop the rest.

The input is from file.fastq and the output will go to new-file.fastq.

The following is a bit more restrictive in that it explicitly matches the characters that you mentioned after the +:

$ sed 's/^\(@.*\)+[ACGTN]*$/\1/' file.fastq >new-file.fastq

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.