in reply to Re: Confused when reading Input within Perl and Shell Scripts
in thread Confused when reading Input within Perl and Shell Scripts

Ok, bear with me. I have used the suggestion:

my $dssp_obj = new Bio::Structure::SecStr::DSSP::Res('-file'=>$ARGV[0] +);

Which works (and I'm ignoring several filehandle warnings). Now, I have written a shell script:

#!/bin/bash while read DSSPLine ; do echo $DSSPLine DSSP_Output.pl $DSSPLine.dssp done

QUESTION: In each interation, the output of DSSP_Output.pl is written to a CSV file. Is there a way such that (in perl) this output is written for all 30,000 iterations to one file only?

The very obvious answer is to use a DSSP array like you mentioned, I have tried that (in a way):

use strict; # 'use strict' requires that you use 'my' for all local va +riables, or explicitely qualify all globals. use warnings; use Bio::Structure::SecStr::DSSP::Res; my @dssp_objs =(); foreach my $file (@ARGV) { push @dssp_objs, Bio::Structure::SecStr::DSSP::Res->new('-file'=>$file +); } foreach my $dssp_obj(@dssp_objs) { #Get PDB ID and Compound representation for each file my $pdb_id = $dssp_obj->pdbID(); print "Analysis of PDB:: ". $pdb_id. "\n"; my $cmpd = $dssp_obj->pdbCompound(); print "Representing:: ". $cmpd. "\n"; etc... }

But when I do this, and run the commandline with a txt file of the DSSP filenames:

 DSSP_Output.pl DSSP_codes.txt

I get an exception!

Please let me know what you think...apologies for all the headache...

A <slowly deconfusing> InfoSeeker

Replies are listed 'Best First'.
Re^3: Confused when reading Input within Perl and Shell Scripts
by gwadej (Chaplain) on Nov 17, 2008 at 01:04 UTC

    The approach I gave would have worked if you had all of the list of filenames on the command line. If you want to take the list of filenames from a file, then we need to modify the input loop somewhat:

    my @dssp_objs =(); #reads the files from the command line one line at a time. while(<>) { chomp; # remove the newline. push @dssp_objs, Bio::Structure::SecStr::DSSP::Res->new('-file'=>$_); }

    This code would read a line at a time out of DSSP_codes.txt (using your example).

    I changed to the while(<>) loop just to be consistent with the way most people do this kind of loop. Since it automatically loads the $_ variable (and the loop is pretty short), I removed the $file variable. Otherwise, this is a drop-in replacement for the previous loop that should meet your needs.

    G. Wade