#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    12
    Rep Power
    0

    Reading coordinates in many pdb files in a directory


    Good morning everybody,
    I have started using perl last Monday and I have encountered lots of issues. I need your helps. Please. Here is my question. I have downloaded pdb files into a directory and now I am writing a perl script to read the pdb files and output all the coordinates into another file.txt.
    Then I have another srcipt to calculate the distance between the coordinates. Below are the two scripts. There are not working.

    This script is to get the coordinates. I have an error saying"Undefined subroutine &main::get_file_data called at out_coordold.pl line 8."

    #!/usr/bin/perl

    #use strict;
    #use warnings;
    #use BeginPerlBioinfo;

    # Read in PDB file
    my @file = get_file_data('1nta.pdb1');

    #Parse the record types of the PDB file
    my %recordtypes = parsePDBrecordtypes(@file);

    #Extract the atoms of all chains in the DNA/RNA
    my %atoms = parseATOM($recordtypes{'ATOM'});

    # Print out some atoms
    print $atoms{'1'}, "\n";

    exit;

    # Extract x, y, and z coordinates
    #@value = coordinates in a string

    sub parseATOM{
    my ($atomrecord) = @_;

    # use strict;
    # use warnings;

    my %results = ( );
    # Turn the scalar into an array of ATOM lines
    my (@atomrecord) = split(/\n/, $atomrecord);

    foreach my $record (@atomrecord){
    my $number = substr($record, 0, 4); # columns 7-9

    my $x = substr($record, 27, 6);
    my $y = substr($record, 33, 6);
    my $z = substr($record, 42, 6);

    my $element = substr($record, 66, 2); #column 66-67

    # $number and $element may have leading spaces:
    $number =~ s/^\s*//;
    $element =~ s/^\s*//;
    #Store information in hash
    $results{$number} = "$x $y $z $element";
    }

    # return the hash
    return %results;
    }

    this last one is to calculate the coordinates. I am having this error "Global symbol "@array" requires explicit package name at Hydrogen_dist.pl line 14."

    #!/usr/bin/perl

    use strict;
    use warnings;

    use Data:umper;

    my @points = ();
    open(IN, "/na-biol/out_coord.pl" or die "$!";
    while (my $line = <IN>) {
    chomp($line);
    my array = (split (/\s+/, $line))[7,8,9];
    print "@array\n";
    push @points, [@array];
    }
    close(IN);

    print '@points : ',Dumper \@points;

    open my $out_fh, '>', 'distances.txt'or die "cannot open distances.txt: $!\";

    for my $i1 (0 ..$#points -1 ){
    my ($x1, $y1, $z1) = @{$points[$i1]};
    for my $i2 (1 ..$points){
    my ($x2, $y2, $z2) =@{$points[$i2]};
    my $dist = sqrt(($x2-$x1)**2 + ($y2-$y1)**2 + ($z2-$z2)**2);
    print $out_fh "distance from ($x1, $y1, $z1) to ($x2, $y2, $z2) is $dist\n" or die "cannot print to distances.txt:$!\n;
    }
    }
    close $out_fh or die"cannot close distances.txt: $!\n";

    If someone can help it willbe awsome.
  2. #2
  3. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,221
    Rep Power
    1809
    Regarding the error message you mentioned, in your second script:

    Code:
    while (my $line = <IN>) {
       chomp($line);
       my @array = (split (/\s+/, $line))[7,8,9];
       print "@array\n";
       push @points, [@array];
    }
    You left the @ symbol off the front of the variable name on the previous line, so when you asked to print @array on the next line, perl didn't know what you meant.

    You should not comment out the strict and warnings statements. They would provide better guidance as to where the problem is.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    12
    Rep Power
    0

    thanks Keath


    Originally Posted by kapab07
    Good morning everybody,
    I have started using perl last Monday and I have encountered lots of issues. I need your helps. Please. Here is my question. I have downloaded pdb files into a directory and now I am writing a perl script to read the pdb files and output all the coordinates into another file.txt.
    Then I have another srcipt to calculate the distance between the coordinates. Below are the two scripts. There are not working.

    This script is to get the coordinates. I have an error saying"Undefined subroutine &main::get_file_data called at out_coordold.pl line 8."

    #!/usr/bin/perl

    #use strict;
    #use warnings;
    #use BeginPerlBioinfo;

    # Read in PDB file
    my @file = get_file_data('1nta.pdb1');

    #Parse the record types of the PDB file
    my %recordtypes = parsePDBrecordtypes(@file);

    #Extract the atoms of all chains in the DNA/RNA
    my %atoms = parseATOM($recordtypes{'ATOM'});

    # Print out some atoms
    print $atoms{'1'}, "\n";

    exit;

    # Extract x, y, and z coordinates
    #@value = coordinates in a string

    sub parseATOM{
    my ($atomrecord) = @_;

    # use strict;
    # use warnings;

    my %results = ( );
    # Turn the scalar into an array of ATOM lines
    my (@atomrecord) = split(/\n/, $atomrecord);

    foreach my $record (@atomrecord){
    my $number = substr($record, 0, 4); # columns 7-9

    my $x = substr($record, 27, 6);
    my $y = substr($record, 33, 6);
    my $z = substr($record, 42, 6);

    my $element = substr($record, 66, 2); #column 66-67

    # $number and $element may have leading spaces:
    $number =~ s/^\s*//;
    $element =~ s/^\s*//;
    #Store information in hash
    $results{$number} = "$x $y $z $element";
    }

    # return the hash
    return %results;
    }

    this last one is to calculate the coordinates. I am having this error "Global symbol "@array" requires explicit package name at Hydrogen_dist.pl line 14."

    #!/usr/bin/perl

    use strict;
    use warnings;

    use Data:umper;

    my @points = ();
    open(IN, "/na-biol/out_coord.pl" or die "$!";
    while (my $line = <IN>) {
    chomp($line);
    my array = (split (/\s+/, $line))[7,8,9];
    print "@array\n";
    push @points, [@array];
    }
    close(IN);

    print '@points : ',Dumper \@points;

    open my $out_fh, '>', 'distances.txt'or die "cannot open distances.txt: $!\";

    for my $i1 (0 ..$#points -1 ){
    my ($x1, $y1, $z1) = @{$points[$i1]};
    for my $i2 (1 ..$points){
    my ($x2, $y2, $z2) =@{$points[$i2]};
    my $dist = sqrt(($x2-$x1)**2 + ($y2-$y1)**2 + ($z2-$z2)**2);
    print $out_fh "distance from ($x1, $y1, $z1) to ($x2, $y2, $z2) is $dist\n" or die "cannot print to distances.txt:$!\n;
    }
    }
    close $out_fh or die"cannot close distances.txt: $!\n";

    If someone can help it willbe awsome.

    Thanks a lot Keath

IMN logo majestic logo threadwatch logo seochat tools logo