Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #generate a random DNA strings and print it to file specified by the user.
- print "What is the name of the output file?\n";
- $rstrings = <STDIN>;
- open (OUT, ">$rstrings");
- print "How many nucleotides for the string?\n";
- $n = <>;
- print "How many strings?\n";
- $num = <>;
- $numstring = ''; # start with the empty string;
- $i = 0;
- $j = 0;
- while ($j < $num) {
- while ($i < $n) {
- $numstring = int(rand(4)) . $numstring; # generate a new random integer
- # between 0 and 3, and concatenate
- # it with the existing $numstring,
- # assigning the result to $numstring.
- $i++; # increase the value of $i by one.
- }
- $j++;
- $i = 0;
- $dnastring = $numstring; # unneeded, but good for clarity.
- $dnastring =~ tr/0123/actg/; # translate the numbers to DNA characters.
- print OUT "$dnastring\n";
- $numstring = ''; # start with the empty string;
- }
- $dnastring = $numstring; # unneeded, but good for clarity.
- $dnastring =~ tr/0123/actg/; # translate the numbers to DNA characters.
- print OUT "$dnastring\n";
- close (OUT);
- open (IN, "$rstrings");
- open (OUT, ">LCSavg");
- $line = <IN>;
- chomp $line;
- @string1 = split(//, $line);
- $sum = 0;
- $V = 1;
- $Im = 0;
- $Cm = 0;
- $avg = 0;
- while ($string2 = <IN>) {
- chomp $string2;
- @string2 = split(//, $string2);
- $n = @string1; #assigning a list to a scalar just assigns the
- #number of elements in the list to the scalar.
- $m = @string2;
- for ($i = 1; $i <= $n; $i++) { # Assign the column 0 values and print
- # String 1 See section 5.2 of Johnson
- # for loops
- $V[$i][0] = $i * $Im;
- # print OUT "$string1[$i-1]"; # Note the -1 here because array indexes start at 0 (ug!)
- }
- # print OUT "\n\n";
- for ($j = 1; $j <= $m; $j++) { # Assign the row 0 values and print String 2
- $V[0][$j] = $j * $Im;
- # print OUT "$string2[$j-1]";
- }
- for ($i = 1; $i <= $n; $i++) { # follow the recurrences to fill in the V matrix.
- for ($j = 1; $j <= $m; $j++) {
- # print OUT "$string1[$i-1], $string2[$j-1]\n"; # This is here for debugging purposes.
- if ($string1[$i-1] eq $string2[$j-1]) {
- $t = $V; }
- else {
- {
- $t = $Cm;
- }
- }
- $max = $V[$i-1][$j-1] + $t;
- # print OUT "For $i, $j, t is $t \n"; # Another debugging line.
- if ($max < $V[$i][$j-1] - 1) {
- $max = $V[$i][$j-1] + $Im;
- }
- if ($V[$i-1][$j] - 1 > $max) {
- $max = $V[$i-1][$j] + $Im;
- }
- $V[$i][$j] = $max;
- }
- }
- print OUT "String LCS is $max\n";
- $sum = $sum + $max;
- }
- $avg = $sum / $num;
- print OUT "Average of all LCS is$avg\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement