重新排列primer3 Boulder IO输出

重新排列primer3 Boulder IO输出

我正在尝试重新排列primer3_core输出。

例如:

SEQUENCE_ID=ID_1
PRIMER_LEFT_0_SEQUENCE=ACGTGTAGCGGTTCAGACG
PRIMER_RIGHT_0_SEQUENCE=ACCATGCATGATCCATCCAGG
PRIMER_LEFT_1_SEQUENCE=CACAGCCACAGCAGCACAC
PRIMER_RIGHT_1_SEQUENCE=ATGCAGGTGATCAAGTTACGCC
=
SEQUENCE_ID=ID_2
PRIMER_LEFT_0_SEQUENCE=CACAGCCACAGCAGCACAC
PRIMER_RIGHT_0_SEQUENCE=GCAGGTGATCAAGTTACGCCATT
=

因此,每个 ID 可能会产生不同数量的引物,范围为 0-20。

输出如下所示:

ID_1 ACGTGTAGCGGTTCAGACG
ID_1 ACCATGCATGATCCATCCAGG
ID_1 CACAGCCACAGCAGCACAC
ID_1 ATGCAGGTGATCAAGTTACGCC
ID_2 CACAGCCACAGCAGCACAC
ID_2 GCAGGTGATCAAGTTACGCCATT

答案1

awk -F= '$0 ~ "^SEQUENCE" {SEQ=$2} $0 !~ "^SEQUENCE" { print SEQ" "$2 }' filename

使用 awk 并使用 = 作为字段分隔符。然后,行以 SEQUENCE 开头,将 SEQ 变量设置为等于第二个分隔片段。对于所有其他实例,打印 SEQ 以及第二个分隔数据

答案2

awk方法:

awk -F'=' '/^SEQUENCE_ID/{ s = $2 }/^PRIMER/{ print s, $2 }' file

输出:

ID_1 ACGTGTAGCGGTTCAGACG
ID_1 ACCATGCATGATCCATCCAGG
ID_1 CACAGCCACAGCAGCACAC
ID_1 ATGCAGGTGATCAAGTTACGCC
ID_2 CACAGCCACAGCAGCACAC
ID_2 GCAGGTGATCAAGTTACGCCATT

答案3

使用sed脚本:

# delete lines starting with '='
/^=/d

# handle sequence ID lines
/^SEQUENCE_ID=/{
    # remove everything up to and including the '='
    s///
    # put the sequence ID in the hold space
    h
    # delete the pattern space and continue with next line
    d
}

# handle primer lines
/^PRIMER.*=/{
    # remove everything up to and including the '='
    s///
    # append a newline and the sequence ID from the hold space to the pattern space
    G
    # swap the two bits of the pattern space around, deleting the newline
    s/^\(.*\)\n\(.*\)$/\2 \1/
}

测试它:

$ sed -f script.sed file
ID_1 ACGTGTAGCGGTTCAGACG
ID_1 ACCATGCATGATCCATCCAGG
ID_1 CACAGCCACAGCAGCACAC
ID_1 ATGCAGGTGATCAAGTTACGCC
ID_2 CACAGCCACAGCAGCACAC
ID_2 GCAGGTGATCAAGTTACGCCATT

没有单独的脚本文件:

$ sed -e '/^=/d' -e '/^SEQUENCE_ID=/{s///;h;d;}' -e '/^PRIMER.*=/{s///;G;s/^\(.*\)\n\(.*\)$/\2 \1/;}' file
ID_1 ACGTGTAGCGGTTCAGACG
ID_1 ACCATGCATGATCCATCCAGG
ID_1 CACAGCCACAGCAGCACAC
ID_1 ATGCAGGTGATCAAGTTACGCC
ID_2 CACAGCCACAGCAGCACAC
ID_2 GCAGGTGATCAAGTTACGCCATT

较短的变体:

$ sed -n -e '/^SEQUENCE_ID=/{s///;h;}' -e '/^PRIMER.*=/{s///;G;s/^\(.*\)\n\(.*\)$/\2 \1/p;}' file

相关内容