sub get_interface{
my ($range,@native)= @_;
my @native_one;
my @native_two;
my @predict_one;
my @predict_two;
my @temp1;
my $count;
my $chain="RANDOM";
my $num;
my $miss;
my $mark;
#read in file
@temp1=grep{/^ATOM.*?/} @native;
#store the files as 2D matrix
$count=0;
$miss=0;
for(my $i=0;$i<scalar(@temp1);$i++){
if($temp1[$i]=~/^ATOM.*?/){
$count++;
#mark first res
if($count == 1){
$chain=substr($temp1[$i],23,3);
$mark=1;
}
#Chain One
if($chain eq substr($temp1[$i],23,3) && $count <30 && $mark==1){
$native_one[$i-$miss][0]=substr($temp1[$i],23,3);#res number
$native_one[$i-$miss][1]=substr($temp1[$i],21,1);#Chain ID
$native_one[$i-$miss][2]=substr($temp1[$i],32,6);#X
$native_one[$i-$miss][3]=substr($temp1[$i],40,6);#Y
$native_one[$i-$miss][4]=substr($temp1[$i],48,6);#Z
$native_one[$i-$miss][5]=$i+1;#line number
$num=scalar(@native_one);
}
if($chain ne substr($temp1[$i],23,3) && $count >1 && $mark==1){
$native_one[$i-$miss][0]=substr($temp1[$i],23,3);#res number
$native_one[$i-$miss][1]=substr($temp1[$i],21,1);#Chain ID
$native_one[$i-$miss][2]=substr($temp1[$i],32,6);#X
$native_one[$i-$miss][3]=substr($temp1[$i],40,6);#Y
$native_one[$i-$miss][4]=substr($temp1[$i],48,6);#Z
$native_one[$i-$miss][5]=$i+1;#line number
$num=scalar(@native_one);
}
#Chain Two
if($count > 30 && $chain eq substr($temp1[$i],23,3)){
$mark=2;
}
if($count >30 && $mark==2){
$native_two[$i-$num-$miss][0]=substr($temp1[$i],23,3);#res number
$native_two[$i-$num-$miss][1]=substr($temp1[$i],21,1);#Chain ID
$native_two[$i-$num-$miss][2]=substr($temp1[$i],32,6);#X
$native_two[$i-$num-$miss][3]=substr($temp1[$i],40,6);#Y
$native_two[$i-$num-$miss][4]=substr($temp1[$i],48,6);#Z
$native_two[$i-$num-$miss][5]=$i+1;#line number
}
}
else{
$miss++;
}
}
#get the line numbers for calculation
my $num1=scalar(@native_one);
my $num2=scalar(@native_two);
my @residue=residue(\@native_one,\@native_two,$num1,$num2,$range);
return @residue;
}
#calculate the distance and find the residues
sub residue{
my($first,$second,$num1,$num2,$range)=@_;
my $distance;
my @result_first;
my @result_second;
for(my $i=0;$i<$num1;$i++){
for(my $j=0;$j<$num2;$j++){
if($distance <= $range){
my $temp="$$first[$i][0]";
push @result_first,$temp;
my $temp2="$$second[$j][0]";
push @result_second,$temp2;
}
}
}
#delete the reduntant residues
my %hash=();
my @result1 = grep{$hash{$_}++ <1} @result_first;
my %hash2=();
my @result2 = grep{$hash2{$_}++ <1} @result_second;
my @result_final=(@result1,"divide",@result2);
return @result_final;
}
#Function for distance
sub distance{
my($x1,$y1,$z1,$x2,$y2,$z2)=@_;
my $square=($x1-$x2)**2+($y1-$y2)**2+($z1-$z2)**2;
my $result=sqrt($square);
return $result;
}作者: dugu072_cu 时间: 2010-02-05 08:10
没有人说,for比foreach 效率高,二者是等价的,效率的高低取决于你的使用方式
另外,要想得到理想的效率提升,修改这种细节,很难达到,更多的时候,是修改的算法
loop in loop, still loop in loop and so many loops make this program slow and slow.
The problem is analyzing of the data struchture.
Discovering the data structure in details and finding the best way
to pattern the required data.作者: Ray001 时间: 2010-02-05 22:09
楼主编程风格没一句注释啊,我看一眼就晕了。