This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Remove quotes in fastq files

Hi, I'm new in this area, so thanks a lot for any help in advance.

I have some fastq files, in which in some lines there are additional quotes " " added to the quality score in the beginning and the end sometimes and I want to remove them now.

For example:

    @NGSNJ-086:647:GW2112051649th:1:1101:6506:1016 1:N:0:CTGAAGCT+ATAGCCTT
AAACTAAGTCAATTCTAATACGACTCACTATAGGAGCTCAGCCTTCACTGCTTCTTAAAGATGCGCACACAACACTCTTTACGTATGTACCGGCACCACGGTCGGATCCTAGATCGGAAGAGCACACGTCTGAACTCCAGTCACCTGAAG
+
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
@NGSNJ-086:647:GW2112051649th:1:1101:7428:1078 1:N:0:CTGAAGCT+ATAGCCTT
AAACTAAGTCAATTCTAATACGACTCACTATAGGAGCTCAGCCTTCACTGCGACAAAATTGGCCATCTTTCCGACAAACAACATGCCCCACGGCACCACGGTCGGATCCTAGATCGGAAGAGCACACGTCTGAACTCCAGTCACCTGAAG
+
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"

So I want to remove the " " in the last line, is there any efficient way to do this, thanks a lot

fastq

How did this come to pass? These should not even be in there.

I did some preprocessing in R and the writeFastq command added them because R prints strings with quotes. But I want to avoid doing the calculations again if the quotes can be removed easily

Which package is that function from? No sane bioinformatician would write a FASTQ with quotes.

It was the writeFastq function from the microseq package. Yes, I didn't expect that either. Also strange that it only occurred in some lines.

Sounds either like a crap package or something else being wrong. I would start over from scratch. The double quote is a valid quality value so simply gsubbing it away may/will break the fastqs as well.

Thanks for the suggestion, I guess I will try sed -i 's/^"//'

sed -i 's/"$//' test.fastq

and if that does not work I could do it in R (conditioned that it won't happen again when writing) by checking the length, doing it from scratch would take some days

Do you know a safe writeFastq function?

Use cpad's 0~4 line-step sed instead of your all-line sed.

Thanks, I must check why such an old version is installed / was not updated

2 answers

$ sed '0~4 s/"//g' test.fq

Thanks a lot

This will delete all quotes in each fourth line, won't it?

yes, If you want to be further careful, try this:

$ sed -r '0~4 s/^"//;s/"$//' test.fq

Generally in R you work with fasta and fastq files as a Biostrings object. If you have a biostrings object of your fastq file writeXStringSet would be the correct function to save it as a file.

Thanks, I was using Biostrings anyway, I just wasn't aware they have read/write functionaliy

Log in to answer this question.