Who can program (specifically, in Perl)?

Magrathean

worldbuilder
Oct 14, 2005
6,987
4
38
Faculty of Science
s1.zetaboards.com
I finally finished the little program i'd been working on since last year. It's nothing too great or useful, but i'm proud of it. It's the first thing i really program on my own (i.e. without a book by my side telling me exactly what to do and only letting me change the font size), so don't burst my bubble for a while. :)

Anywho, here it is (in case anyone cares): a little program which compares two DNA sequences and finds any mutations in them:

Code:
print "\n\nWelcome.\n\nWe will compare two DNA sequences and analyze any mutations.\n\nPlease choose a sequence length (in multiples of 3): ";
$length=<STDIN>;
while ($length%3!=0)
	{
		print "That is not a multiple of 3. Please choose another sequence length: ";
		$length=<STDIN>;
	}
print "\nVery well. Now write the first sequence.\n";
$nt=1;
while ($nt<=$length)
	{
		print "Nucleotide $nt: ";
		$seq1[$nt]=<STDIN>;
		if (($seq1[$nt]=~"A")||($seq1[$nt]=~"a"))
			{
				$seq1[$nt]='A';
				$nt++;
			}
		elsif (($seq1[$nt]=~"C")||($seq1[$nt]=~"c"))
			{
				$seq1[$nt]='C';
				$nt++;
			}
		elsif (($seq1[$nt]=~"G")||($seq1[$nt]=~"g"))
			{
				$seq1[$nt]='G';
				$nt++;
			}
		elsif (($seq1[$nt]=~"T")||($seq1[$nt]=~"t"))
			{
				$seq1[$nt]='T';
				$nt++;
			}
		elsif (($seq1[$nt]=~"U")||($seq1[$nt]=~"u"))
			{
				print "Uracil only exists in RNA. We are working with DNA.\n";
			}
		else
			{
				print "That nucleotide doesn't exist. Please write A, C, G or T.\n";
			}
	}
print "\nNow write the second sequence.\n";
$nt=1;
while ($nt<=$length)
	{
		print "Nucleotide $nt: ";
		$seq2[$nt]=<STDIN>;
		if (($seq2[$nt]=~"A")||($seq2[$nt]=~"a"))
			{
				$seq2[$nt]='A';
				$nt++;
			}
		elsif (($seq2[$nt]=~"C")||($seq2[$nt]=~"c"))
			{
				$seq2[$nt]='C';
				$nt++;
			}
		elsif (($seq2[$nt]=~"G")||($seq2[$nt]=~"g"))
			{
				$seq2[$nt]='G';
				$nt++;
			}
		elsif (($seq2[$nt]=~"T")||($seq2[$nt]=~"t"))
			{
				$seq2[$nt]='T';
				$nt++;
			}
		elsif (($seq2[$nt]=~"U")||($seq2[$nt]=~"u"))
			{
				print "Uracil only exists in RNA. We are working with DNA.\n";
			}
		else
			{
				print "That nucleotide doesn't exist. Please write A, C, G or T.\n";
			}
		}
print "\nVerification:\n\nSequence 1: ";
$nt=1;
while ($nt<=$length)
	{
		print ("$seq1[$nt]");
		$nt++;
	}
$nt=1;
print ("\nSequence 2: ");
while ($nt<=$length)
	{
		print ("$seq2[$nt]");
		$nt++;
	}
print "\n\nIs this correct? (y/n) ";
$yes=<STDIN>;
while (($yes!=~"y")&&($yes!=~"Y")&&($yes!=~"n")&&($yes!=~"N"))
	{
		print ("Please state whether these sequences are correct (y/n): ");
		$yes=<STDIN>;
	}
while (($yes=~"n")||($yes=~"N"))
	{
		print "\nWrite the first sequence again.\n";
		$nt=1;
		while ($nt<=$length)
			{
				print "Nucleotide $nt: ";
				$seq1[$nt]=<STDIN>;
				if (($seq1[$nt]=~"A")||($seq1[$nt]=~"a"))
					{
						$seq1[$nt]="A";
						$nt++;
					}
				elsif (($seq1[$nt]=~"C")||($seq1[$nt]=~"c"))
					{
						$seq1[$nt]="C";
						$nt++;
					}
				elsif (($seq1[$nt]=~"G")||($seq1[$nt]=~"g"))
					{
						$seq1[$nt]="G";
						$nt++;
					}
				elsif (($seq1[$nt]=~"T")||($seq1[$nt]=~"t"))
					{
						$seq1[$nt]="T";
						$nt++;
					}
				elsif (($seq1[$nt]=~"U")||($seq1[$nt]=~"u"))
					{
						print "Uracil only exists in RNA. We are working with DNA.\n";
					}
				else
					{
						print "That nucleotide doesn't exist. Please write A, C, G or T.\n";
					}
			}
		print "\nNow write the second sequence.\n";
		$nt=1;
		while ($nt<=$length)
			{
				print "Nucleotide $nt: ";
				$seq2[$nt]=<STDIN>;
				if (($seq2[$nt]=~"A")||($seq2[$nt]=~"a"))
					{
						$seq2[$nt]="A";
						$nt++;
					}
				elsif (($seq2[$nt]=~"C")||($seq2[$nt]=~"c"))
					{
						$seq2[$nt]="C";
						$nt++;
					}
				elsif (($seq2[$nt]=~"G")||($seq2[$nt]=~"g"))
					{
						$seq2[$nt]="G";
						$nt++;
					}
				elsif (($seq2[$nt]=~"T")||($seq2[$nt]=~"t"))
					{
						$seq2[$nt]="T";
						$nt++;
					}
				elsif (($seq2[$nt]=~"U")||($seq2[$nt]=~"u"))
					{
						print "Uracil only exists in RNA. We are working with DNA.\n";
					}
				else
					{
						print "That nucleotide doesn't exist. Please write A, C, G or T.\n";
					}
				}
		print "\nVerification:\n\nSequence 1: ";
		$nt=1;
		while ($nt<=$length)
			{
				print ("$seq1[$nt]");
				$nt++;
			}
		$nt=1;
		print ("\nSequence 2: ");
		while ($nt<=$length)
			{
				print ("$seq2[$nt]");
				$nt++;
			}
		print "\n\nIs this correct? (y/n) ";
		$yes=<STDIN>;
	}
if (($yes=~"y")||($yes=~"Y"))
	{
		print "\nProcessing...\n\n";
		$identical=1;
		$nt=1;
		while ($nt<=$length)
			{
				if ($seq1[$nt] eq $seq2[$nt])
					{
						$mutation[$nt]=0;
					}
				else
					{
						$mutation[$nt]=1;
						$identical=0;
					}
				$nt++;
			}
		$nt=1;
		$aa=1;
		while ($nt<=$length)
			{
				if (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "C"))
					{
						$aa1[$aa]="alanine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] ne "T"))
					{
						$aa1[$aa]="cysteine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] ne "C"))
					{
						$aa1[$aa]="cysteine";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] ne "C"))
					{
						$aa1[$aa]="aspartate";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] ne "T"))
					{
						$aa1[$aa]="aspartate";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] ne "G"))
					{
						$aa1[$aa]="glutamate";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] ne "A"))
					{
						$aa1[$aa]="glutamate";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "T")&&($seq1[$nt+2] ne "C"))
					{
						$aa1[$aa]="phenylalanine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "T")&&($seq1[$nt+2] ne "T"))
					{
						$aa1[$aa]="phenylalanine";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "G"))
					{
						$aa1[$aa]="glycine";
					}
				elsif (($seq1[$nt] eq "C")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] ne "C"))
					{
						$aa1[$aa]="histidine";
					}
				elsif (($seq1[$nt] eq "C")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] ne "T"))
					{
						$aa1[$aa]="histidine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "T")&&($seq1[$nt+2] ne "G"))
					{
						$aa1[$aa]="isoleucine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "A"))
					{
						$aa1[$aa]="lysine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "G"))
					{
						$aa1[$aa]="lysine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "T")&&($seq1[$nt+2] eq "G"))
					{
						$aa1[$aa]="leucine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "T")&&($seq1[$nt+2] eq "A"))
					{
						$aa1[$aa]="leucine";
					}
				elsif (($seq1[$nt] eq "C")&&($seq1[$nt+1] eq "T"))
					{
						$aa1[$aa]="leucine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "T")&&($seq1[$nt+2] eq "G"))
					{
						$aa1[$aa]="methionine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "C"))
					{
						$aa1[$aa]="asparagine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "T"))
					{
						$aa1[$aa]="asparagine";
					}
				elsif (($seq1[$nt] eq "C")&&($seq1[$nt+1] eq "C"))
					{
						$aa1[$aa]="proline";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "G"))
					{
						$aa1[$aa]="glutamine";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "A"))
					{
						$aa1[$aa]="glutamine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] eq "G"))
					{
						$aa1[$aa]="arginine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] eq "A"))
					{
						$aa1[$aa]="arginine";
					}
				elsif (($seq1[$nt] eq "C")&&($seq1[$nt+1] eq "G"))
					{
						$aa1[$aa]="arginine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] eq "T"))
					{
						$aa1[$aa]="serine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] eq "C"))
					{
						$aa1[$aa]="serine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "C"))
					{
						$aa1[$aa]="serine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "C"))
					{
						$aa1[$aa]="threonine";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "T"))
					{
						$aa1[$aa]="valine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] eq "G"))
					{
						$aa1[$aa]="tryptophan";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "T"))
					{
						$aa1[$aa]="tyrosine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "C"))
					{
						$aa1[$aa]="tyrosine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "A"))
					{
						$aa1[$aa]="a stop codon";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] eq "A"))
					{
						$aa1[$aa]="a stop codon";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "G"))
					{
						$aa1[$aa]="a stop codon";
					}
				$nt+=3;
				$aa++;
			}
		$nt=1;
		$aa=1;
		while ($nt<=$length)
			{
				if (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "C"))
					{
						$aa2[$aa]="alanine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] ne "T"))
					{
						$aa2[$aa]="cysteine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] ne "C"))
					{
						$aa2[$aa]="cysteine";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] ne "C"))
					{
						$aa2[$aa]="aspartate";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] ne "T"))
					{
						$aa2[$aa]="aspartate";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] ne "G"))
					{
						$aa2[$aa]="glutamate";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] ne "A"))
					{
						$aa2[$aa]="glutamate";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "T")&&($seq2[$nt+2] ne "C"))
					{
						$aa2[$aa]="phenylalanine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "T")&&($seq2[$nt+2] ne "T"))
					{
						$aa2[$aa]="phenylalanine";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "G"))
					{
						$aa2[$aa]="glycine";
					}
				elsif (($seq2[$nt] eq "C")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] ne "C"))
					{
						$aa2[$aa]="histidine";
					}
				elsif (($seq2[$nt] eq "C")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] ne "T"))
					{
						$aa2[$aa]="histidine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "T")&&($seq2[$nt+2] ne "G"))
					{
						$aa2[$aa]="isoleucine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "A"))
					{
						$aa2[$aa]="lysine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "G"))
					{
						$aa2[$aa]="lysine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "T")&&($seq2[$nt+2] eq "G"))
					{
						$aa2[$aa]="leucine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "T")&&($seq2[$nt+2] eq "A"))
					{
						$aa2[$aa]="leucine";
					}
				elsif (($seq2[$nt] eq "C")&&($seq2[$nt+1] eq "T"))
					{
						$aa2[$aa]="leucine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "T")&&($seq2[$nt+2] eq "G"))
					{
						$aa2[$aa]="methionine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "C"))
					{
						$aa2[$aa]="asparagine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "T"))
					{
						$aa2[$aa]="asparagine";
					}
				elsif (($seq2[$nt] eq "C")&&($seq2[$nt+1] eq "C"))
					{
						$aa2[$aa]="proline";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "G"))
					{
						$aa2[$aa]="glutamine";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "A"))
					{
						$aa2[$aa]="glutamine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] eq "G"))
					{
						$aa2[$aa]="arginine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] eq "A"))
					{
						$aa2[$aa]="arginine";
					}
				elsif (($seq2[$nt] eq "C")&&($seq2[$nt+1] eq "G"))
					{
						$aa2[$aa]="arginine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] eq "T"))
					{
						$aa2[$aa]="serine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] eq "C"))
					{
						$aa2[$aa]="serine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "C"))
					{
						$aa2[$aa]="serine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "C"))
					{
						$aa2[$aa]="threonine";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "T"))
					{
						$aa2[$aa]="valine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] eq "G"))
					{
						$aa2[$aa]="tryptophan";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "T"))
					{
						$aa2[$aa]="tyrosine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "C"))
					{
						$aa2[$aa]="tyrosine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "A"))
					{
						$aa2[$aa]="a stop codon";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] eq "A"))
					{
						$aa2[$aa]="a stop codon";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "G"))
					{
						$aa2[$aa]="a stop codon";
					}
				$nt+=3;
				$aa++;
			}
		$nt=1;
		$aa=1;
		if ($identical==1)
			{
				print "The two sequences are identical.\n\n";
			}
		else
			{
				$mutationcounter=0;
				while ($nt<=$length)
					{
						$mutationcounter=0;
						if ($mutation[$nt]==1)
							{
								$mutationcounter++;
								$aa=($nt+2)/3;
							}
						if ($mutation[$nt+1]==1)
							{
								$mutationcounter++;
								$aa=($nt+2)/3;
							}
						if ($mutation[$nt+2]==1)
							{
								$mutationcounter++;
								$aa=($nt+2)/3;
							}
						if ($mutationcounter==1)
							{
								print "There is one ";
								if ($aa1[$aa] eq $aa2[$aa])
									{
										print "synonymous mutation in codon $aa.\n";
									}
								else
									{
										print "mutation in codon $aa which causes $aa2[$aa] to substitute $aa1[$aa].\n";
									}
							}
						elsif ($mutationcounter==2)
							{
								print "There are two ";
								if ($aa1[$aa] eq $aa2[$aa])
									{
										print "synonymous mutations in codon $aa.\n";
									}
								else
									{
										print "mutations in codon $aa which cause $aa2[$aa] to substitute $aa1[$aa].\n";
									}
							}
						elsif ($mutationcounter==3)
							{
								print "There are three mutations in codon $aa which cause $aa2[$aa] to substitute $aa1[$aa].\n";
							}
						$nt+=3;
					}
				print "\n";
			}
	}
Questions / comments / suggestions / corrections / dinner invitations?
 
i say this stays, the other thread was never very successful, this is a specific question to boot, and i don't really see people starting dozens of new ones about computer programming. it's not as if we're on the internet or something.
 
rahvin: Thanks (i think).

mardy: :) It's not that hard once you learn to read it (almost everything makes sense, and whatever doesn't you just memorize :D).

plintus: Those are to tell the program which codons code for which aminoacids.
 
Hey thanks for the correction... and yeah, It's very cool, I made like thousand games hahaha, chess and stuffs like that... but finally the music wins and my family support me, because I was interested in music since I was a child, and my parents knew that :). It was a very difficult desicion.
 
I didn't test it, well, I never used the Perl language so I don't recognize the librarys but looks familiar, like C++ hahahaha. Questions: why not Java?
This is your first program? a "DNA mutation's finder" is quite original! I made one to find the mass of a star! hahaha oh the good old times:)...

one more thing... What are you studing? is something related with this or not... maybe you are a self-teached talent :)
 
BastardSonOfGod said:
Perl (...) looks familiar, like C++
It's rather similar. A few changes here and there, and it's easier to use, but i like C++ better.

BastardSonOfGod said:
why not Java?
Because i don't know Java. :(

BastardSonOfGod said:
This is your first program?
I made a word processor some time ago, but that was kind of copying codes from a book and changing font color, window layout, menu item names and so on, so it doesn't really count. So yes, this is my first program. :)

BastardSonOfGod said:
a "DNA mutation's finder" is quite original! I made one to find the mass of a star! hahaha oh the good old times:)...
Thanks! :) What happened to your star one? I love astronomy. :)

BastardSonOfGod said:
What are you studing? is something related with this or not...
Genomics (genetics with computers).

BastardSonOfGod said:
maybe you are a self-teached talent :)
I took basic programming last semester, but some of the codes on that program i made were self-taught (well, with tutorials, but no teachers). And lately i'm trying to teach myself more so i can build upon that program and improve it.

:)
 
My teacher of Algebra was an astronomy lover... he used to measure the mass of the stars for the NASA as a hobbie... so I made the program as a gift... I never used exept when I test it with my teacher of Informatic elements (I don't know the name in English for that signature so that's the literal traduction)... He was very happy :)... and about my programs, I left all that in Chile when I came here... so I lost them I think, because My brother bought a new computer for christmas and sold the old one :(

Anyway good job with the program, Genomics sounds really interesting... and damn difficult too :)
 
:) I liked your story. It sucks that you've lost those programs, but i suppose you could always program new things as a hobby. And, well, genomics isn't all that difficult (for me, anyway), but it's sure as hell interesting. :)
 
Version 0.2 (new and improved):

Code:
print "\n\nWelcome.\n\nWe will compare two DNA sequences and analyze any mutations.\n\nPlease choose a sequence length (in multiples of 3): ";
$length=<STDIN>;
while ($length==0)
	{
		print "Your sequence must have at least three nucleotides. Please choose a sequence length: ";
		$length=<STDIN>;
	}
$res=1;
if ($length%3==0)
	{
		$res=0;
	}
while ($res!=0)
	{
		print "That is not a multiple of 3. Please choose another sequence length: ";
		$length=<STDIN>;
		if ($length%3==0)
			{
				$res=0;
			}
	}
print "\nVery well. Now write the first sequence.\n";
$nt=1;
while ($nt<=$length)
	{
		print "Nucleotide $nt: ";
		$seq1[$nt]=<STDIN>;
		if (($seq1[$nt] eq "A\n")||($seq1[$nt] eq "a\n"))
			{
				$seq1[$nt]='A';
				$nt++;
			}
		elsif (($seq1[$nt] eq "C\n")||($seq1[$nt] eq "c\n"))
			{
				$seq1[$nt]='C';
				$nt++;
			}
		elsif (($seq1[$nt] eq "G\n")||($seq1[$nt] eq "g\n"))
			{
				$seq1[$nt]='G';
				$nt++;
			}
		elsif (($seq1[$nt] eq "T\n")||($seq1[$nt] eq "t\n"))
			{
				$seq1[$nt]='T';
				$nt++;
			}
		elsif (($seq1[$nt] eq "U\n")||($seq1[$nt] eq "u\n"))
			{
				print "Uracil only exists in RNA. We are working with DNA.\n";
			}
		else
			{
				print "That nucleotide doesn't exist. Please write A, C, G or T.\n";
			}
	}
print "\nNow write the second sequence.\n";
$nt=1;
while ($nt<=$length)
	{
		print "Nucleotide $nt: ";
		$seq2[$nt]=<STDIN>;
		if (($seq2[$nt] eq "A\n")||($seq2[$nt] eq "a\n"))
			{
				$seq2[$nt]='A';
				$nt++;
			}
		elsif (($seq2[$nt] eq "C\n")||($seq2[$nt] eq "c\n"))
			{
				$seq2[$nt]='C';
				$nt++;
			}
		elsif (($seq2[$nt] eq "G\n")||($seq2[$nt] eq "g\n"))
			{
				$seq2[$nt]='G';
				$nt++;
			}
		elsif (($seq2[$nt] eq "T\n")||($seq2[$nt] eq "t\n"))
			{
				$seq2[$nt]='T';
				$nt++;
			}
		elsif (($seq2[$nt] eq "U\n")||($seq2[$nt] eq "u\n"))
			{
				print "Uracil only exists in RNA. We are working with DNA.\n";
			}
		else
			{
				print "That nucleotide doesn't exist. Please write A, C, G or T.\n";
			}
		}
print "\nVerification:\nSequence 1: ";
$nt=1;
while ($nt<=$length)
	{
		print "$seq1[$nt]";
		$nt++;
	}
$nt=1;
print "\nSequence 2: ";
while ($nt<=$length)
	{
		print "$seq2[$nt]";
		$nt++;
	}
print "\nIs this correct? (y/n) ";
$yes=<STDIN>;
while (($yes ne "y\n")&&($yes ne "Y\n")&&($yes ne "n\n")&&($yes ne "N\n"))
	{
		print "Please state whether these sequences are correct (y/n): ";
		$yes=<STDIN>;
	}
while (($yes eq "n\n")||($yes eq "N\n"))
	{
		print "\nWrite the first sequence again.\n";
		$nt=1;
		while ($nt<=$length)
			{
				print "Nucleotide $nt: ";
				$seq1[$nt]=<STDIN>;
				if (($seq1[$nt] eq "A\n")||($seq1[$nt] eq "a\n"))
					{
						$seq1[$nt]='A';
						$nt++;
					}
				elsif (($seq1[$nt] eq "C\n")||($seq1[$nt] eq "c\n"))
					{
						$seq1[$nt]='C';
						$nt++;
					}
				elsif (($seq1[$nt] eq "G\n")||($seq1[$nt] eq "g\n"))
					{
						$seq1[$nt]='G';
						$nt++;
					}
				elsif (($seq1[$nt] eq "T\n")||($seq1[$nt] eq "t\n"))
					{
						$seq1[$nt]='T';
						$nt++;
					}
				elsif (($seq1[$nt] eq "U\n")||($seq1[$nt] eq "u\n"))
					{
						print "Uracil only exists in RNA. We are working with DNA.\n";
					}
				else
					{
						print "That nucleotide doesn't exist. Please write A, C, G or T.\n";
					}
			}
		print "\nNow write the second sequence.\n";
		$nt=1;
		while ($nt<=$length)
			{
				print "Nucleotide $nt: ";
				$seq2[$nt]=<STDIN>;
				if (($seq2[$nt] eq "A\n")||($seq2[$nt] eq "a\n"))
					{
						$seq2[$nt]='A';
						$nt++;
					}
				elsif (($seq2[$nt] eq "C\n")||($seq2[$nt] eq "c\n"))
					{
						$seq2[$nt]='C';
						$nt++;
					}
				elsif (($seq2[$nt] eq "G\n")||($seq2[$nt] eq "g\n"))
					{
						$seq2[$nt]='G';
						$nt++;
					}
				elsif (($seq2[$nt] eq "T\n")||($seq2[$nt] eq "t\n"))
					{
						$seq2[$nt]='T';
						$nt++;
					}
				elsif (($seq2[$nt] eq "U\n")||($seq2[$nt] eq "u\n"))
					{
						print "Uracil only exists in RNA. We are working with DNA.\n";
					}
				else
					{
						print "That nucleotide doesn't exist. Please write A, C, G or T.\n";
					}
				}
		print "\nVerification:\nSequence 1: ";
		$nt=1;
		while ($nt<=$length)
			{
				print "$seq1[$nt]";
				$nt++;
			}
		$nt=1;
		print "\nSequence 2: ";
		while ($nt<=$length)
			{
				print "$seq2[$nt]";
				$nt++;
			}
		print "\nIs this correct? (y/n) ";
		$yes=<STDIN>;
	}
if (($yes eq "y\n")||($yes eq "Y\n"))
	{
		print "\nProcessing...\n\n";
		$identical=1;
		$nt=1;
		while ($nt<=$length)
			{
				if ($seq1[$nt] eq $seq2[$nt])
					{
						$mutation[$nt]=0;
					}
				else
					{
						$mutation[$nt]=1;
						$identical=0;
					}
				$nt++;
			}
		$nt=1;
		$aa=1;
		while ($nt<=$length)
			{
				if (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "C"))
					{
						$aa1[$aa]="alanine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] ne "T"))
					{
						$aa1[$aa]="cysteine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] ne "C"))
					{
						$aa1[$aa]="cysteine";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] ne "C"))
					{
						$aa1[$aa]="aspartate";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] ne "T"))
					{
						$aa1[$aa]="aspartate";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] ne "G"))
					{
						$aa1[$aa]="glutamate";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] ne "A"))
					{
						$aa1[$aa]="glutamate";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "T")&&($seq1[$nt+2] ne "C"))
					{
						$aa1[$aa]="phenylalanine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "T")&&($seq1[$nt+2] ne "T"))
					{
						$aa1[$aa]="phenylalanine";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "G"))
					{
						$aa1[$aa]="glycine";
					}
				elsif (($seq1[$nt] eq "C")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] ne "C"))
					{
						$aa1[$aa]="histidine";
					}
				elsif (($seq1[$nt] eq "C")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] ne "T"))
					{
						$aa1[$aa]="histidine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "T")&&($seq1[$nt+2] ne "G"))
					{
						$aa1[$aa]="isoleucine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "A"))
					{
						$aa1[$aa]="lysine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "G"))
					{
						$aa1[$aa]="lysine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "T")&&($seq1[$nt+2] eq "G"))
					{
						$aa1[$aa]="leucine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "T")&&($seq1[$nt+2] eq "A"))
					{
						$aa1[$aa]="leucine";
					}
				elsif (($seq1[$nt] eq "C")&&($seq1[$nt+1] eq "T"))
					{
						$aa1[$aa]="leucine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "T")&&($seq1[$nt+2] eq "G"))
					{
						$aa1[$aa]="methionine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "C"))
					{
						$aa1[$aa]="asparagine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "T"))
					{
						$aa1[$aa]="asparagine";
					}
				elsif (($seq1[$nt] eq "C")&&($seq1[$nt+1] eq "C"))
					{
						$aa1[$aa]="proline";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "G"))
					{
						$aa1[$aa]="glutamine";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "A"))
					{
						$aa1[$aa]="glutamine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] eq "G"))
					{
						$aa1[$aa]="arginine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] eq "A"))
					{
						$aa1[$aa]="arginine";
					}
				elsif (($seq1[$nt] eq "C")&&($seq1[$nt+1] eq "G"))
					{
						$aa1[$aa]="arginine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] eq "T"))
					{
						$aa1[$aa]="serine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] eq "C"))
					{
						$aa1[$aa]="serine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "C"))
					{
						$aa1[$aa]="serine";
					}
				elsif (($seq1[$nt] eq "A")&&($seq1[$nt+1] eq "C"))
					{
						$aa1[$aa]="threonine";
					}
				elsif (($seq1[$nt] eq "G")&&($seq1[$nt+1] eq "T"))
					{
						$aa1[$aa]="valine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] eq "G"))
					{
						$aa1[$aa]="tryptophan";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "T"))
					{
						$aa1[$aa]="tyrosine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "C"))
					{
						$aa1[$aa]="tyrosine";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "A"))
					{
						$aa1[$aa]="a stop codon";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "G")&&($seq1[$nt+2] eq "A"))
					{
						$aa1[$aa]="a stop codon";
					}
				elsif (($seq1[$nt] eq "T")&&($seq1[$nt+1] eq "A")&&($seq1[$nt+2] eq "G"))
					{
						$aa1[$aa]="a stop codon";
					}
				$nt+=3;
				$aa++;
			}
		$nt=1;
		$aa=1;
		while ($nt<=$length)
			{
				if (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "C"))
					{
						$aa2[$aa]="alanine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] ne "T"))
					{
						$aa2[$aa]="cysteine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] ne "C"))
					{
						$aa2[$aa]="cysteine";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] ne "C"))
					{
						$aa2[$aa]="aspartate";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] ne "T"))
					{
						$aa2[$aa]="aspartate";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] ne "G"))
					{
						$aa2[$aa]="glutamate";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] ne "A"))
					{
						$aa2[$aa]="glutamate";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "T")&&($seq2[$nt+2] ne "C"))
					{
						$aa2[$aa]="phenylalanine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "T")&&($seq2[$nt+2] ne "T"))
					{
						$aa2[$aa]="phenylalanine";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "G"))
					{
						$aa2[$aa]="glycine";
					}
				elsif (($seq2[$nt] eq "C")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] ne "C"))
					{
						$aa2[$aa]="histidine";
					}
				elsif (($seq2[$nt] eq "C")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] ne "T"))
					{
						$aa2[$aa]="histidine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "T")&&($seq2[$nt+2] ne "G"))
					{
						$aa2[$aa]="isoleucine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "A"))
					{
						$aa2[$aa]="lysine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "G"))
					{
						$aa2[$aa]="lysine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "T")&&($seq2[$nt+2] eq "G"))
					{
						$aa2[$aa]="leucine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "T")&&($seq2[$nt+2] eq "A"))
					{
						$aa2[$aa]="leucine";
					}
				elsif (($seq2[$nt] eq "C")&&($seq2[$nt+1] eq "T"))
					{
						$aa2[$aa]="leucine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "T")&&($seq2[$nt+2] eq "G"))
					{
						$aa2[$aa]="methionine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "C"))
					{
						$aa2[$aa]="asparagine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "T"))
					{
						$aa2[$aa]="asparagine";
					}
				elsif (($seq2[$nt] eq "C")&&($seq2[$nt+1] eq "C"))
					{
						$aa2[$aa]="proline";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "G"))
					{
						$aa2[$aa]="glutamine";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "A"))
					{
						$aa2[$aa]="glutamine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] eq "G"))
					{
						$aa2[$aa]="arginine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] eq "A"))
					{
						$aa2[$aa]="arginine";
					}
				elsif (($seq2[$nt] eq "C")&&($seq2[$nt+1] eq "G"))
					{
						$aa2[$aa]="arginine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] eq "T"))
					{
						$aa2[$aa]="serine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] eq "C"))
					{
						$aa2[$aa]="serine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "C"))
					{
						$aa2[$aa]="serine";
					}
				elsif (($seq2[$nt] eq "A")&&($seq2[$nt+1] eq "C"))
					{
						$aa2[$aa]="threonine";
					}
				elsif (($seq2[$nt] eq "G")&&($seq2[$nt+1] eq "T"))
					{
						$aa2[$aa]="valine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] eq "G"))
					{
						$aa2[$aa]="tryptophan";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "T"))
					{
						$aa2[$aa]="tyrosine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "C"))
					{
						$aa2[$aa]="tyrosine";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "A"))
					{
						$aa2[$aa]="a stop codon";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "G")&&($seq2[$nt+2] eq "A"))
					{
						$aa2[$aa]="a stop codon";
					}
				elsif (($seq2[$nt] eq "T")&&($seq2[$nt+1] eq "A")&&($seq2[$nt+2] eq "G"))
					{
						$aa2[$aa]="a stop codon";
					}
				$nt+=3;
				$aa++;
			}
		$nt=1;
		$aa=1;
		if ($identical==1)
			{
				print "The two sequences are identical.\n\n";
			}
		else
			{
				$mutationcounter=0;
				while ($nt<=$length)
					{
						$mutationcounter=0;
						if ($mutation[$nt]==1)
							{
								$mutationcounter++;
								$aa=($nt+2)/3;
							}
						if ($mutation[$nt+1]==1)
							{
								$mutationcounter++;
								$aa=($nt+2)/3;
							}
						if ($mutation[$nt+2]==1)
							{
								$mutationcounter++;
								$aa=($nt+2)/3;
							}
						if ($mutationcounter==1)
							{
								print "There is one ";
								if ($aa1[$aa] eq $aa2[$aa])
									{
										print "synonymous mutation in codon $aa.\n";
									}
								else
									{
										print "mutation in codon $aa which causes $aa2[$aa] to substitute $aa1[$aa].\n";
									}
							}
						elsif ($mutationcounter==2)
							{
								print "There are two ";
								if ($aa1[$aa] eq $aa2[$aa])
									{
										print "synonymous mutations in codon $aa.\n";
									}
								else
									{
										print "mutations in codon $aa which cause $aa2[$aa] to substitute $aa1[$aa].\n";
									}
							}
						elsif ($mutationcounter==3)
							{
								print "There are three mutations in codon $aa which cause $aa2[$aa] to substitute $aa1[$aa].\n";
							}
						$nt+=3;
					}
				print "\n";
			}
	}
Fixed a couple of errors, such as:

1. Restricted sequence length to numbers (previously you could enter letters or weird characters and it would interpret that as zero; you also can't choose zero as the sequence length anymore).
2. Fixed the verification thing (again, it didn't work well if you entered weird characters).
 
Well... I'm pretty sure I burned those programs on a Cd, but it must be in Chile too :(, I didn't continued creating programs because, since I came here, I spend almost all my time at work and the computer that I have here is not mine, so I can't install executable archives because is blocked :(, I only use my computer to chat.

Question: Wich program you use to compile in perl?
 
BastardSonOfGod said:
Well... I'm pretty sure I burned those programs on a Cd, but it must be in Chile too :(, I didn't continued creating programs because, since I came here, I spend almost all my time at work and the computer that I have here is not mine, so I can't install executable archives because is blocked :(, I only use my computer to chat.
That sucks, man. :( I hope you can get your own computer soon.

BastardSonOfGod said:
Question: Wich program you use to compile in perl?
TextWrangler 2.1.1. :) And i run them on the Mac Terminal.