我想读取一个文件并根据它有多少个链(M,N,O,..)来生成多个数组。
以下是文件的一部分:
SEQRES 1 M 312 ALA ALA ASP PRO LYS LEU LEU LYS ALA ALA ALA GLU ALA
SEQRES 2 M 312 SER TYR ALA PHE ALA LYS GLU VAL ASP TRP ASN ASN GLY
SEQRES 3 M 312 ILE PHE LEU GLN ALA PRO GLY LYS LEU GLN PRO LEU GLU
SEQRES 4 M 312 ALA LEU LYS ALA ILE ASP LYS MET ILE VAL MET GLY ALA
SEQRES 5 M 213 SER PHE ASN ARG ASN
SEQRES 1 N 312 ASP GLU ILE GLY ASP ALA ALA LYS LYS LEU GLY ASP ALA
SEQRES 2 N 312 SER TYR ALA PHE ALA LYS GLU VAL ASP TRP ASN ASN GLY
SEQRES 3 N 312 ILE PHE LEU GLN ALA PRO GLY LYS LEU GLN PRO LEU GLU
SEQRES 4 N 312 ALA LEU LYS ALA ILE ASP LYS MET ILE VAL MET GLY ALA
SEQRES 5 N 312 ALA ALA ASP PRO LYS LEU LEU LYS ALA ALA ALA GLU ALA
SEQRES 6 N 312 VAL THR SER ARG ALA ASP TRP ASP ASN VAL
SEQRES 1 O 312 HIS HIS LYS ALA ILE GLY SER ILE SER GLY PRO ASN GLY
SEQRES 2 O 312 SER TYR ALA PHE ALA LYS GLU VAL ASP TRP ASN ASN GLY
SEQRES 3 O 312 ILE PHE LEU GLN ALA PRO GLY LYS LEU GLN PRO LEU GLU
SEQRES 4 O 312 ALA LEU LYS ALA ILE ASP LYS MET ILE VAL
这是我的代码:
my @seq;
my $string="";
my @seqFile;
my $file=<>;
open(FILE, "$file");
while (my $line=<FILE>){
if ($line =~ /^SEQRES/) {
chomp $line;
push @seq, [split (/\s+/, $line)] ;
}
}
close(FILE);
for my $i (0..$#seq) {
my $ob =$seq[$i][2];
if ($seq[$i][2] eq $ob ){
for (my $j=4;$j<=$#{$seq[$i]};$j++) {
my $temp= $seq[$i][$j];
$string .= $temp;
}
$ob = $seq[$i][2];
last;
}
push @seqFile, $ob;
push @seqFile, $string;
$string = ''; #string needs to be empty to store new lines
}
使用上面的示例:3 个数组 M(:)ALAALAASP:.., N(:)ASPGLU.., O(:)HISHISLYS...
我设法在一个字符串中创建了所有 SEQRES,但这不是我想要的。
在某个地方我需要放置一个if(){}
和来检查M <=> N
并且N <=> O
是不同的。然后保存字符串并开始一个字符串和数组。但它会不断累积与 $#seq 一样多的相同字符串。或者,如果我移动一个的位置,}
那么它不会存储任何东西,或者给我错误消息。我怎样才能做到这一点?