/*this program counts the number of transitions and tranversion occur between two
*genes when two DNA strings from a source file are compared using threading.*/
import java.io.*;
import java.util.*;
import java.lang.*;
public class Gacer021109{
public static Vector<String> DNA = new Vector<String>();
public static int cnt=0;
public static void main(String[] args) throws IOException{
BufferedReader stndin = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter source file: ");
String source = stndin.readLine();
File inFile = new File(source);
FileReader in = new FileReader(inFile);
BufferedReader br = new BufferedReader(in);
Thread1 t1 = new Thread1();
while(true) {
String s = null;
try {
s = br.readLine();
}
catch (IOException e) {
System.out.println("Error reading file");
System.exit(1);
}
if(s == null) break;
DNA.addElement(s.trim());
cnt++;
}
in.close();
t1.start();
}
static class Thread1 extends Thread {
public static int[] transition = new int[(cnt*(cnt-1)/2)];
public static int[] transversion = new int[(cnt*(cnt-1)/2)];
public void run() {
int n=0,m=0;
for(int i=0; i<(cnt*(cnt-1)/2); i++){
transition[i] = 0;
transversion[i] = 0;
}
for(int i=0; i<cnt; i++){
if(i+1 < cnt){
for(int j=(i+1); j<cnt; j++){
String str1 = DNA.elementAt(i);
String str2 = DNA.elementAt(j);
for(int k=0; k<str1.length(); k++){
char let1 = str1.charAt(k);
char let2 = str2.charAt(k);
if(let1 == let2);
else if(let1=='A'&& let2=='G' || let1=='C'&& let2=='T' || let1=='G'&& let2=='A' || let1=='T'&& let2=='C')
transition[n]++;
else transversion[n]++;
}
n++;
}
}
}
for(int i=0; i<cnt; i++){
if(i+1 < cnt){
for(int j=(i+1); j<cnt; j++){
System.out.println("Gene["+(i+1)+"] vs Gene["+(j+1)+"]");
System.out.println("Transition: " + transition[m]);
System.out.println("Transversion: " + transversion[m]);
m++;
}
}
}
}
}
}
ERROR: Exception in thread "Thread-0" java.lang.ArrayIndexOutOfBoundsException: 0
at Gacer021109$Thread1.run(Gacer021109.java:45)
Sample DNA Genes inside the file:
ACGATGCTACTGCTAGCT
GCTAATCGTAGCGATGTC
ACTGATACAGATTAACCG
Output should be:
Gene[1] vs Gene[2]
Transition: 3
transversion: 11
Gene[1] vs Gene[3]
Transition: 3
transversion: 10
Gene[2] vs Gene[3]
Transition: 6
transversion: 7