Hi I have written a simple program to print a string with one character of the string changed to either A,C,G or T. This is a simple bioinformatics program to generate a SNP. I see the output with as well as without the print statement of the subroutine for some unknown reason.

Actual possible output (out of many expected) should be: The DNA sequence is: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA mutation at base position 5 AAAATAAAAAAAAAAAAAAAAAAAAAAAAA But sometimes the following is obtained: The DNA sequence is: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
(Here the sub routince call is not considered...why?)

Can anybody help me with the reason for this. Thanks in advance, minnie

Program code is as follows:
#!/usr/bin/perl -w print "The DNA sequence is : \n" ; my $seq = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; print "$seq \n"; mutate ($seq); print "\n"; exit; sub mutate{ my($dna) = @_; my $position = randposition($dna); for ($i =0;$i<length($dna);$i++){ if ($i == $position){ print " mutation at base position ". ($position+1) . "\n"; do { $nucleotide = randombase(); } until ($nucleotide ne substr($dna,$position,1)); substr($dna, $position, 1, $nucleotide); print "$dna\n"; } $i++; } } sub randposition{ my($sequence) = @_; return int rand length($sequence); } sub randombase{ my(@nucleo) =('A','T','C','G'); return $nucleo[rand(@nucleo)]; }

In reply to Help regarding the outout of the program by minnie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.