On Thu, Aug 04, 2011 at 02:33:19PM +0530, VinoRex.E wrote:
> Hi
> i am a beginner in Perl i have a pdb file containing the X,Y,and Z
> coordinates of atoms example given below. the data extends upto 1000 atoms
> and its coordinates. I need a perl program to export these data into excel
> worksheet into distinct columns and ROws.
>
> ATOM 1 N GLY A 2 1.888 -8.251 -2.511 1.00 36.63
> N
> ATOM 2 CA GLY A 2 2.571 -8.428 -1.248 1.00 33.02
> C
> ATOM 3 C GLY A 2 2.586 -7.069 -0.589 1.00 30.43
> C
Here's one way:
#!/usr/bin/perl
# convert raw data file to *.csv which can be loaded by Excel
use strict; # this can be removed when all bugs are fixed
use warnings; # more control than -w
my ($str, @fields);
open my $fh, '<', 'data.pdb' or die "Unable to open DATA: $!";
while( my $line = <$fh> )
{ chomp $line;
@fields = split /\s+/, $line;
if( @fields == 1 )
{ $str .= "," . $line;
print $str, "\n";
}
else
{ $str = join ",", @fields;
}
}
close $fh;
Mike
--
Satisfied user of Linux since 1997.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/