我需要从这种格式转换FASTA头:
gi|351517969|ref|NW_003613580.1| Cricetulus未放置的基因组支架,CriGri_1.0 scaffold329,全基因组猎枪序列
对此:
NW_003613580.1 Cricetulus未放置的基因组支架,CriGri_1.0 scaffold329,全基因组猎枪序列
NW中的W可以是其他地址中的C,下划线之后的数字数也会有所不同。
我找到了一个perl脚本,可以将it更改为不同的格式,并试图对其进行修改。有关部分:
while( $seq = $seq_in->next_seq() )
{
my $seqName = $seq->id;
$seqName =~ s/\|/\./g; #replace pipe with dot
$seqName =~ s/(NW\_)/$1/;
#$seqName =~ s/(gi\.\w*)\..*/$1/;
$seq->id($seqName);
$seq_out->write_seq($seq);
}将注释去掉的seqname位作为原始位。我希望把gi改为NW会让它稍后在标题中开始阅读,但没有骰子。然而,将$1改为随机文本确实会使它在NW替换,所以我不太确定。此外,替换管道的周期似乎消失了,没有任何合理的理由(尽管我确实希望它们消失)。任何帮助,或至少一些关于搜索和替换是如何在这里工作的资源,将不胜感激。
发布于 2012-12-17 22:13:56
将各组成部分分开:
my @fastaHeaderComponents = split("\\|", $seq->id);然后进入它们:
my $accessionId = $fastaHeaderComponents[3];
my $description = $fastaHeaderComponents[4];并重新生成标题:
my $newFastaHeader = ">$accessionId $description";
$seq->id($newFastaHeader);发布于 2012-12-17 22:14:19
使用sed单线线:
sed -r 's/^([^|]+\|){3}//;s/\|//' fileNW_003613580.1 Cricetulus未放置的基因组支架,CriGri_1.0 scaffold329,全基因组猎枪序列
使用sed解决方案的好处是,您可以指定对哪一行进行替换,例如第一行只使用1s,并使用-i选项将替换存储回文件:
sed -ri '1s/^([^|]+\|){3}//;1s/\|//' file雷加解释:
s/ # Substitution, 1s/ first line only, 2s/ second line..
^ # Match the start of the line
( # Group pattern
[^|]+ # Match one or more character that isn't a |
\| # Match the | (escaped)
) # End grouped pattern
{3} # Repeat grouped pattern 3 times
/ # Replace with
/ # Nothing
;
s/ # Substitute, 1s/ first line only..
\| # The remaining |
/ # Replace with
/ # Nothing 发布于 2012-12-18 02:08:28
也许以下几点将有帮助:
use strict;
use warnings;
use Bio::SeqIO;
my $seq_in = Bio::SeqIO->new( -file => 'input.fas', '-format' => 'Fasta' );
my $seq_out = Bio::SeqIO->new( -file => '>output.fas', '-format' => 'Fasta' );
while ( my $seq = $seq_in->next_seq ) {
my $shortened_seq = Bio::Seq->new(
-desc => $seq->desc,
-display_id => ( split /\|/, $seq->id )[-1]
);
$seq_out->write_seq($shortened_seq);
}给定一个FASTA头,如下所示作为输入:
>gi|351517969|ref|NW_003613580.1| Cricetulus griseus unplaced genomic scaffold, CriGri_1.0 scaffold329, whole genome shotgun sequence它产生以下输出:
>NW_003613580.1 Cricetulus griseus unplaced genomic scaffold, CriGri_1.0 scaffold329, whole genome shotgun sequencehttps://stackoverflow.com/questions/13923072
复制相似问题