TJCooper has asked for the wisdom of the Perl Monks concerning the following question:
I'm not familiar much at all with user-input in Perl as I never usually bother however in this case it's required. What would be the best way to incorporate user-input into this such that the user can type in the search patterns (GATCR GGCC) etc. Thanks!use warnings; use strict; use File::Basename; my $name = basename($0); my $usage = "\nUsage (OSX Terminal/Windows Cmd-Prompt): perl <$name> < +.FASTA or.FA File> <Results Directory>\n\n"; #Scanning for restriction sites and length-output my $infile1 = shift or die $usage; open(my $in, "<", shift); open(my $out, ">", shift); my $DNA = read_fasta($in); my $len = length($$DNA); print "\n FASTA/Sequence Length is: $len bp \n"; my @pats=qw( GATCR GGCC ); for (@pats) { s/K/[GT]/g; s/M/[AC]/g; s/Y/[CT]/g; s/S/[CG]/g; s/W/[AT]/g; s/B/[CGT]/g; s/V/[ACG]/g; s/H/[ACT]/g; s/D/[AGT]/g; s/X/[AGCT]/g; s/R/[AG]/g; s/N/[AGCT]/g; } for (@pats) { my $m = () = $$DNA =~ /$_/gi; print "\n Total DNA matches to $_ are: $m \n"; } my $pat=join("|",@pats); my @cutarr = split(/$pat/, $$DNA); for (@cutarr) { my $len = length($_); print $out "$len \n"; } close($out); close($in); #Subfunction - Reading formatted FASTA/FA files sub read_fasta { my ($in) = @_; my $sequence = ""; while(<$in>) { my $line = $_; chomp($line); if($line =~ /^>/){ next } else { $sequence .= $line } } return(\$sequence); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Searching for strings specified via user input
by AppleFritter (Vicar) on May 01, 2014 at 11:36 UTC | |
by TJCooper (Beadle) on May 01, 2014 at 11:59 UTC | |
by AppleFritter (Vicar) on May 01, 2014 at 16:13 UTC | |
|
Re: Searching for strings specified via user input
by Anonymous Monk on May 01, 2014 at 11:56 UTC |