Split Fastq Paired-Read Using Awk
1
1
Entering edit mode
11.6 years ago
thiagomafra ▴ 70

Hi guys,

I have a fastq file that contains paired reads. I know that F3 and R3 tag beginning with G and T, respectively in second line. I want split the file in R3.fastq and F3.fastq using awk, but I can not. Anybody help me?

@745_15_830
G..13...10...033..3323.331..131..3.0..3311.333....2
+
!!@@!!!8'!!!A%@!!@A'B!&3:!!?A&!!B!<!!B?(&!B=7!!!!%
@745_15_830
T103223.0303002200023123021022000003020..301233..0.
+
6+%'<(!%-?B-)4%=(<(?+&%%)-)%%91%-)<*5)!!4%%&A2!!%!
@745_15_908
G..12...032..030..1120.311..130..3.1..0233.231....1
+
!!-;!!!%*@!!@A1!!A57%!0+A!!4=<!!@!/!!-'*@!(1A!!!!4
@745_15_908
T303313.2231300002222330212112022210120..311031..0.
+
&@B,(*!,'/1B%%)%=&'(9*%0&0:&8%&&&.')>)!!;:3(%2!!0!
split fastq awk • 4.1k views
ADD COMMENT
0
Entering edit mode

+1 for using Awk!

ADD REPLY
1
Entering edit mode
11.6 years ago
toni ★ 2.2k

If you are sure that pair F3 is ALWAYS written before pair G3, you can try this :

awk 'BEGIN{count=0}{count++; if(count<=4) {print $0 > "F3.fastq"} else {print $0 > "R3.fastq" } if(count==8) count=0 }' input.fastq
ADD COMMENT
0
Entering edit mode

Nice Awk command. It could be improved a bit:

awk '{++count ; if (count<=4) {print > "F3.fastq"} else {print > "R3.fastq" } if (count==8) count=0 }' input.fastq

You don't need to specify $0, and you do not need to initialize the variable (count).

ADD REPLY
0
Entering edit mode

Thanks so much! Just a correction: F3 beginning with base T and R3 beginning with G!

ADD REPLY

Login before adding your answer.

Traffic: 1968 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