import java.io.*; import java.util.*; public class listEnzyme extends Thread { private Lock1_2 lock1_2; private Lock2_1 lock2_1; private String seqline = ""; //source sequence private int snploc = 0; //position of snp in sequence private char allele1 = ' '; //first snp allele in sequence private char allele2 = ' '; //second snp allele in sequence private int optproductsize = 0; //optimum primer size private int maxproductsize = 0; //maximum primer size private int minproductsize = 0; //minimum primer size private int bpwidth = 0; //number of positions for mismatches on either side of SNP public listEnzyme (Lock1_2 l1, Lock2_1 l2, String s, int loc, char a1, char a2, int optprosize, int maxprosize, int minprosize, int numbp) { lock1_2 = l1; lock2_1 = l2; seqline = s; snploc = loc; allele1 = a1; allele2 = a2; optproductsize = optprosize; maxproductsize = maxprosize; minproductsize = minprosize; bpwidth = numbp; } public void run() { String infile = "/export/home/xiayi/primer2/type2seq.out"; Stack stack = new Stack(); Stack tempStack = new Stack(); try { String thisline = ""; String misline = ""; String sequence = ""; String recogseq = ""; //recognition sequence String positions = ""; //cutting positions DataInputStream dis = new DataInputStream(new FileInputStream(infile)); boolean found = false; boolean printentry = false; //save infile into stack while ((thisline = dis.readLine()) != null) tempStack.push(thisline); dis.close(); //reverse to the right order while (tempStack.empty() != true) stack.push(tempStack.pop()); //introduce various mismatches mismatchseq mms = new mismatchseq(seqline, snploc, bpwidth); mms.mismatching(); //do the trick while ((misline = mms.get()) != null) { String ch = ""; int misp = 0; boolean printmisinfo = true; boolean printstarline = true; if (misline.equals(java.lang.Integer.toString(snploc)) == true) { sequence = seqline; //orginal misp = snploc; //means no mismatch } else { StringTokenizer st = new StringTokenizer(misline); ch = st.nextToken(); misp = java.lang.Integer.valueOf(st.nextToken()).intValue(); sequence = seqline.substring(0, misp-1); sequence += ch; sequence += seqline.substring(misp); } while (stack.empty() != true) { thisline = (String)stack.pop(); //save data for later use tempStack.push(thisline); if (thisline.startsWith("Recognition") == true) { StringTokenizer st = new StringTokenizer(thisline); recogseq = st.nextToken(); //actually "Recognition" recogseq = st.nextToken(); //actually "sequence:" recogseq = st.nextToken(); //that is it matchseq mts = new matchseq(sequence, recogseq, allele1, allele2, snploc, misp); int allelep = mts.anchorseq(); if (allelep != -1) { String tempseq = ""; if (allelep == 1) tempseq = sequence; else { tempseq = sequence.substring(0, snploc-1); tempseq += allele2; tempseq += sequence.substring(snploc); } matchwide mtw = new matchwide(tempseq, recogseq); if (mtw.matching() == true) { //print out what mismatch (only) once if (printmisinfo == true) { //print out a star line to terminate if (printstarline) { System.out.println("********************************************************************************"); printstarline = false; } System.out.println(""); if (misp == snploc) //no mismatch introduced System.out.println("No mismatch introduced"); else System.out.println("Mismatch " + ch + " introduced at position of " + misp); System.out.println("\n"); printmisinfo = false; } //send the info out for primer design lock1_2.put(recogseq + " " + java.lang.Integer.toString(misp) + " " + ch); //wait for the feedback (content is not important) lock2_1.get(); //print out the recognition sequence System.out.println(thisline); String position = ""; positions = "Locations: "; while ((position = mtw.get()) != null) { positions += position; positions += ", "; } //get ride of last ", " positions = positions.trim(); positions = positions.substring(0, positions.length()-1); found = true; printentry = true; } } } else if ((thisline.startsWith("Enzymes:")) && (printentry)) { //print out the position list System.out.println(positions); //print out the enzyme list, not more than 80 characters per line if (thisline.length() <= 80) { System.out.println(thisline); } else { String templine = thisline; while (templine.length() > 80) { int p1 = 80; while (templine.charAt(p1-1) != ',') p1--; System.out.println(templine.substring(0, p1)); templine = templine.substring(p1); } System.out.println(templine); } System.out.println("\n"); printentry = false; } } //end of inner while //push back all entries to stack while (tempStack.empty() != true) stack.push(tempStack.pop()); } //end of outer while if (found == false) System.out.println("No suitable enzymes found"); } //end of try catch (IOException e) { System.err.println(e); } lock1_2.put("finish"); //terminate all threads return; } //end of run } //end