将标签添加到Fasta序列名称中

问题描述 投票:-1回答:4

我需要帮助。我有一个fasta文件,例如:

>YP_00698.1 hypothetical protein sp [Species 1]
MDMQFGYFTRNPSTKYPATLYPREVSCALYEDDNENTSLIPKSRHYHYTIQPPINYKKLTNVDRYKNFRL

>YP_0098.1 hypothetical protein sp [Species 2]
MDMQFGYFTRNPSTKYPATLYPREVSCALYEDDNENTSLIPKSRHYHYTIQPPINYKKLTNVDRYKNFRL

>YP_009378.1 hypothetical protein sp [Species 3]
MEDNTAEDIIKNHLLNTSNDDDDDADSLKKKKENIDDIVKESKNVNLFFISYIKAYNDLVLFLKQQEIVFINILHLNNLNLSIYNLLQKCYSTKDKYKFLPDNNKNLLQLILTLKKNVKFRLKRLKDK

并且我正在寻找一种bash方法,以便在"_CT"之后添加>Seqnames,所以我应该得到:

>YP_00698.1_CT hypothetical protein sp [Species 1]
MDMQFGYFTRNPSTKYPATLYPREVSCALYEDDNENTSLIPKSRHYHYTIQPPINYKKLTNVDRYKNFRL

>YP_0098.1_CT hypothetical protein sp [Species 2]
MDMQFGYFTRNPSTKYPATLYPREVSCALYEDDNENTSLIPKSRHYHYTIQPPINYKKLTNVDRYKNFRL

>YP_009378.1_CT hypothetical protein sp [Species 3]
MEDNTAEDIIKNHLLNTSNDDDDDADSLKKKKENIDDIVKESKNVNLFFISYIKAYNDLVLFLKQQEIVFINILHLNNLNLSIYNLLQKCYSTKDKYKFLPDNNKNLLQLILTLKKNVKFRLKRLKDK

我尝试过:

sed 's/^\(>.*\)$/\1 _CT/' fastafile.fa

但是我最后得到"_CT" ...

感谢您的帮助。

bash awk sed bioinformatics fasta
4个回答
1
投票
[

[awk可以很容易地完成,请您试一下。

awk '/^>/{$1=$1"_CT"} 1' Input_file

说明:为以上awk代码添加说明。

awk '            ##Starting awk program here.
/^>/{            ##Checking condition if a line starts from > then do following.
  $1=$1"_CT"     ##Setting value of $1 to $1 and concatenating _CT to it too.
}                ##Closing BLOCK for this condition here.
1                ##Mentioning 1 will print edited/non-edited line.
' Input_file     ##Mentioning Input_file name here.

[sed解决方案:

sed '/^>/s/\([^ ]*\)\(.*\)/\1_CT\2/'  Input_file

3
投票

您可以使用sed之类

sed 's/^>[^[:space:]]\{1,\}/&_CT/' fastafile.fa > newfastafile.fa
sed 's/^>[^ \t]\{1,\}/&_CT/' fastafile.fa > newfastafile.fa
sed -E 's/^>[^ \t]+/&_CT/' fastafile.fa > newfastafile.fa

请参见online demo

详细信息

  • [^-字符串开头
  • [>-一个>字符
  • [^[:space:]]\{1,\}-除空格以外的1个或多个字符。注意\{1,0\}可以在POSIX ERE模式中写为+(通过-E-r选项启用)

替换部分中的&代表整个匹配值。


2
投票

只需将每行的第一个空格替换为_CT

sed 's/ /_CT /' input_file.fasta

这应该足够,因为FASTA序列行不应包含任何空格


1
投票

问题是.*可以而且将匹配整行,尤其是当您的搜索模式包括$“行尾”锚点时。请使用只能与序列名称匹配的名称,例如[^ ]*(连续的非空格字符序列):

sed 's/^\(>[^ ]*\)/\1_CT/' fastafile.fa

您可以try it here

© www.soinside.com 2019 - 2024. All rights reserved.