[ Top-posting fixed ]

Mike Robeson wrote:
> 
> In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (John W. Krahn)
> wrote:
> >
> > You keep changing the specs Mike.  :-)   Based on your code and data above,
> > this will work:
> >
> > #!/usr/bin/perl
> > use warnings;
> > use strict;
> >
> > print "Enter the path of the INFILE to be processed: ";
> > chomp( my $infile = <STDIN> );
> > open INFILE, $infile or die "Can't open $infile for input: $!";
> >
> > print "Enter in the path of the OUTFILE: ";
> > chomp( my $outfile = <STDIN> );
> > open OUTFILE, ">$outfile" or die "Can't open $outfile for output: $!";
> >
> > print "Enter in the LENGTH you want the sequence to be: ";
> > my ( $len ) = <STDIN> =~ /(\d+)/ or die "Invalid length parameter";
> >
> > print OUTFILE "R 1 $len\n\n"; # The top of the file is supposed
> >
> > $/ = '>';  # Set input record separator
> >
> > while ( <INFILE> ) {
> >     chomp;
> >     next unless s/^\s*(\S+)//;
> >     my $name = $1;
> >     my @char = ( /[acgt]/g, ( '-' ) x $len )[ 0 .. $len - 1 ];
> >     print OUTFILE " @char       $name\n";
> >     }
> >
> > close INFILE;
> > close OUTFILE;
> >
> > __END__
> 
> Yeah, the parameters keep changing because my buddy and I had
> incorrectly remembered the format it was supposd to be (several times).

If you think it's hard on your end, the only data I can test on is the
data you post here.  :-)


> Sorry about that. Anyway, what you provided did work with some changes.
> the code you sent didn't do anything other than give me the command
> promt again - but I managed to get it to work anyway. However, I can't
> seem to figure out why I cannot use this line:
> 
> my @char = ( split( // ), ( '-' ) x ( $len - length ) );

split( // ) returns a list of ALL the characters in $_ and the use of
length() assumes that ONLY valid characters are in $_


> instead of this line:
> 
> my @char = ( /[a-z]/ig, ( '-' ) x $len )[ 0 .. $len - 1 ];

/[acgt]/g returns a list of ONLY the characters 'a', 'c', 'g' and 't'
and using the list slice assumes that there may be invalid characers in
$_


> in the script - I get errors ( I mean there are other changes that need
> to be made but these lines are my major focus). I just like the way the
> first line of code calculates the amount of dashes to add. It's just an
> aesthetic thing. :-)

It works fine if you KNOW that ONLY valid characters are in $_.


> Note I changed it to a-z because we use many other
> characters than "atcg", for example "n" means "unkown base". Also, just
> do not understand as clearly the second line of code above as I do the
> first. From what I can gather you are making, say, 50 dashes and then
> "filling in" the dashes that match the charatcers within [a-z] from left
> to right as long as there are characters to "fill in" the dashes. Does
> that make sense?

//g creates a list of valid characters from $_ with $len hyphens
appended on the end and that list is sliced to the length of $len.


> Anyway, when I add "$/ = '>';" to the original script below I get a
                                                 ^^^^^^^^^^^^
I see no script below.

> contatination error (why?). Basically, I am trying to understand why

Did you chomp the input?  Did you test for valid data before processing
it?

> certain bits of code "break" the script and others don't. I find I learn
> things better by trying alternate forms of code to figure out
> relationships. However, I have been looking through my perl books like
> crazy and can't seem to understand some of these relationships. I know
> it will take time and experience... I guess I'll pick up another perl
> book that provides another perspective.
> 
> Sorry about taking so long with this, I am trying to make an honest
> effort to learn. :-)

No problem.   :-)


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to