Arrays 简化列表/数组的元素,然后添加增量标识符a、b、c、d。。。。等等

Arrays 简化列表/数组的元素,然后添加增量标识符a、b、c、d。。。。等等,arrays,perl,for-loop,replace,bioinformatics,Arrays,Perl,For Loop,Replace,Bioinformatics,我正在处理一个.fasta文件的头文件(这个文件在遗传学/生物信息学中普遍用于存储DNA/RNA序列数据)。Fasta文件的标题以>符号开头(提供特定信息),然后是标题描述的下一行的实际序列数据。序列数据无限期地扩展到下一个\n之后是下一个标头及其相应的序列。例如: >scaffold1.1_size947603 ACGCTCGATCGTACCAGACTCAGCATGCATGACTGCATGCATGCATGCATCATCTGACTGATG.... >scaffold2.1_size7

我正在处理一个.fasta文件的头文件(这个文件在遗传学/生物信息学中普遍用于存储DNA/RNA序列数据)。Fasta文件的标题以>符号开头(提供特定信息),然后是标题描述的下一行的实际序列数据。序列数据无限期地扩展到下一个\n之后是下一个标头及其相应的序列。例如:

>scaffold1.1_size947603
ACGCTCGATCGTACCAGACTCAGCATGCATGACTGCATGCATGCATGCATCATCTGACTGATG....
>scaffold2.1_size747567.2.603063_605944
AGCTCTGATCGTCGAAATGCGCGCTCGCTAGCTCGATCGATCGATCGATCGACTCAGACCTCA....
等等

因此,我对与我合作的生物体基因组的fasta头有一个问题。不幸的是,解决这个问题所需的perl专业知识似乎超出了我目前的技能水平:因此我希望这里的人能告诉我如何做到这一点

我的基因组由大约25000个fasta头和它们各自的序列组成,当前状态下的头给我尝试使用的序列比对器带来了很多麻烦,所以我必须大大简化它们。以下是我的前几个标题的示例:

>scaffold1.1_size947603
>scaffold10.1_size550551
>scaffold100.1_size305125:1-38034
>scaffold100.1_size305125:38147-38987
>scaffold100.1_size305125:38995-44965
>scaffold100.1_size305125:76102-78738
>scaffold100.1_size305125:84171-87568
>scaffold100.1_size305125:87574-89457
>scaffold100.1_size305125:90495-305068
>scaffold1000.1_size94939
基本上,我希望将这些内容细化为:

>scaffold1.1a
>scaffold10.1a
>scaffold100.1a
>scaffold100.1b
>scaffold100.1c
>scaffold100.1d
>scaffold100.1e
>scaffold100.1f
>scaffold100.1g
>scaffold1000.1a
甚至可能是这样(但这似乎更复杂):

我在这里做的是去除基因组每个支架的所有大小数据。对于恰好是碎片的支架,我想用a、b、c、d等来表示它们。有一些支架有超过26个碎片,所以也许我可以用x、y、z、a、b、c、d来表示它们。。。。等等

我想用一个简单的替换foreach循环来实现这一点,类似于:

#!/usr/bin/perl -w

### Open the files 
$gen = './Hc_genome/haemonchus_V1.fa';
open(FASTAFILE, $gen);
@lines = <FASTAFILE>;
#print @lines; 

###Add an @ symbol to the start of the label
my @refined;
foreach my $lines (@lines){ 
    chomp $lines;
    $lines =~ s/match everything after .1/replace it with a, b, c.. etc/g;
    push @refined, $lines;
}
#print @refined;


###Push the array on to a new fasta file
open FILE3, "> ./Hc_genome/modded_haemonchus_V1.fa" or die "Cannot open output.txt: $!";

foreach (@refined)
{
    print FILE3 "$_\n"; # Print each entry in our array to the file
}
close FILE3;  
#/usr/bin/perl-w
###打开文件
$gen='./Hc_基因组/haemonchus_V1.fa';
打开(FASTAFILE,$gen);
@行=;
#打印@行;
###将@符号添加到标签的开头
我的“优雅”;
foreach我的$line(@line){
咀嚼$line;
$lines=~s/匹配后面的所有内容。1/将其替换为a、b、c…等/g;
按@行;
}
#打印@精炼;
###将阵列推送到新的fasta文件
打开文件3“>。/Hc_genome/modded_haemonchus_V1.fa”或die“无法打开output.txt:$!”;
foreach(@defined)
{
打印文件3“$\n”#将数组中的每个条目打印到文件中
}
关闭文件3;
但我不知道是否必须在match and replace运算符中的$1和\n之间添加字母标签。基本上是因为我不确定如何通过字母表顺序地为特定支架的每个片段执行此操作(我所能做的就是在每个片段的开头添加一个a…)

如果你不介意的话,请告诉我如何才能做到这一点

非常感谢


Andrew

在Perl中,增量运算符
++
对字符串具有“神奇”的行为。例如,
my$s=“a”$a++
$a
增加到
“b”
。这一直持续到
“z”
,增量将产生
“aa”
,依此类推

文件的标题似乎已正确排序,因此我们可以循环遍历每个标题。从标题中,我们提取起始部分(包括
.1
在内的所有内容)。如果这个起始部分与前一个报头的起始部分相同,我们将增加序列标识符。否则,我们将其设置为
“a”


非常感谢你的回答。尽管出于某种原因,我似乎无法用实际的fasta文件复制您的结果。碎片化支架的fasta标题中似乎只添加了“a”。例如grep-n scaffold100./Hc_基因组/sim_haemonchus_V1.fa 1374098:>scaffold100.1a 1375367:>scaffold100.1a 1375398:>scaffold100.1a 1375599:>scaffold100.1a 1375688:>scaffold100.1a 1375803:>scaffold100.1a 1375868:>scaffold100.1a有什么想法可以阻止$index++累积吗?是否每个fasta标题之间都有序列行?这与上面的例子不同?@amrezans我之前假设输入中只存在标题。我添加了一些代码来测试行是否是标题。再次感谢您的解决方案和建议!工作得很好!
#!/usr/bin/perl -w

### Open the files 
$gen = './Hc_genome/haemonchus_V1.fa';
open(FASTAFILE, $gen);
@lines = <FASTAFILE>;
#print @lines; 

###Add an @ symbol to the start of the label
my @refined;
foreach my $lines (@lines){ 
    chomp $lines;
    $lines =~ s/match everything after .1/replace it with a, b, c.. etc/g;
    push @refined, $lines;
}
#print @refined;


###Push the array on to a new fasta file
open FILE3, "> ./Hc_genome/modded_haemonchus_V1.fa" or die "Cannot open output.txt: $!";

foreach (@refined)
{
    print FILE3 "$_\n"; # Print each entry in our array to the file
}
close FILE3;  
use strict; use warnings;  # start every script with these

my $index = "a";
my $prev = "";

# iterate over all lines (rather than reading all 25E3 into memory at once)
while (<>) {

  # pass through non-header lines
  unless (/^>/) {
    print;  # comment this line to remove non-header lines
    next;
  }

  s/\.1\K.*//s;  # remove everything after ".1". Implies chomping

  # reset or increment $index
  if ($_ eq $prev) {
    $index++;
  } else {
    $index = "a";
  }

  # update the previous line
  $prev = $_;

  # output new header
  print "$_$index\n";
}
>scaffold1.1a
>scaffold10.1a
>scaffold100.1a
>scaffold100.1b
>scaffold100.1c
>scaffold100.1d
>scaffold100.1e
>scaffold100.1f
>scaffold100.1g
>scaffold1000.1a