Biotechnology Forums
PERL Program - BINC 2017 question - Printable Version

+- Biotechnology Forums (https://www.biotechnologyforums.com)
+-- Forum: Biotechnology Discussion (https://www.biotechnologyforums.com/forum-1.html)
+--- Forum: Bioinformatics (https://www.biotechnologyforums.com/forum-5.html)
+--- Thread: PERL Program - BINC 2017 question (/thread-7914.html)



PERL Program - BINC 2017 question - binu - 04-25-2017

Question:

Intra Molecular Distance Matrix calculation (50 marks) : ATOM lines (155) of a pdb file are provided in input file (only C@ residues). Calculate intra molecular distance between each C@ residue. If distance >= 6, print 1 in distance matrix of output file, else print 0 in distance matrix.


Solution:

#!/usr/bin/perl -w
# Perl program to calculate intra molecular distance
use strict;
my ($file,$line,@array_x,@array_y,@array_z,$dist,$j,$i,$element);
my $k=0;
print "Enter the PDB filename: ";
$file = <STDIN>;
chomp $file;
open (FILE, $file) or die "Cannot open file $file \n\n" ;

while ($line = <FILE>) 
{
if ($line =~ /^ATOM/)
{  
$array_x[$k] = (split (/\s+/, $line))[6];
$array_y[$k] = (split (/\s+/, $line))[7];
$array_z[$k] = (split (/\s+/, $line))[8];
$k++;
}
}
close FILE;
#print "K=$k \n";
#print "@array_x \n @array_y \n @array_z \n";
print "\n Intramolecular Distance Matrix is : \n\n";
print "ATOMi \t ATOMj \t Euclidean Distance \t Element \n";
for($i = 0; $i < $k ; $i++)
{
for($j = 0; $j < $k ; $j++)
{
#Euclidean Distance Calculation
$dist = sqrt(
                ($array_x[$i] - $array_x[$j])**2 +
                ($array_y[$i] - $array_y[$j])**2 +
                ($array_z[$i] - $array_z[$j])**2
            );
if ($dist >= 6)

$element = 1;
print "$i \t $j \t $dist \t $element \n"; 
}
else

$element = 0;
print "$i \t $j \t $dist \t $element \n"; 
}
}
}