Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: I'm trying to consolidate my functions into subroutines

by Anonymous Monk
on May 14, 2017 at 07:52 UTC ( [id://1190256]=note: print w/replies, xml ) Need Help??


in reply to I'm trying to consolidate my functions into subroutines

Fix this

#!/usr/bin/perl -- # consolidated.pl # 2017-05-13-19:55:06 # # ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if while for " +-otr -opr -ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; Main( @ARGV ); exit( 0 ); sub Main { my $infile = "human_hg19_circRNAs_putative_spliced_sequence.fa"; my( $seq, $id ) = ReadHashSequences( $infile ); my( $min, $max ) = PromptMinMax(); SpecifySeqLengths( $seq, $min, $max ); } sub ReadHashSequences { my( $infile ) = @_; use autodie qw/ open /; open my( $fh ), '<', $infile; my %seq = (); my $id = ''; while( <$fh> ) { chomp; if( $_ =~ /^>(.+)/ ) { $id = $1; } else { $seq{$id} .= $_; } } close $fh; return \%seq, $id; } ## end sub ReadHashSequences sub Prompt { my( $msg, $default ) = @_; ...; return $default; } sub PromptMinMax { my( $def_min, $def_max ) = grep defined, @_, 0, 10; my $min = Prompt( "Enter Max sequence length:", $def_min ); my $max = Prompt( "Enter Min sequence length:", $def_max ); return $min, $max; } sub SpecifySeqLengths { my( $seq, $minlength, $maxlength ) = @_; for my $id ( keys %$seq ) { if( ( length $seq->{$id} <= $maxlength ) && ( length $seq->{$id} >= $minlength ) ) { PunchFile( "SeqLength_$minlength-$maxlength", $id, $seq->{ +$id} ); } } } ## end sub SpecifySeqLengths sub PunchFile { my( $newfile, $id, $val ) = @_; if( -f $id ) { print $id, " already exists. It is about to be overwritten\n"; } use autodie qw/ open /; open my( $newfh ), '>>', $newfile; print $newfh $id, "\n", $val, "\n"; close $newfh; } ## end sub PunchFile __END__ $ perl consolidated.pl Can't open 'human_hg19_circRNAs_putative_spliced_sequence.fa' for read +ing: 'No such file or directory' at consolidated.p l line 23

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1190256]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-26 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found