Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Keep It Simple, Stupid
 
PerlMonks  

Can any Perl Monk help me to correct the mistake in counting motifs in a string in the perl program written by me?

by supriyoch_2008 (Scribe)
on Dec 12, 2011 at 10:28 UTC ( #943057=perlquestion: print w/ replies, xml ) Need Help??
supriyoch_2008 has asked for the wisdom of the Perl Monks concerning the following question:

Comment on Can any Perl Monk help me to correct the mistake in counting motifs in a string in the perl program written by me?
Re: Can any Perl Monk help me to correct the mistake in counting motifs in a string in the perl program written by me?
by Corion (Pope) on Dec 12, 2011 at 10:30 UTC

    Have you looked at line 38?

      Dear Sir,

      I have seen the line 38. But I could not correct it because it is only 6 (six) days that I have been exposed to perl programming. I have read only chapter 3 and 4 of the book "Beginning Perl for Bioinformatics" by James Tisdall. But I failed to correct the mistake. I am learning it with my own efforts i.e. self study.

      Chakraborty

Re: Can any Perl Monk help me to correct the mistake in counting motifs in a string in the perl program written by me?
by marto (Chancellor) on Dec 12, 2011 at 10:35 UTC
Re: Can any Perl Monk help me to correct the mistake in counting motifs in a string in the perl program written by me?
by Utilitarian (Vicar) on Dec 12, 2011 at 10:43 UTC
    This is a public message board, why would I send a solution to you without it being available to other monks to learn from? (and me to show off with of course)

    From perldoc perlop and searching for transliteration we discover that

    Because the transliteration table is built at compile time, neither th +e SEARCHLIST nor the REPLACEMENTLIST are subjected to double quote interpolation. That means that if you w +ant to use variables, you must use an eval(): eval "tr/$oldlist/$newlist/"; die $@ if $@;
    So that may be part of your issue, or at least it will be when you remove the g modifier which makes no sense with athe tr opperator

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
Re: Can any Perl Monk help me to correct the mistake in counting motifs in a string in the perl program written by me?
by pvaldes (Hermit) on Dec 12, 2011 at 13:31 UTC

    not really sure what is a motif here, but this can't stop me to fail, of course XDD ... please, save the facepalms for the end, thanks ;-)

    Only a draft, unworking and untested...but can give you some ideas

    use 5.010; my ($file, $motif) = @ARGV; my $warn = <<'EOF'; Number or arguments incorrect, Please run this program with 2 arguments, a file and a motif to count the number of letters between any two motifs: i.e. perl script.pl myfile mymotif EOF if (scalar @ARGV != 2) {print $warn} if (scalar @ARGV == 2){ open (my $DNAFILE, '<', $file) or die "I need that you provide a file. Cannot open file $!"; ## $DNAFILE = join( '', @DNA); ## don't understand this line ... can you explain this? $DNAFILE =~ s/\s//g; # Remove whitespace, ok if ( $DNAFILE =~ /$motif/ ) { print "\nI found it!\n"; # Count number of nt between two motifs my $string ="@DNA"; # same question, explain please, why do you need t +his? ## mmmh... are you trying to say "\@DNA"? say "Lengths are:", $_ for map { sprintf("%d", length) } split /$ +motif/, $string; # Count number of motifs my $count=($string =~ m/$motif/g); print "Number of motifs: $count.\n\n"; close DNAFILE; } else { print "The motif: $motif was not found in the file $file.\n"} } # first else block __END__

    Your turn

    (Updated: problem with $warn fixed)

Re: Can any Perl Monk help me to correct the mistake in counting motifs in a string in the perl program written by me?
by cdarke (Prior) on Dec 12, 2011 at 14:39 UTC
    You have a space between the = and the ~ just before tr on line 38. The ~ is an operator on its own, so perl thinks you are doing an assignment.

    That's only your first issue though...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://943057]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2014-04-23 21:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (555 votes), past polls