Eu tenho um arquivo fastq. Vou explicar o que é. É algo assim
@SRR1024120.7 DBRHHJN1:259:D0PM7ACXX:1:1101:1386:1189 length=100
GATACAGGATGCCTGGGTCTAGGCTGTGTGACCTTGGGCCAGTTCCTCTC
+SRR1024120.7 DBRHHJN1:259:D0PM7ACXX:1:1101:1386:1189 length=100
DDDFFDDBGFEHEHGIGC9F>HG9EH8?DF4?:DF<?3:D?DHIGGDDFH
@SRR1024120.25 DBRHHJN1:259:D0PM7ACXX:1:1101:1752:1149 length=100
CTGCTGCTCATGCTCAT
+SRR1024120.25 DBRHHJN1:259:D0PM7ACXX:1:1101:1752:1149 length=100
BDDDDD<<CC:C+AFFE
@SRR1024120.42 DBRHHJN1:259:D0PM7ACXX:1:1101:2482:1096 length=100
AGCGTGTGCCACCCTACGCCGGC
+SRR1024120.42 DBRHHJN1:259:D0PM7ACXX:1:1101:2482:1096 length=100
DD>DAA@AA@@?2C8AB)?@:DD
@SRR1024120.1 DBRHHJN1:259:D0PM7ACXX:1:1101:1200:1120 length=100
AGACAGAAGGGGAGTACAGCTCTCTGGAACATGAGAGTGCAAGGGGTTGAGTGTTT
+SRR1024120.1 DBRHHJN1:259:D0PM7ACXX:1:1101:1200:1120 length=100
DDDFFFCFGEHI@CGFADFGCCFFGHFGCFFFHGGDGHIFHDFGGI<BF=DHIHHH
Agora 4 linhas correspondem a 1 leitura
@SRR1024120.7 DBRHHJN1:259:D0PM7ACXX:1:1101:1386:1189 length=100
GATACAGGATGCCTGGGTCTAGGCTGTGTGACCTTGGGCCAGTTCCTCTC
+SRR1024120.7 DBRHHJN1:259:D0PM7ACXX:1:1101:1386:1189 length=100
DDDFFDDBGFEHEHGIGC9F>HG9EH8?DF4?:DF<?3:D?DHIGGDDFH
corresponde a 1 leitura que éGATACAGGATGCCTGGGTCTAGGCTGTGTGACCTTGGGCCAGTTCCTCTC
Mostrei o arquivo fastq acima. O que eu quero fazer é extrair apenas aquelas leituras em que o comprimento da sequência de leitura é <= 25. Portanto, minha saída deve ser
@SRR1024120.25 DBRHHJN1:259:D0PM7ACXX:1:1101:1752:1149 length=100
CTGCTGCTCATGCTCAT
+SRR1024120.25 DBRHHJN1:259:D0PM7ACXX:1:1101:1752:1149 length=100
BDDDDD<<CC:C+AFFE
@SRR1024120.42 DBRHHJN1:259:D0PM7ACXX:1:1101:2482:1096 length=100
AGCGTGTGCCACCCTACGCCGGC
+SRR1024120.42 DBRHHJN1:259:D0PM7ACXX:1:1101:2482:1096 length=100
DD>DAA@AA@@?2C8AB)?@:DD
Eu quero usar o awk para esse propósito.
Eu tentei algo assim
awk 'NR % 2 == 0 {if(length($1) <= 25) print $0}; NR % 2 == 1' test.fastq
MAS isso imprime algo assim
@SRR1024120.7 DBRHHJN1:259:D0PM7ACXX:1:1101:1386:1189 length=100
+SRR1024120.7 DBRHHJN1:259:D0PM7ACXX:1:1101:1386:1189 length=100
@SRR1024120.25 DBRHHJN1:259:D0PM7ACXX:1:1101:1752:1149 length=100
CTGCTGCTCATGCTCAT
+SRR1024120.25 DBRHHJN1:259:D0PM7ACXX:1:1101:1752:1149 length=100
BDDDDD<<CC:C+AFFE
@SRR1024120.42 DBRHHJN1:259:D0PM7ACXX:1:1101:2482:1096 length=100
AGCGTGTGCCACCCTACGCCGGC
+SRR1024120.42 DBRHHJN1:259:D0PM7ACXX:1:1101:2482:1096 length=100
DD>DAA@AA@@?2C8AB)?@:DD
@SRR1024120.1 DBRHHJN1:259:D0PM7ACXX:1:1101:1200:1120 length=100
+SRR1024120.1 DBRHHJN1:259:D0PM7ACXX:1:1101:1200:1120 length=100
Claramente eu não quero
@SRR1024120.7 DBRHHJN1:259:D0PM7ACXX:1:1101:1386:1189 length=100
+SRR1024120.7 DBRHHJN1:259:D0PM7ACXX:1:1101:1386:1189 length=100
@SRR1024120.1 DBRHHJN1:259:D0PM7ACXX:1:1101:1200:1120 length=100
+SRR1024120.1 DBRHHJN1:259:D0PM7ACXX:1:1101:1200:1120 length=100
na minha saída.
Qualquer ajuda seria apreciada
Obrigado
Responder1
Você pode usar separadores de registros e campos para impedir que o awk use novas linhas e espaços. Em vez disso, você pode usar "\n@" para mostrar a separação de registros e um "\n" simples para separar os campos.
$ awk 'BEGIN {RS="\n@";FS="\n"} {if (length($2) <= 25) {print "@"$0} }' fastq
@SRR1024120.25 DBRHHJN1:259:D0PM7ACXX:1:1101:1752:1149 length=100
CTGCTGCTCATGCTCAT
+SRR1024120.25 DBRHHJN1:259:D0PM7ACXX:1:1101:1752:1149 length=100
BDDDDD<<CC:C+AFFE
@SRR1024120.42 DBRHHJN1:259:D0PM7ACXX:1:1101:2482:1096 length=100
AGCGTGTGCCACCCTACGCCGGC
+SRR1024120.42 DBRHHJN1:259:D0PM7ACXX:1:1101:2482:1096 length=100
DD>DAA@AA@@?2C8AB)?@:DD
Cada uma das linhas será um campo diferente, então você pode verificar o comprimento da segunda linha com $2. Tive que adicionar o "@" novamente durante a impressão, pois ele é consumido pelo separador de registros.