Question: Split Fastq Paired-Read Using Awk
1
gravatar for thiagomafra
6.0 years ago by
thiagomafra70
Brazil
thiagomafra70 wrote:

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!
fastq split awk • 2.3k views
ADD COMMENTlink modified 6.0 years ago by toni2.1k • written 6.0 years ago by thiagomafra70

+1 for using Awk!

ADD REPLYlink written 6.0 years ago by Frédéric Mahé2.9k
1
gravatar for toni
6.0 years ago by
toni2.1k
Lyon
toni2.1k wrote:

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 COMMENTlink modified 6.0 years ago • written 6.0 years ago by toni2.1k

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 REPLYlink modified 6.0 years ago • written 6.0 years ago by Frédéric Mahé2.9k

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

ADD REPLYlink written 6.0 years ago by thiagomafra70
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1780 users visited in the last hour