Editing FastQ header
2
0
Entering edit mode
7.4 years ago
acxcrew007 ▴ 10

Hi everyone,

I was wondering what I was doing wrong here in my code. I am trying to edit the FastQ headers of an input file based on some findings.

perl -p -e 's/^@(.*)/@New_Title_$1/' input_file.fastq > new_fastq_header_file.fastq

This removes the "@" of the fastq headers instead.

Many thanks in advance.

FastQ Editing • 1.8k views
ADD COMMENT
1
Entering edit mode
7.4 years ago

"@" in perl means array/list

perl -p -e 's/^@(.*)/\@New_Title_$1/' input_file.fastq > new_fastq_header_file.fastq
ADD COMMENT
0
Entering edit mode
7.4 years ago

@shenwei356's is right when he says that you need to escape the @ character with the inverted slash \ if you want to use it inside a regex pattern. additionally, you don't need to store all header in $1, but simple to replace the initial @ character:

perl -pe 's/^@/\@New_Title_/' input_file.fastq > new_fastq_header_file.fastq

but it looks like you are trying to edit only sequence headers just by looking at the first character, and you can't do that since the @ character can also appear in the quality string. a quick way to workaround this could be replacing odd lines only:

perl -pe '$i = $i ? 0 : 1; s/^@/\@New_Title_/ if $i' input_file.fastq > new_fastq_header_file.fastq

although the proper way to do it would be replacing 1st line only of each 4 lines group:

perl -pe '$i++; s/^@/\@New_Title_/ if $i % 4 == 1' input_file.fastq > new_fastq_header_file.fastq
ADD COMMENT

Login before adding your answer.

Traffic: 2073 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6