我有这个文件:
m64071_220512_054244/12584899/ccs rev pet047-10055 ACGTGCGACCTTGTGA TTGAGGGTTCAAACGTGCGACCTTGTGA
m64071_220512_054244/128321000/ccs rev pet047-10055 ACGTGCGACCTTGTGA TTGAGGGTTCAAACGTGCGACCTTGTGA
m64071_220512_054244/132186699/ccs fwd pet047-10055 TCACAAGGTCGCACGT TCACAAGGTCGCACGTTTGAACCCTCAA
m64071_220512_054244/134874748/ccs fwd pet047-10055 TCACAAGGTCGCACGT TCACAAGGTCGCACGTTTGAACCCTCAA
我需要tr
和reverse
字段 $4 et $5 仅当$2==rev
预计 :
m64071_220512_054244/12584899/ccs rev pet047-10055 TCACAAGGTCGCACGT TCACAAGGTCGCACGTTTGAACCCTCAA
m64071_220512_054244/128321000/ccs rev pet047-10055 TCACAAGGTCGCACGT TCACAAGGTCGCACGTTTGAACCCTCAA
m64071_220512_054244/132186699/ccs fwd pet047-10055 TCACAAGGTCGCACGT TCACAAGGTCGCACGTTTGAACCCTCAA
m64071_220512_054244/134874748/ccs fwd pet047-10055 TCACAAGGTCGCACGT TCACAAGGTCGCACGTTTGAACCCTCAA
我试过 :
perl -lpe 'if(/rev/) {$rev=/rev/;next}; if ($rev) {$F[4,5]=~tr/ATGC/TACG/; $F[4,5]=reverse $F[4,5]; print "@F"}' file
我还尝试使用 awk (在 awk 中执行 bash 命令并打印命令输出)
awk '{
if($2==rev)
{
cmd1="echo \047" $4 "\047 | rev | tr \047ATGC\047 \047TACG\047"
cmd2="echo \047" $5 "\047 | rev | tr \047ATGC\047 \047TACG\047"
newVar1=((cmd1 | getline line) > 0 ? line : "failed")
newVar2=((cmd2 | getline line) > 0 ? line : "failed")
close(cmd)
print $1, $2, $3, newVar1, newVar2
}
else {print}
}' file