I had not seen that post! Thanks for sharing, I'll try it.
Hi! I have several fastq files (paired sequencing, si I have R1 and R2 files) with different headers. For example:
@SRR8834012.1.1 MG00HS20:989:CAKP3ANXX:1:1101:1962:1989 length=101
NGGTCCTCGGCAGGCCGAGACCGGCTTCTGCGATCAAGCTGCGCTGAACCTCGCTGCTCCCGGCGTAGATCGTCGCGGCGATGTTTCGGCGCGACATCCAC
Or
@MG00HS20:989:CAKP3ANXX:1:1101:1457:56177/1
TTCCGGATCCCGTCGCGCTGATCGCGGCCTTTTCGCGTCGAGATTGCACGAATGCCGCGTAGGTTTCGCGGTGACCGAGGCC
+
AAABCGC<<C1/@C99/EGEGGD=CGGGG/:FDEEGGGGDEGGGGGGGGGG/09FGG/C:CGG=FG0:FAGG.@DEG.?E.@
I would like to edit the headers on all my FASTQ files so that the header would be the name of the file with a number to the end that would act a sequence counter. So the headers for the reads in a file named test would be test_1, test_2, test_3, and so on.
Could someone help me?
3 answers
Here's a seqkit replace answer also that will loop over all of the fastq files in a directory.
find . -name "*.fastq" -exec sh -c \
'seqkit replace -p .+ -r "$(basename $0 .fastq)_{nr}" $0 > ${0%.fastq}.renamed.fastq' {} \;
Hi! Please consider reformatting your question to be more readable.
Have you seen Quick One Liner For Fastq Header Renaming post? I think you can very much adapt the awk solution suggested there, and slightly modify it so that the name of your file is used. Something like this (not tested):
cat input_name.fastq | awk -v fqname="input_name" '{print (NR%4 == 1) ? "@"fqname"_" ++i : $0}' | > renamed_header.fastq
$ bioawk -c fastx '{ print "@"FILENAME"_"++c, $seq,"+",$qual }' test.fq | tr -s "\t" "\n"
Log in to answer this question.
You should look into
bioawk(https://github.com/lh3/bioawk) - I think it will allow you to access these variables (file name, record number i.e. ordinal number of each read) in a streamlined way.