Created
September 26, 2013 02:48
-
-
Save mccurdyc/6709220 to your computer and use it in GitHub Desktop.
DNA Mutator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//************************ | |
// Colton McCurdy | |
// CMPSC 111 Fall 2013 | |
// Lab 4 | |
// Date: 9-19-2013 | |
// | |
//Purpose: to create a program that simulates manipulations to DNA strands | |
import java.util.*; //imports | |
public class Lab4 | |
{ | |
//----------------------- | |
//main method starts | |
//----------------------- | |
public static void main(String[] args) | |
{ | |
//Variable Dictionary | |
Scanner scan = new Scanner(System.in); //used for input | |
Random random = new Random(); //inserting randoms | |
String dna; //original DNA String | |
String dnaComplement; //DNA Complement | |
String dnaInsert; //Inserting into original DNA | |
String dnaDelete; //Deleting portion of orignal DNA | |
String dnaChange; //Changing character in original DNA | |
char changeChar; //changing character | |
char c; //random character | |
int len; //length of DNA String | |
int place; //random place in DNA String | |
int place2; //a different random place in a different DNA String | |
int place3; //another random place | |
//Label output with name and date: | |
System.out.println("Colton McCurdy\nLab 4 " + "\n" + new Date() + "\n"); | |
System.out.print("Enter a string containing only C, G, T,and A: "); | |
dna = scan.nextLine(); //user input | |
dna = dna.toUpperCase(); //formating input to all CAPS | |
len = dna.length(); //length of DNA String | |
place = random.nextInt(len); //random place | |
place2 = random.nextInt(len); //different random place | |
place3 = random.nextInt(len); //another random place | |
c = "CGTA".charAt(random.nextInt(len)); //random character | |
//making a complement to the original dna strand | |
dnaComplement = dna.replace('A', 'Z') | |
.replace('C', 'Y') | |
.replace('T', 'X') | |
.replace('G', 'W') | |
.replace('Z', 'T') | |
.replace('Y', 'G') | |
.replace('X', 'A') | |
.replace('W', 'C'); | |
//*************** | |
// Outputs | |
//*************** | |
//complement | |
System.out.println("Complement of " + dna + " is " + | |
dnaComplement); | |
//insertion | |
dnaInsert = dna.substring(0, place) + c + dna.substring(place); //insert | |
System.out.println("Inserting " + c + " at position " + | |
place + " gives " + dnaInsert ); | |
//deletion | |
dnaDelete = dna.substring(0, place2) + dna.substring(place2 + 1); | |
System.out.println("Deleting from position " + place2+ " gives " + | |
dnaDelete); | |
//change | |
changeChar = dna.charAt(place3); | |
dnaChange = dna.replace(changeChar, c); //replacing a character with a random | |
System.out.println("Changing position " + place3 + | |
" gives " + dnaChange); | |
//formatting in terminal | |
System.out.println(); //blank line after output | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment