minnie has asked for the wisdom of the Perl Monks concerning the following question:
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.
(Here the sub routince call is not considered...why?)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
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)]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help regarding the outout of the program
by Your Mother (Archbishop) on Feb 24, 2010 at 04:20 UTC | |
|
Re: Help regarding the outout of the program
by jwkrahn (Abbot) on Feb 24, 2010 at 04:36 UTC | |
|
Re: Help regarding the outout of the program
by Utilitarian (Vicar) on Feb 24, 2010 at 08:54 UTC | |
by roboticus (Chancellor) on Feb 24, 2010 at 12:04 UTC |