import java.util.*;
import java.io.*;
public class DNA {
public static void main(String[] args) throws FileNotFoundException {
Scanner console = new Scanner(System.in);
System.out.println("This program reports information about DNA");
System.out.println("nucleotide sequences that may encode proteins.");
System.out.print("Input file name? ");
String inputFile = console.next();
System.out.print("Output file name? ");
String outputFile = console.next();
Scanner input = new Scanner(new File(inputFile));
PrintStream output = new PrintStream(new File(outputFile));
while (input.hasNextLine()) {
String regionName = input.nextLine();
String data = input.nextLine();
String nucleotides = data.toUpperCase();
String line = nucleotides.replace("-", "");
int[] count = getCount(line);
double[] percentage = getMass(count, nucleotides);
String[] list = getList(line);
output.println("Region Name: " + regionName);
output.println("Nucleotides: " + nucleotides);
output.println("Nuc. Counts: " + Arrays.toString(count));
output.println("Total Mass%: " + Arrays.toString(percentage));
output.println("Codons List: " + Arrays.toString(list));
output.println("Is Protein?: " + );
output.println();
}
}
//
public static int[] getCount(String line) {
int[] count = new int[4];
for (int i = 0; i < line.length(); i++) {
char type = line.charAt(i);
int indice = convert(type);
count[indice] += 1;
}
return count;
}
//
public static double[] getMass(int[] count, String nucleotides) {
double[] masses = {135.128, 111.103, 151.128, 125.107};
double[] sum = new double[4];
double[] percentage = new double[4];
double total = 0.0;
/*
for (int i = 0; i < count.length(); i++) {
sum[i] = count[i] * masses[i] / total;
}
*/
for (int i = 0; i < nucleotides.length(); i++) {
char type = nucleotides.charAt(i);
int indice = convert(type);
if (indice == 4) {
total += 100.000;
} else {
total += masses[indice];
}
if (indice < 4) {
sum[indice] += masses[indice];
percentage[indice] = Math.round(sum[indice] / total * 1000.0) / 10.0;
}
}
return percentage;
}
//
public static String[] getList(String line) {
String[] list = new String[line.length() / 3];
for (int i = 0; i < line.length() / 3; i++) {
list[i] = line.substring(i * 3, i * 3 +3);
}
return list;
}
//
public static int convert(char type){
if (type == 'A') {
return 0;
} else if (type == 'C') {
return 1;
} else if (type == 'G') {
return 2;
} else if (type == 'T') {
return 3;
} else {
return 4;
}
}
}