List of usage examples for java.io DataInputStream readInt
public final int readInt() throws IOException
readInt
method of DataInput
. From source file:MiGA.StatsSelection.java
public void getCompoundPerfectSSRs(String[] organisms, int length, boolean flag, int gap) throws SQLException, ClassNotFoundException, FileNotFoundException, IOException { String statsfile = ""; for (int i = 0; i < organisms.length; i++) { boolean found = false; String buffer = new String(); int seekstart = 0; int seekend = 0; List<String> ssrs = new ArrayList<String>(); // 18/11/2013 added starting here String filetype = ""; String filepro = ""; if (flag) { filetype = "organisms"; filepro = "organisms/" + organisms[i] + "/data/"; int ret = getOrganismStatus(organisms[i]); if (ret == -1) indexer = new Indexer(chromosomelist); else/* w ww . j a v a 2 s .c o m*/ indexer = new Indexer(ret); } else { filetype = "local"; filepro = "local/" + organisms[i] + "/data/"; String indexfile = "local/" + organisms[i] + "/index.txt"; indexer = new Indexer(indexfile); } //List<String> files = getFiles(organisms[i], minlen, flag); // 18/11/2013 added ending here PrintWriter stats = null; PrintWriter html = null; PrintWriter out; DataOutputStream lt = null; if (filetype.contains("organism")) { File f = new File("organisms/" + organisms[i] + "/stats/"); if (!f.exists()) { f.mkdir(); } stats = new PrintWriter( new FileWriter("organisms/" + organisms[i] + "/stats/" + "summary_statistics" + now.toString().replace(':', '_').replace(' ', '_') + ".txt", true)); lt = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("organisms/" + organisms[i] + "/data/" + now.toString().replace(':', '_').replace(' ', '_') + ".compp"))); html = new PrintWriter(new FileWriter("organisms/" + organisms[i] + "/stats/" + "summary_statistics" + now.toString().replace(':', '_').replace(' ', '_') + ".html", true)); File fi = new File("organisms/" + organisms[i] + "/results/"); if (!fi.exists()) { fi.mkdir(); } String toopen = "organisms/" + organisms[i] + "/results/allCompPerfect_" + now.toString().replace(':', '_').replace(' ', '_') + ".txt"; statsfile = toopen; out = new PrintWriter(toopen); out.println("Results for organism: " + organisms[i] + "\t Search Parameters --> Maximum Inter-repeat Region for Perfect Compound SSRs (bp) : " + gap + " - minimum SSR length (bp): " + length); } else { File f = new File("local/" + organisms[i] + "/stats/"); if (!f.exists()) { f.mkdir(); } stats = new PrintWriter(new FileWriter("local/" + organisms[i] + "/stats/" + "summary_statistics" + now.toString().replace(':', '_').replace(' ', '_') + ".txt", true)); lt = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("local/" + organisms[i] + "/data/" + now.toString().replace(':', '_').replace(' ', '_') + ".compp"))); html = new PrintWriter(new FileWriter("local/" + organisms[i] + "/stats/" + "summary_statistics" + now.toString().replace(':', '_').replace(' ', '_') + ".html", true)); File fi = new File("local/" + organisms[i] + "/results/"); if (!fi.exists()) { fi.mkdir(); } String toopen = "local/" + organisms[i] + "/results/allCompPerfect_" + now.toString().replace(':', '_').replace(' ', '_') + ".txt"; statsfile = toopen; out = new PrintWriter(toopen); out.println("Results for project: " + organisms[i] + "\t Search Parameters --> Maximum Inter-repeat Region for Perfect Compound SSRs (bp) : " + gap + " - minimum SSR length (bp): " + length); } int countpc = 0; int bpcount = 0, Aperc = 0, Tperc = 0, Gperc = 0, Cperc = 0; while (indexer.hasNext()) { String files = filepro + indexer.getNextFileName(); DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(files))); boolean eof = false; while (!eof) { try { SSR = new ArrayList<String>(); repeats = new ArrayList<Integer>(); EndOfSsr = new ArrayList<Integer>(); start = new ArrayList<Integer>(); int len = in.readInt(); int line = in.readInt(); for (int k = 0; k < len; k++) { String temp = in.readUTF(); if (!temp.contains("N")) { SSR.add(temp); EndOfSsr.add(in.readInt()); repeats.add(in.readInt()); int st = EndOfSsr.get(k) - (SSR.get(k).length() * repeats.get(k)); if (st >= 0) start.add(st); else start.add(0); } else { int junk = in.readInt(); junk = in.readInt(); } /* int real_end = end+(line-1)*20000; int start = real_end - (ssr.length()*reps); //SSR.add(ssr); repeats.add(in.readInt()); EndOfSsr.add(real_end); this.start.add(start); * */ } List<String> SSRlen = new ArrayList<String>(); List<Integer> Endlen = new ArrayList<Integer>(); List<Integer> repslen = new ArrayList<Integer>(); List<Integer> startlen = new ArrayList<Integer>(); for (int k = 0; k < SSR.size(); k++) { if (SSR.get(k).length() * repeats.get(k) >= length) { SSRlen.add(SSR.get(k)); Endlen.add(EndOfSsr.get(k)); repslen.add(repeats.get(k)); startlen.add(start.get(k)); } } List<Integer> sortedstart = new ArrayList<Integer>(); List<Integer> sortedend = new ArrayList<Integer>(); for (int t = 0; t < startlen.size(); t++) { sortedstart.add(startlen.get(t)); sortedend.add(Endlen.get(t)); } Collections.sort(sortedstart); Collections.sort(sortedend); for (int k = 0; k < sortedstart.size() - 2; k++) { found = false; ssrs = new ArrayList<String>(); if (sortedstart.get(k + 1) - sortedend.get(k) <= gap && sortedstart.get(k + 1) - sortedend.get(k) >= 0) { seekstart = sortedstart.get(k); while (k < sortedstart.size() - 1 && sortedstart.get(k + 1) - sortedend.get(k) <= gap && sortedstart.get(k + 1) - sortedend.get(k) >= 0) { for (int c = 0; c < startlen.size(); c++) { if (sortedstart.get(k) == startlen.get(c)) { ssrs.add(SSRlen.get(c)); } if (sortedstart.get(k + 1) == startlen.get(c)) { ssrs.add(SSRlen.get(c)); seekend = Endlen.get(c); found = true; } } k++; } k--; } boolean check = checkalldiff(ssrs); if (found && check) { BufferedReader stdin = null; String newdir = ""; if (flag) { String[] temp = files.split("/"); boolean type = CheckForKaryotype(organisms[i]); newdir = ""; if (type) { newdir = temp[0] + "/" + temp[1] + "/chrom-" + temp[3].substring(0, temp[3].lastIndexOf('.')) + "-slices.txt"; } else { newdir = temp[0] + "/" + temp[1] + "/slice-" + temp[3].substring(0, temp[3].lastIndexOf('.')) + ".txt"; } stdin = new BufferedReader(new FileReader(newdir)); } else { String[] temp = files.split("data/"); newdir = temp[0] + "/" + temp[1].substring(0, temp[1].lastIndexOf('.')) + ".txt"; stdin = new BufferedReader(new FileReader(newdir)); } buffer = ""; String prebuf = ""; for (int c = 0; c < line; c++) { buffer = stdin.readLine(); } stdin.close(); //System.out.println(buffer.length() + "\t" + seekstart + "\t" + seekend); int real_end = (line - 1) * 20000 + seekend; int real_start = (line - 1) * 20000 + seekstart; //tofile.add("SSR: "+buffer.substring(seekstart, seekend) + "start-end: "+ real_start + "-" +real_end ); countpc++; String tmp = ""; if (seekstart < 0) { stdin = new BufferedReader(new FileReader(newdir)); for (int c = 0; c < line - 1; c++) { prebuf = stdin.readLine(); } stdin.close(); tmp += prebuf.substring(prebuf.length() + seekstart); tmp += buffer.substring(0, seekend); } else tmp = buffer.substring(seekstart, seekend); bpcount += tmp.length(); if (tmp.contains("A")) { Aperc += StringUtils.countMatches(tmp, "A"); } if (tmp.contains("T")) { Tperc += StringUtils.countMatches(tmp, "T"); } if (tmp.contains("G")) { Gperc += StringUtils.countMatches(tmp, "G"); } if (tmp.contains("C")) { Cperc += StringUtils.countMatches(tmp, "C"); } out.println("SSR: " + tmp + " start-end: " + real_start + "-" + real_end + " Path(../data/chromosome): " + files.substring(0, files.lastIndexOf('.'))); } } } catch (EOFException e) { eof = true; } } in.close(); } out.close(); Runtime.getRuntime().exec("notepad " + statsfile); try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException ex) { Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex); } Connection con = null; try { con = DriverManager.getConnection("jdbc:mysql://localhost:3306", "biouser", "thesis2012"); } catch (SQLException ex) { Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex); } Statement st = null; try { st = con.createStatement(); } catch (SQLException ex) { Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex); } st.executeUpdate("use lobid"); int seqcount = 0; if (filetype.contains("organisms")) { ResultSet rs = st.executeQuery( "SELECT end FROM slices INNER JOIN organism WHERE slices.org_id=organism.org_id AND organism.name='" + organisms[i] + "'"); while (rs.next()) { seqcount += Long.parseLong(rs.getString(1)); } } else if (filetype.contains("local")) { BufferedReader in = new BufferedReader(new FileReader("local/" + organisms[i] + "/index.txt")); int count = countlines("local/" + organisms[i] + "/index.txt"); for (int c = 0; c < count; c++) { String temp = in.readLine(); BufferedReader tmp = new BufferedReader( new FileReader("local/" + organisms[i] + "/" + temp + ".txt")); boolean eof = false; while (!eof) { String s = tmp.readLine(); if (s != null) { seqcount += s.length(); } else { eof = true; } } tmp.close(); } } DecimalFormat round = new DecimalFormat("#.###"); html.println("<html><h1>******* Compound Perfect SSRs *******</h1>"); html.println("<h4>Results for project: " + organisms[i] + "</h4><h4>Search Parameters --> Maximum Inter-repeat Region for Perfect Compound SSRs (bp) : " + gap + "</h4><h4>minimum SSR length (bp): " + length + "</h4>"); html.println( "<table border=\"1\"><tr><td> </td><td><b>count</b></td><td><b>bp</b></td><td><b>A%</b></td><td><b>T%</b></td><td><b>C%</b></td><td><b>G%</b></td><td><b>Relative Frequency</b></td><td><b>Abundance</b></td><td><b>Relative Abundance</b></td></tr>"); html.println("<tr><td><b>Compound Perf.</b></td><td>" + countpc + "</td><td>" + bpcount + "</td><td>" + round.format((float) Aperc * 100 / bpcount) + "</td><td>" + round.format((float) Tperc * 100 / bpcount) + "</td><td>" + round.format((float) Cperc * 100 / bpcount) + "</td><td>" + round.format((float) Gperc * 100 / bpcount) + "</td><td>" + round.format((float) countpc / countpc) + "</td><td>" + round.format((float) bpcount / seqcount) + "</td><td>" + round.format((float) bpcount / bpcount) + "</td></tr>"); html.println("<tr><td><b>TOTAL</b></td><td>" + countpc + "</td><td>" + bpcount + "</td><td>" + round.format((float) Aperc * 100 / bpcount) + "</td><td>" + round.format((float) Tperc * 100 / bpcount) + "</td><td>" + round.format((float) Cperc * 100 / bpcount) + "</td><td>" + round.format((float) Gperc * 100 / bpcount) + "</td><td>" + round.format((float) countpc / countpc) + "</td><td>" + round.format((float) bpcount / seqcount) + "</td><td>" + round.format((float) bpcount / bpcount) + "</td></tr></table></html>"); html.close(); stats.println("******* Compound Perfect SSRs *******"); stats.println("Results for project: " + organisms[i] + "\nSearch Parameters --> Maximum Inter-repeat Region for Perfect Compound SSRs (bp) : " + gap + "\nminimum SSR length (bp): " + length); stats.println( " ___________________________________________________________________________________________________________________ "); stats.println( "| | | | | | | | Relative | | Relative |"); stats.println( "| | count | bp | A% | T% | C% | G% | Frequency | Abundance | Abundance |"); stats.println( "|==============|=======|============|=======|=======|=======|=======|===============|===============|===============|"); stats.printf( "|Compound Perf.|" + cell(Integer.toString(countpc), 7) + "|" + cell(Integer.toString(bpcount), 12) + "|%s|%s|%s|%s|" + cell((float) countpc / countpc, 15) + "|" + cell((float) bpcount / seqcount, 15) + "|" + cell((float) bpcount / bpcount, 15) + "|\n", cell((float) Aperc * 100 / bpcount, 7), cell((float) Tperc * 100 / bpcount, 7), cell((float) Cperc * 100 / bpcount, 7), cell((float) Gperc * 100 / bpcount, 7)); stats.println( "|--------------|-------|------------|-------|-------|-------|-------|---------------|---------------|---------------|"); lt.writeLong(seqcount); lt.writeInt(countpc); lt.writeInt(bpcount); lt.writeInt(Aperc); lt.writeInt(Tperc); lt.writeInt(Gperc); lt.writeInt(Cperc); stats.println("|TOTAL |" + cell(Integer.toString(countpc), 7) + "|" + cell(Long.toString(bpcount), 12) + "|" + cell((float) Aperc * 100 / bpcount, 7) + "|" + cell((float) Tperc * 100 / bpcount, 7) + "|" + cell((float) Cperc * 100 / bpcount, 7) + "|" + cell((float) Gperc * 100 / bpcount, 7) + "|" + cell((float) countpc / countpc, 15) + "|" + cell((float) bpcount / seqcount, 15) + "|" + cell((float) bpcount / bpcount, 15) + "|"); stats.println( "|______________|_______|____________|_______|_______|_______|_______|_______________|_______________|_______________|"); stats.println("Genome length (bp): " + seqcount); stats.println("Relative Frequency: Count of each motif type / total SSR count"); stats.println("Abundance: bp of each motif type / total sequence bp"); stats.println("Relative Abundance: bp of each motif type / total microsatellites bp"); stats.println(); stats.println(); stats.close(); lt.close(); } }
From source file:MiGA.StatsSelection.java
public void getImPerfectCompoundSSRs(String[] organisms, int length, boolean flag, int gap) throws SQLException, ClassNotFoundException, FileNotFoundException, IOException { String statsfile = ""; for (int i = 0; i < organisms.length; i++) { boolean found = false; String buffer = new String(); int seekstart = 0; int seekend = 0; List<String> ssrs = new ArrayList<String>(); // 18/11/2013 added starting here String filetype = ""; String filepro = ""; if (flag) { filetype = "organisms"; filepro = "organisms/" + organisms[i] + "/data/"; int ret = getOrganismStatus(organisms[i]); if (ret == -1) indexer = new Indexer(chromosomelist); else/*from w w w. j a v a 2 s . co m*/ indexer = new Indexer(ret); } else { filetype = "local"; filepro = "local/" + organisms[i] + "/data/"; String indexfile = "local/" + organisms[i] + "/index.txt"; indexer = new Indexer(indexfile); } //List<String> files = getFiles(organisms[i], minlen, flag); // 18/11/2013 added ending here PrintWriter out; PrintWriter stats; PrintWriter html; DataOutputStream lt = null; if (filetype.contains("organism")) { File f = new File("organisms/" + organisms[i] + "/stats/"); if (!f.exists()) { f.mkdir(); } stats = new PrintWriter( new FileWriter("organisms/" + organisms[i] + "/stats/" + "summary_statistics" + now.toString().replace(':', '_').replace(' ', '_') + ".txt", true)); lt = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("organisms/" + organisms[i] + "/data/" + now.toString().replace(':', '_').replace(' ', '_') + ".compim"))); html = new PrintWriter(new FileWriter("organisms/" + organisms[i] + "/stats/" + "summary_statistics" + now.toString().replace(':', '_').replace(' ', '_') + ".html", true)); File fi = new File("organisms/" + organisms[i] + "/results/"); if (!fi.exists()) { fi.mkdir(); } String toopen = "organisms/" + organisms[i] + "/results/allCompImPerfect_" + now.toString().replace(':', '_').replace(' ', '_') + ".txt"; statsfile = toopen; out = new PrintWriter(toopen); out.println("Results for organism: " + organisms[i] + "\t Search Parameters --> Maximum Inter-repeat Region for Imperfect Compound SSRs(bp) : " + gap + " - minimum SSR length(bp): " + length); } else { File f = new File("local/" + organisms[i] + "/stats/"); if (!f.exists()) { f.mkdir(); } stats = new PrintWriter(new FileWriter("local/" + organisms[i] + "/stats/" + "summary_statistics" + now.toString().replace(':', '_').replace(' ', '_') + ".txt", true)); lt = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("local/" + organisms[i] + "/data/" + now.toString().replace(':', '_').replace(' ', '_') + ".compim"))); html = new PrintWriter(new FileWriter("local/" + organisms[i] + "/stats/" + "summary_statistics" + now.toString().replace(':', '_').replace(' ', '_') + ".html", true)); File fi = new File("local/" + organisms[i] + "/results/"); if (!fi.exists()) { fi.mkdir(); } Calendar calendar = Calendar.getInstance(); Date now = calendar.getTime(); String toopen = "local/" + organisms[i] + "/results/allCompImPerfect_" + now.toString().replace(':', '_').replace(' ', '_') + ".txt"; statsfile = toopen; out = new PrintWriter(toopen); out.println("Results for project: " + organisms[i] + "\t Search Parameters --> Maximum Inter-repeat Region for Imperfect Compound SSRs(bp) : " + gap + " - minimum SSR length(bp): " + length); } int countpc = 0; int bpcount = 0, Aperc = 0, Tperc = 0, Gperc = 0, Cperc = 0; while (indexer.hasNext()) { String files = filepro + indexer.getNextFileName(); DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(files))); //PrintWriter out = new PrintWriter(files + "-minlentgh_" + length + "_ImPerfect.stats"); boolean eof = false; while (!eof) { try { SSR = new ArrayList<String>(); repeats = new ArrayList<Integer>(); EndOfSsr = new ArrayList<Integer>(); start = new ArrayList<Integer>(); int len = in.readInt(); int line = in.readInt(); for (int k = 0; k < len; k++) { //THIS String temp = in.readUTF(); if (!temp.contains("N")) { SSR.add(temp); EndOfSsr.add(in.readInt()); repeats.add(in.readInt()); start.add(EndOfSsr.get(k) - (SSR.get(k).length() * repeats.get(k))); } else { int junk = in.readInt(); junk = in.readInt(); } } List<String> SSRlen = new ArrayList<String>(); List<Integer> Endlen = new ArrayList<Integer>(); List<Integer> repslen = new ArrayList<Integer>(); List<Integer> startlen = new ArrayList<Integer>(); for (int k = 0; k < SSR.size(); k++) { if (SSR.get(k).length() * repeats.get(k) >= length) { SSRlen.add(SSR.get(k)); Endlen.add(EndOfSsr.get(k)); repslen.add(repeats.get(k)); startlen.add(start.get(k)); } } List<Integer> sortedstart = new ArrayList<Integer>(); List<Integer> sortedend = new ArrayList<Integer>(); for (int t = 0; t < startlen.size(); t++) { sortedstart.add(startlen.get(t)); sortedend.add(Endlen.get(t)); } Collections.sort(sortedstart); Collections.sort(sortedend); //List<String> tofile = new ArrayList<String>(); for (int k = 0; k < sortedstart.size() - 2; k++) { found = false; ssrs.clear(); ssrs = new ArrayList<String>(); if (sortedstart.get(k + 1) - sortedend.get(k) <= gap && sortedstart.get(k + 1) - sortedend.get(k) >= 0) { seekstart = sortedstart.get(k); while (k < sortedstart.size() - 1 && sortedstart.get(k + 1) - sortedend.get(k) <= gap && sortedstart.get(k + 1) - sortedend.get(k) >= 0) { for (int c = 0; c < startlen.size(); c++) { if (sortedstart.get(k) == startlen.get(c)) { ssrs.add(SSRlen.get(c)); } if (sortedstart.get(k + 1) == startlen.get(c)) { ssrs.add(SSRlen.get(c)); seekend = Endlen.get(c); found = true; } } k++; } k--; } boolean check = checkallsame(ssrs); boolean check2 = checkalldiff(ssrs); if (found && !check && !check2) { BufferedReader stdin = null; if (flag) { String[] temp = files.split("/"); boolean type = CheckForKaryotype(organisms[i]); String newdir = ""; if (type) { newdir = temp[0] + "/" + temp[1] + "/chrom-" + temp[3].substring(0, temp[3].lastIndexOf('.')) + "-slices.txt"; } else { newdir = temp[0] + "/" + temp[1] + "/slice-" + temp[3].substring(0, temp[3].lastIndexOf('.')) + ".txt"; } stdin = new BufferedReader(new FileReader(newdir)); } else { String[] temp = files.split("data/"); String newdir = temp[0] + "/" + temp[1].substring(0, temp[1].lastIndexOf('.')) + ".txt"; stdin = new BufferedReader(new FileReader(newdir)); } buffer = ""; for (int c = 0; c < line; c++) { buffer = stdin.readLine(); } //System.out.println(buffer.length() + "\t" + seekstart + "\t" + seekend); int real_end = (line - 1) * 20000 + seekend; int real_start = (line - 1) * 20000 + seekstart; //tofile.add("SSR: "+buffer.substring(seekstart, seekend) + "start-end: "+ real_start + "-" +real_end ); countpc++; if (seekstart < 0) seekstart++; String tmp = buffer.substring(seekstart, seekend); bpcount += tmp.length(); if (tmp.contains("A")) { Aperc += StringUtils.countMatches(tmp, "A"); } if (tmp.contains("T")) { Tperc += StringUtils.countMatches(tmp, "T"); } if (tmp.contains("G")) { Gperc += StringUtils.countMatches(tmp, "G"); } if (tmp.contains("C")) { Cperc += StringUtils.countMatches(tmp, "C"); } out.println("SSR: " + tmp + " start-end: " + real_start + "-" + real_end + " Path(../data/chromosome): " + files.substring(0, files.lastIndexOf('.'))); stdin.close(); } } } catch (EOFException e) { eof = true; } } in.close(); } out.close(); Runtime.getRuntime().exec("notepad " + statsfile); try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException ex) { Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex); } Connection con = null; try { con = DriverManager.getConnection("jdbc:mysql://localhost:3306", "biouser", "thesis2012"); } catch (SQLException ex) { Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex); } Statement st = null; try { st = con.createStatement(); } catch (SQLException ex) { Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex); } st.executeUpdate("use lobid"); int seqcount = 0; if (filetype.contains("organisms")) { ResultSet rs = st.executeQuery( "SELECT end FROM slices INNER JOIN organism WHERE slices.org_id=organism.org_id AND organism.name='" + organisms[i] + "'"); while (rs.next()) { seqcount += Long.parseLong(rs.getString(1)); } } else if (filetype.contains("local")) { BufferedReader in = new BufferedReader(new FileReader("local/" + organisms[i] + "/index.txt")); int count = countlines("local/" + organisms[i] + "/index.txt"); for (int c = 0; c < count; c++) { String temp = in.readLine(); BufferedReader tmp = new BufferedReader( new FileReader("local/" + organisms[i] + "/" + temp + ".txt")); boolean eof = false; while (!eof) { String s = tmp.readLine(); if (s != null) { seqcount += s.length(); } else { eof = true; } } tmp.close(); } } DecimalFormat round = new DecimalFormat("#.###"); html.println("<html><h1>******* Compound Imperfect SSRs *******</h1>"); html.println("<h4>Results for project: " + organisms[i] + "</h4><h4>Search Parameters --> Maximum Inter-repeat Region for Imperfect Compound SSRs (bp) : " + gap + "</h4><h4>minimum SSR length (bp): " + length + "</h4>"); html.println( "<table border=\"1\"><tr><td> </td><td><b>count</b></td><td><b>bp</b></td><td><b>A%</b></td><td><b>T%</b></td><td><b>C%</b></td><td><b>G%</b></td><td><b>Relative Frequency</b></td><td><b>Abundance</b></td><td><b>Relative Abundance</b></td></tr>"); html.println("<tr><td><b>Compound Imperf.</b></td><td>" + countpc + "</td><td>" + bpcount + "</td><td>" + round.format((float) Aperc * 100 / bpcount) + "</td><td>" + round.format((float) Tperc * 100 / bpcount) + "</td><td>" + round.format((float) Cperc * 100 / bpcount) + "</td><td>" + round.format((float) Gperc * 100 / bpcount) + "</td><td>" + round.format((float) countpc / countpc) + "</td><td>" + round.format((float) bpcount / seqcount) + "</td><td>" + round.format((float) bpcount / bpcount) + "</td></tr>"); html.println("<tr><td><b>TOTAL</b></td><td>" + countpc + "</td><td>" + bpcount + "</td><td>" + round.format((float) Aperc * 100 / bpcount) + "</td><td>" + round.format((float) Tperc * 100 / bpcount) + "</td><td>" + round.format((float) Cperc * 100 / bpcount) + "</td><td>" + round.format((float) Gperc * 100 / bpcount) + "</td><td>" + round.format((float) countpc / countpc) + "</td><td>" + round.format((float) bpcount / seqcount) + "</td><td>" + round.format((float) bpcount / bpcount) + "</td></tr></table></html>"); html.close(); stats.println("******* Compound Imperfect SSRs *******"); stats.println("Results for project: " + organisms[i] + "\nSearch Parameters --> Maximum Inter-repeat Region for Imperfect Compound SSRs(bp) : " + gap + "\nminimum SSR length(bp): " + length); stats.println( " ____________________________________________________________________________________________________________________ "); stats.println( "| | | | | | | | Relative | | Relative |"); stats.println( "| | count | bp | A% | T% | C% | G% | Frequency | Abundance | Abundance |"); stats.println( "|===============|=======|============|=======|=======|=======|=======|===============|===============|===============|"); stats.printf( "|Compound Imper.|" + cell(Integer.toString(countpc), 7) + "|" + cell(Integer.toString(bpcount), 12) + "|%s|%s|%s|%s|" + cell((float) countpc / countpc, 15) + "|" + cell((float) bpcount / seqcount, 15) + "|" + cell((float) bpcount / bpcount, 15) + "|\n", cell((float) Aperc * 100 / bpcount, 7), cell((float) Tperc * 100 / bpcount, 7), cell((float) Cperc * 100 / bpcount, 7), cell((float) Gperc * 100 / bpcount, 7)); stats.println( "|---------------|-------|------------|-------|-------|-------|-------|---------------|---------------|---------------|"); lt.writeLong(seqcount); lt.writeInt(countpc); lt.writeInt(bpcount); lt.writeInt(Aperc); lt.writeInt(Tperc); lt.writeInt(Gperc); lt.writeInt(Cperc); stats.println("|TOTAL |" + cell(Integer.toString(countpc), 7) + "|" + cell(Long.toString(bpcount), 12) + "|" + cell((float) Aperc * 100 / bpcount, 7) + "|" + cell((float) Tperc * 100 / bpcount, 7) + "|" + cell((float) Cperc * 100 / bpcount, 7) + "|" + cell((float) Gperc * 100 / bpcount, 7) + "|" + cell((float) countpc / countpc, 15) + "|" + cell((float) bpcount / seqcount, 15) + "|" + cell((float) bpcount / bpcount, 15) + "|"); stats.println( "|_______________|_______|____________|_______|_______|_______|_______|_______________|_______________|_______________|"); stats.println("Genome length (bp): " + seqcount); stats.println("Relative Frequency: Count of each motif type / total SSR count"); stats.println("Abundance: bp of each motif type / total sequence bp"); stats.println("Relative Abundance: bp of each motif type / total microsatellites bp"); stats.println(); stats.println(); stats.close(); lt.close(); } }
From source file:MiGA.StatsSelection.java
public void getPerfectSSRs(String[] organisms, int length, boolean flag) throws FileNotFoundException, SQLException, ClassNotFoundException, IOException { for (int i = 0; i < organisms.length; i++) { // 18/11/2013 added starting here String filetype = ""; String filepro = ""; if (flag) { filetype = "organisms"; filepro = "organisms/" + organisms[i] + "/data/"; int ret = getOrganismStatus(organisms[i]); if (ret == -1) indexer = new Indexer(chromosomelist); else/*from w w w . j a va2s . c o m*/ indexer = new Indexer(ret); } else { filetype = "local"; filepro = "local/" + organisms[i] + "/data/"; String indexfile = "local/" + organisms[i] + "/index.txt"; indexer = new Indexer(indexfile); } //List<String> files = getFiles(organisms[i], minlen, flag); // 18/11/2013 added ending here countmono.set(i, 0); countdi.set(i, 0); counttri.set(i, 0); counttetra.set(i, 0); countpenta.set(i, 0); counthexa.set(i, 0); countmonore.set(i, 0); countdire.set(i, 0); counttrire.set(i, 0); counttetrare.set(i, 0); countpentare.set(i, 0); counthexare.set(i, 0); Amono.set(i, 0); Adi.set(i, 0); Atri.set(i, 0); Atetra.set(i, 0); Apenta.set(i, 0); Ahexa.set(i, 0); Tmono.set(i, 0); Tdi.set(i, 0); Ttri.set(i, 0); Ttetra.set(i, 0); Tpenta.set(i, 0); Thexa.set(i, 0); Gmono.set(i, 0); Gdi.set(i, 0); Gtri.set(i, 0); Gtetra.set(i, 0); Gpenta.set(i, 0); Ghexa.set(i, 0); Cmono.set(i, 0); Cdi.set(i, 0); Ctri.set(i, 0); Ctetra.set(i, 0); Cpenta.set(i, 0); Chexa.set(i, 0); while (indexer.hasNext()) { String files = filepro + indexer.getNextFileName(); //for (int j = 0; j < files.size(); j++) { List<File> exis = new ArrayList<File>(); exis.add(new File(files + "_" + length + "_monoPerfect.temp")); exis.add(new File(files + "_" + length + "_diPerfect.temp")); exis.add(new File(files + "_" + length + "_triPerfect.temp")); exis.add(new File(files + "_" + length + "_tetraPerfect.temp")); exis.add(new File(files + "_" + length + "_pentaPerfect.temp")); exis.add(new File(files + "_" + length + "_hexaPerfect.temp")); int num = 0; for (int temp = 0; temp < exis.size(); temp++) { if (exis.get(temp).exists()) { num++; } } if (num != exis.size()) { DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(files))); // DataOutputStream outmono = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(files + "_" + length + "_monoPerfect.temp"))); DataOutputStream outdi = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(files + "_" + length + "_diPerfect.temp"))); DataOutputStream outtri = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(files + "_" + length + "_triPerfect.temp"))); DataOutputStream outtetra = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(files + "_" + length + "_tetraPerfect.temp"))); DataOutputStream outpenta = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(files + "_" + length + "_pentaPerfect.temp"))); DataOutputStream outhexa = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(files + "_" + length + "_hexaPerfect.temp"))); boolean eof = false; while (!eof) { try { int len = in.readInt(); int line = in.readInt(); for (int k = 0; k < len; k++) { SSR.add(in.readUTF()); int end = in.readInt(); repeats.add(in.readInt()); EndOfSsr.add(end + (line - 1) * 20000); } for (int c = 0; c < SSR.size(); c++) { if (!SSR.get(c).contains("N")) { if (repeats.get(c) * SSR.get(c).length() >= length) { if (SSR.get(c).length() == 1) { countmono.set(i, countmono.get(i) + 1); countmonore.set(i, countmonore.get(i) + repeats.get(c)); if (SSR.get(c).contains("A")) { Amono.set(i, Amono.get(i) + repeats.get(c)); } if (SSR.get(c).contains("T")) { Tmono.set(i, Tmono.get(i) + repeats.get(c)); } if (SSR.get(c).contains("G")) { Gmono.set(i, Gmono.get(i) + repeats.get(c)); } if (SSR.get(c).contains("C")) { Cmono.set(i, Cmono.get(i) + repeats.get(c)); } outmono.writeUTF(SSR.get(c)); outmono.writeInt(repeats.get(c)); outmono.writeInt(EndOfSsr.get(c)); } else if (SSR.get(c).length() == 2) { countdi.set(i, countdi.get(i) + 1); countdire.set(i, countdire.get(i) + repeats.get(c)); if (SSR.get(c).contains("A")) { Adi.set(i, Adi.get(i) + repeats.get(c)); } if (SSR.get(c).contains("T")) { Tdi.set(i, Tdi.get(i) + repeats.get(c)); } if (SSR.get(c).contains("G")) { Gdi.set(i, Gdi.get(i) + repeats.get(c)); } if (SSR.get(c).contains("C")) { Cdi.set(i, Cdi.get(i) + repeats.get(c)); } outdi.writeUTF(SSR.get(c)); outdi.writeInt(repeats.get(c)); outdi.writeInt(EndOfSsr.get(c)); } else if (SSR.get(c).length() == 3) { counttri.set(i, counttri.get(i) + 1); counttrire.set(i, counttrire.get(i) + repeats.get(c)); if (SSR.get(c).contains("A")) { Atri.set(i, Atri.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "A")); } if (SSR.get(c).contains("T")) { Ttri.set(i, Ttri.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "T")); } if (SSR.get(c).contains("G")) { Gtri.set(i, Gtri.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "G")); } if (SSR.get(c).contains("C")) { Ctri.set(i, Ctri.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "C")); } outtri.writeUTF(SSR.get(c)); outtri.writeInt(repeats.get(c)); outtri.writeInt(EndOfSsr.get(c)); } else if (SSR.get(c).length() == 4) { counttetra.set(i, counttetra.get(i) + 1); counttetrare.set(i, counttetrare.get(i) + repeats.get(c)); if (SSR.get(c).contains("A")) { Atetra.set(i, Atetra.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "A")); } if (SSR.get(c).contains("T")) { Ttetra.set(i, Ttetra.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "T")); } if (SSR.get(c).contains("G")) { Gtetra.set(i, Gtetra.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "G")); } if (SSR.get(c).contains("C")) { Ctetra.set(i, Ctetra.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "C")); } outtetra.writeUTF(SSR.get(c)); outtetra.writeInt(repeats.get(c)); outtetra.writeInt(EndOfSsr.get(c)); } else if (SSR.get(c).length() == 5) { countpenta.set(i, countpenta.get(i) + 1); countpentare.set(i, countpentare.get(i) + repeats.get(c)); if (SSR.get(c).contains("A")) { Apenta.set(i, Apenta.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "A")); } if (SSR.get(c).contains("T")) { Tpenta.set(i, Tpenta.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "T")); } if (SSR.get(c).contains("G")) { Gpenta.set(i, Gpenta.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "G")); } if (SSR.get(c).contains("C")) { Cpenta.set(i, Cpenta.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "C")); } outpenta.writeUTF(SSR.get(c)); outpenta.writeInt(repeats.get(c)); outpenta.writeInt(EndOfSsr.get(c)); } else if (SSR.get(c).length() == 6) { counthexa.set(i, counthexa.get(i) + 1); counthexare.set(i, counthexare.get(i) + repeats.get(c)); if (SSR.get(c).contains("A")) { Ahexa.set(i, Ahexa.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "A")); } if (SSR.get(c).contains("T")) { Thexa.set(i, Thexa.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "T")); } if (SSR.get(c).contains("G")) { Ghexa.set(i, Ghexa.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "G")); } if (SSR.get(c).contains("C")) { Chexa.set(i, Chexa.get(i) + repeats.get(c) * StringUtils.countMatches(SSR.get(c), "C")); } outhexa.writeUTF(SSR.get(c)); outhexa.writeInt(repeats.get(c)); outhexa.writeInt(EndOfSsr.get(c)); } } } } SSR = new ArrayList<String>(); repeats = new ArrayList<Integer>(); EndOfSsr = new ArrayList<Integer>(); } catch (EOFException e) { eof = true; } } outmono.close(); outdi.close(); outtri.close(); outtetra.close(); outpenta.close(); outhexa.close(); // in.close(); DataOutputStream save = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(files.substring(0, files.lastIndexOf('/')) + "/perf_stats"))); save.writeInt(countmono.get(i)); save.writeInt(countdi.get(i)); save.writeInt(counttri.get(i)); save.writeInt(counttetra.get(i)); save.writeInt(countpenta.get(i)); save.writeInt(counthexa.get(i)); save.writeInt(countmonore.get(i)); save.writeInt(countdire.get(i)); save.writeInt(counttrire.get(i)); save.writeInt(counttetrare.get(i)); save.writeInt(countpentare.get(i)); save.writeInt(counthexare.get(i)); save.writeInt(Amono.get(i)); save.writeInt(Tmono.get(i)); save.writeInt(Gmono.get(i)); save.writeInt(Cmono.get(i)); save.writeInt(Adi.get(i)); save.writeInt(Tdi.get(i)); save.writeInt(Gdi.get(i)); save.writeInt(Cdi.get(i)); save.writeInt(Atri.get(i)); save.writeInt(Ttri.get(i)); save.writeInt(Gtri.get(i)); save.writeInt(Ctri.get(i)); save.writeInt(Atetra.get(i)); save.writeInt(Ttetra.get(i)); save.writeInt(Gtetra.get(i)); save.writeInt(Ctetra.get(i)); save.writeInt(Apenta.get(i)); save.writeInt(Tpenta.get(i)); save.writeInt(Gpenta.get(i)); save.writeInt(Cpenta.get(i)); save.writeInt(Ahexa.get(i)); save.writeInt(Thexa.get(i)); save.writeInt(Ghexa.get(i)); save.writeInt(Chexa.get(i)); save.close(); } else { DataInputStream save = new DataInputStream(new BufferedInputStream( new FileInputStream(files.substring(0, files.lastIndexOf('/')) + "/perf_stats"))); countmono.set(i, save.readInt()); countdi.set(i, save.readInt()); counttri.set(i, save.readInt()); counttetra.set(i, save.readInt()); countpenta.set(i, save.readInt()); counthexa.set(i, save.readInt()); countmonore.set(i, save.readInt()); countdire.set(i, save.readInt()); counttrire.set(i, save.readInt()); counttetrare.set(i, save.readInt()); countpentare.set(i, save.readInt()); counthexare.set(i, save.readInt()); Amono.set(i, save.readInt()); Tmono.set(i, save.readInt()); Gmono.set(i, save.readInt()); Cmono.set(i, save.readInt()); Adi.set(i, save.readInt()); Tdi.set(i, save.readInt()); Gdi.set(i, save.readInt()); Cdi.set(i, save.readInt()); Atri.set(i, save.readInt()); Ttri.set(i, save.readInt()); Gtri.set(i, save.readInt()); Ctri.set(i, save.readInt()); Atetra.set(i, save.readInt()); Ttetra.set(i, save.readInt()); Gtetra.set(i, save.readInt()); Ctetra.set(i, save.readInt()); Apenta.set(i, save.readInt()); Tpenta.set(i, save.readInt()); Gpenta.set(i, save.readInt()); Cpenta.set(i, save.readInt()); Ahexa.set(i, save.readInt()); Thexa.set(i, save.readInt()); Ghexa.set(i, save.readInt()); Chexa.set(i, save.readInt()); save.close(); } } } }
From source file:MiGA.StatsSelection.java
public void getImPerfectSSRs(String[] organisms, int length, boolean flag, int gap) throws SQLException, ClassNotFoundException, FileNotFoundException, IOException { for (int i = 0; i < organisms.length; i++) { countmono.set(i, 0);/*w w w. ja v a 2 s.c o m*/ countdi.set(i, 0); counttri.set(i, 0); counttetra.set(i, 0); countpenta.set(i, 0); counthexa.set(i, 0); countmonore.set(i, 0); countdire.set(i, 0); counttrire.set(i, 0); counttetrare.set(i, 0); countpentare.set(i, 0); counthexare.set(i, 0); Amono.set(i, 0); Adi.set(i, 0); Atri.set(i, 0); Atetra.set(i, 0); Apenta.set(i, 0); Ahexa.set(i, 0); Tmono.set(i, 0); Tdi.set(i, 0); Ttri.set(i, 0); Ttetra.set(i, 0); Tpenta.set(i, 0); Thexa.set(i, 0); Gmono.set(i, 0); Gdi.set(i, 0); Gtri.set(i, 0); Gtetra.set(i, 0); Gpenta.set(i, 0); Ghexa.set(i, 0); Cmono.set(i, 0); Cdi.set(i, 0); Ctri.set(i, 0); Ctetra.set(i, 0); Cpenta.set(i, 0); Chexa.set(i, 0); boolean found = false; String buffer = new String(); int seekstart = 0; int seekend = 0; List<String> ssrs = new ArrayList<String>(); // 18/11/2013 added starting here String filetype = ""; String filepro = ""; if (flag) { filetype = "organisms"; filepro = "organisms/" + organisms[i] + "/data/"; int ret = getOrganismStatus(organisms[i]); if (ret == -1) indexer = new Indexer(chromosomelist); else indexer = new Indexer(ret); } else { filetype = "local"; filepro = "local/" + organisms[i] + "/data/"; String indexfile = "local/" + organisms[i] + "/index.txt"; indexer = new Indexer(indexfile); } //List<String> files = getFiles(organisms[i], minlen, flag); // 18/11/2013 added ending here while (indexer.hasNext()) { String files = filepro + indexer.getNextFileName(); List<File> exis = new ArrayList<File>(); exis.add(new File(files + "_" + length + "_" + gap + "_monoImPerfect.temp")); exis.add(new File(files + "_" + length + "_" + gap + "_diImPerfect.temp")); exis.add(new File(files + "_" + length + "_" + gap + "_triImPerfect.temp")); exis.add(new File(files + "_" + length + "_" + gap + "_tetraImPerfect.temp")); exis.add(new File(files + "_" + length + "_" + gap + "_pentaImPerfect.temp")); exis.add(new File(files + "_" + length + "_" + gap + "_hexaImPerfect.temp")); int num = 0; for (int temp = 0; temp < exis.size(); temp++) { if (exis.get(temp).exists()) { num++; } } if (num != exis.size()) { DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(files))); DataOutputStream outmono = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(files + "_" + length + "_" + gap + "_monoImPerfect.temp"))); DataOutputStream outdi = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(files + "_" + length + "_" + gap + "_diImPerfect.temp"))); DataOutputStream outtri = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(files + "_" + length + "_" + gap + "_triImPerfect.temp"))); DataOutputStream outtetra = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(files + "_" + length + "_" + gap + "_tetraImPerfect.temp"))); DataOutputStream outpenta = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(files + "_" + length + "_" + gap + "_pentaImPerfect.temp"))); DataOutputStream outhexa = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(files + "_" + length + "_" + gap + "_hexaImPerfect.temp"))); boolean eof = false; while (!eof) { try { SSR = new ArrayList<String>(); repeats = new ArrayList<Integer>(); EndOfSsr = new ArrayList<Integer>(); start = new ArrayList<Integer>(); int len = in.readInt(); int line = in.readInt(); //try{ for (int k = 0; k < len; k++) { String temp = in.readUTF(); //THIS //if(!temp.contains("N")){ SSR.add(temp); EndOfSsr.add(in.readInt()); repeats.add(in.readInt()); start.add(EndOfSsr.get(k) - (SSR.get(k).length() * repeats.get(k))); /*}else{ int junk = in.readInt(); junk = in.readInt(); k--; len--; }*/ } /*} catch(IndexOutOfBoundsException e){ System.out.println(SSR.size()); System.out.println(EndOfSsr.size()); System.out.println(repeats.size()); System.out.println(start.size()); }*/ List<String> SSRlen = new ArrayList<String>(); List<Integer> Endlen = new ArrayList<Integer>(); List<Integer> repslen = new ArrayList<Integer>(); List<Integer> startlen = new ArrayList<Integer>(); for (int k = 0; k < SSR.size(); k++) { if (SSR.get(k).length() * repeats.get(k) >= length) { SSRlen.add(SSR.get(k)); Endlen.add(EndOfSsr.get(k)); repslen.add(repeats.get(k)); startlen.add(start.get(k)); } } List<Integer> sortedstart = new ArrayList<Integer>(); List<Integer> sortedend = new ArrayList<Integer>(); for (int t = 0; t < startlen.size(); t++) { sortedstart.add(startlen.get(t)); sortedend.add(Endlen.get(t)); } Collections.sort(sortedstart); Collections.sort(sortedend); //List<String> tofile = new ArrayList<String>(); for (int k = 0; k < sortedstart.size() - 1; k++) { found = false; ssrs.clear(); ssrs = new ArrayList<String>(); if (sortedstart.get(k + 1) - sortedend.get(k) <= gap && sortedstart.get(k + 1) - sortedend.get(k) >= 0) { seekstart = sortedstart.get(k); while (k < sortedstart.size() - 1 && sortedstart.get(k + 1) - sortedend.get(k) <= gap && sortedstart.get(k + 1) - sortedend.get(k) >= 0) { for (int c = 0; c < startlen.size(); c++) { if (sortedstart.get(k) == startlen.get(c)) { ssrs.add(SSRlen.get(c)); } if (sortedstart.get(k + 1) == startlen.get(c)) { ssrs.add(SSRlen.get(c)); seekend = Endlen.get(c); found = true; } } k++; } k--; } boolean check = checkallsame(ssrs); if (found && check) { BufferedReader stdin = null; if (flag) { String[] temp = files.split("/"); boolean type = CheckForKaryotype(organisms[i]); String newdir = ""; if (type) { newdir = temp[0] + "/" + temp[1] + "/chrom-" + temp[3].substring(0, temp[3].lastIndexOf('.')) + "-slices.txt"; } else { newdir = temp[0] + "/" + temp[1] + "/slice-" + temp[3].substring(0, temp[3].lastIndexOf('.')) + ".txt"; } stdin = new BufferedReader(new FileReader(newdir)); } else { //files.add("local/" + organism + "/data/" + temp + ".ssr"); String[] temp = files.split("data/"); String newdir = temp[0] + "/" + temp[1].substring(0, temp[1].lastIndexOf('.')) + ".txt"; stdin = new BufferedReader(new FileReader(newdir)); } buffer = ""; for (int c = 0; c < line; c++) { buffer = stdin.readLine(); } //System.out.println(buffer.length() + "\t" + seekstart + "\t" + seekend); int real_end = ((Integer) (line - 1) * 20000) + seekend; int real_start = ((Integer) (line - 1) * 20000) + seekstart; //tofile.add("SSR: "+buffer.substring(seekstart, seekend) + "start-end: "+ real_start + "-" +real_end ); if (ssrs.get(1).length() == 1) { countmono.set(i, countmono.get(i) + 1); countmonore.set(i, countmonore.get(i) + real_end - real_start); outmono.writeUTF(buffer.substring(seekstart + 1, seekend + 1)); if (buffer.substring(seekstart + 1, seekend + 1).contains("A") || buffer.substring(seekstart + 1, seekend + 1).contains("a")) { Amono.set(i, Amono.get(i) + StringUtils.countMatches( buffer.substring(seekstart + 1, seekend + 1), "A") + StringUtils.countMatches( buffer.substring(seekstart + 1, seekend + 1), "a")); } if (buffer.substring(seekstart + 1, seekend + 1).contains("T") || buffer.substring(seekstart + 1, seekend + 1).contains("t")) { Tmono.set(i, Tmono.get(i) + StringUtils.countMatches( buffer.substring(seekstart + 1, seekend + 1), "T") + StringUtils.countMatches( buffer.substring(seekstart + 1, seekend + 1), "t")); } if (buffer.substring(seekstart + 1, seekend + 1).contains("G") || buffer.substring(seekstart + 1, seekend + 1).contains("g")) { Gmono.set(i, Gmono.get(i) + StringUtils.countMatches( buffer.substring(seekstart + 1, seekend + 1), "G") + StringUtils.countMatches( buffer.substring(seekstart + 1, seekend + 1), "g")); } if (buffer.substring(seekstart + 1, seekend + 1).contains("C") || buffer.substring(seekstart + 1, seekend + 1).contains("c")) { Cmono.set(i, Cmono.get(i) + StringUtils.countMatches( buffer.substring(seekstart + 1, seekend + 1), "C") + StringUtils.countMatches( buffer.substring(seekstart + 1, seekend + 1), "c")); } outmono.writeInt(real_start + 1); outmono.writeInt(real_end + 1); } else if (ssrs.get(1).length() == 2) { countdi.set(i, countdi.get(i) + 1); countdire.set(i, countdire.get(i) + real_end - real_start); if (buffer.substring(seekstart, seekend).contains("A") || buffer.substring(seekstart, seekend).contains("a")) { Adi.set(i, Adi.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "A") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "a")); } if (buffer.substring(seekstart, seekend).contains("T") || buffer.substring(seekstart, seekend).contains("t")) { Tdi.set(i, Tdi.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "T") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "t")); } if (buffer.substring(seekstart, seekend).contains("G") || buffer.substring(seekstart, seekend).contains("g")) { Gdi.set(i, Gdi.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "G") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "g")); } if (buffer.substring(seekstart, seekend).contains("C") || buffer.substring(seekstart, seekend).contains("c")) { Cdi.set(i, Cdi.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "C") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "c")); } outdi.writeUTF(buffer.substring(seekstart, seekend)); outdi.writeInt(real_start); outdi.writeInt(real_end); } else if (ssrs.get(1).length() == 3) { counttri.set(i, counttri.get(i) + 1); counttrire.set(i, counttrire.get(i) + real_end - real_start); if (buffer.substring(seekstart, seekend).contains("A") || buffer.substring(seekstart, seekend).contains("a")) { Atri.set(i, Atri.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "A") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "a")); } if (buffer.substring(seekstart, seekend).contains("T") || buffer.substring(seekstart, seekend).contains("t")) { Ttri.set(i, Ttri.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "T") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "t")); } if (buffer.substring(seekstart, seekend).contains("G") || buffer.substring(seekstart, seekend).contains("g")) { Gtri.set(i, Gtri.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "G") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "g")); } if (buffer.substring(seekstart, seekend).contains("C") || buffer.substring(seekstart, seekend).contains("c")) { Ctri.set(i, Ctri.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "C") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "c")); } outtri.writeUTF(buffer.substring(seekstart, seekend)); outtri.writeInt(real_start); outtri.writeInt(real_end); } else if (ssrs.get(1).length() == 4) { counttetra.set(i, counttetra.get(i) + 1); counttetrare.set(i, counttetrare.get(i) + real_end - real_start); if (buffer.substring(seekstart, seekend).contains("A") || buffer.substring(seekstart, seekend).contains("a")) { Atetra.set(i, Atetra.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "A") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "a")); } if (buffer.substring(seekstart, seekend).contains("T") || buffer.substring(seekstart, seekend).contains("t")) { Ttetra.set(i, Ttetra.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "T") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "t")); } if (buffer.substring(seekstart, seekend).contains("G") || buffer.substring(seekstart, seekend).contains("g")) { Gtetra.set(i, Gtetra.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "G") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "g")); } if (buffer.substring(seekstart, seekend).contains("C") || buffer.substring(seekstart, seekend).contains("c")) { Ctetra.set(i, Ctetra.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "C") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "c")); } outtetra.writeUTF(buffer.substring(seekstart, seekend)); outtetra.writeInt(real_start); outtetra.writeInt(real_end); } else if (ssrs.get(1).length() == 5) { countpenta.set(i, countpenta.get(i) + 1); countpentare.set(i, countpentare.get(i) + real_end - real_start); if (buffer.substring(seekstart, seekend).contains("A") || buffer.substring(seekstart, seekend).contains("a")) { Apenta.set(i, Apenta.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "A") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "a")); } if (buffer.substring(seekstart, seekend).contains("T") || buffer.substring(seekstart, seekend).contains("t")) { Tpenta.set(i, Tpenta.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "T") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "t")); } if (buffer.substring(seekstart, seekend).contains("G") || buffer.substring(seekstart, seekend).contains("g")) { Gpenta.set(i, Gpenta.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "G") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "g")); } if (buffer.substring(seekstart, seekend).contains("C") || buffer.substring(seekstart, seekend).contains("c")) { Cpenta.set(i, Cpenta.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "C") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "c")); } outpenta.writeUTF(buffer.substring(seekstart, seekend)); outpenta.writeInt(real_start); outpenta.writeInt(real_end); } else if (ssrs.get(1).length() == 6) { counthexa.set(i, counthexa.get(i) + 1); counthexare.set(i, counthexare.get(i) + real_end - real_start); if (buffer.substring(seekstart, seekend).contains("A") || buffer.substring(seekstart, seekend).contains("a")) { Ahexa.set(i, Ahexa.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "A") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "a")); } if (buffer.substring(seekstart, seekend).contains("T") || buffer.substring(seekstart, seekend).contains("t")) { Thexa.set(i, Thexa.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "T") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "t")); } if (buffer.substring(seekstart, seekend).contains("G") || buffer.substring(seekstart, seekend).contains("g")) { Ghexa.set(i, Ghexa.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "G") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "g")); } if (buffer.substring(seekstart, seekend).contains("C") || buffer.substring(seekstart, seekend).contains("c")) { Chexa.set(i, Chexa.get(i) + StringUtils.countMatches( buffer.substring(seekstart, seekend), "C") + StringUtils.countMatches( buffer.substring(seekstart, seekend), "c")); } outhexa.writeUTF(buffer.substring(seekstart, seekend)); outhexa.writeInt(real_start); outhexa.writeInt(real_end); } //out.println("SSR: " + buffer.substring(seekstart, seekend) + " start-end: " + real_start + "-" + real_end); stdin.close(); } } } catch (EOFException e) { eof = true; } } in.close(); outmono.close(); outdi.close(); outtri.close(); outtetra.close(); outpenta.close(); outhexa.close(); DataOutputStream save = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(files.substring(0, files.lastIndexOf('/')) + "/imperf_stats"))); save.writeInt(countmono.get(i)); save.writeInt(countdi.get(i)); save.writeInt(counttri.get(i)); save.writeInt(counttetra.get(i)); save.writeInt(countpenta.get(i)); save.writeInt(counthexa.get(i)); save.writeInt(countmonore.get(i)); save.writeInt(countdire.get(i)); save.writeInt(counttrire.get(i)); save.writeInt(counttetrare.get(i)); save.writeInt(countpentare.get(i)); save.writeInt(counthexare.get(i)); save.writeInt(Amono.get(i)); save.writeInt(Tmono.get(i)); save.writeInt(Gmono.get(i)); save.writeInt(Cmono.get(i)); save.writeInt(Adi.get(i)); save.writeInt(Tdi.get(i)); save.writeInt(Gdi.get(i)); save.writeInt(Cdi.get(i)); save.writeInt(Atri.get(i)); save.writeInt(Ttri.get(i)); save.writeInt(Gtri.get(i)); save.writeInt(Ctri.get(i)); save.writeInt(Atetra.get(i)); save.writeInt(Ttetra.get(i)); save.writeInt(Gtetra.get(i)); save.writeInt(Ctetra.get(i)); save.writeInt(Apenta.get(i)); save.writeInt(Tpenta.get(i)); save.writeInt(Gpenta.get(i)); save.writeInt(Cpenta.get(i)); save.writeInt(Ahexa.get(i)); save.writeInt(Thexa.get(i)); save.writeInt(Ghexa.get(i)); save.writeInt(Chexa.get(i)); save.close(); } else { DataInputStream save = new DataInputStream(new BufferedInputStream( new FileInputStream(files.substring(0, files.lastIndexOf('/')) + "/imperf_stats"))); countmono.set(i, save.readInt()); countdi.set(i, save.readInt()); counttri.set(i, save.readInt()); counttetra.set(i, save.readInt()); countpenta.set(i, save.readInt()); counthexa.set(i, save.readInt()); countmonore.set(i, save.readInt()); countdire.set(i, save.readInt()); counttrire.set(i, save.readInt()); counttetrare.set(i, save.readInt()); countpentare.set(i, save.readInt()); counthexare.set(i, save.readInt()); Amono.set(i, save.readInt()); Tmono.set(i, save.readInt()); Gmono.set(i, save.readInt()); Cmono.set(i, save.readInt()); Adi.set(i, save.readInt()); Tdi.set(i, save.readInt()); Gdi.set(i, save.readInt()); Cdi.set(i, save.readInt()); Atri.set(i, save.readInt()); Ttri.set(i, save.readInt()); Gtri.set(i, save.readInt()); Ctri.set(i, save.readInt()); Atetra.set(i, save.readInt()); Ttetra.set(i, save.readInt()); Gtetra.set(i, save.readInt()); Ctetra.set(i, save.readInt()); Apenta.set(i, save.readInt()); Tpenta.set(i, save.readInt()); Gpenta.set(i, save.readInt()); Cpenta.set(i, save.readInt()); Ahexa.set(i, save.readInt()); Thexa.set(i, save.readInt()); Ghexa.set(i, save.readInt()); Chexa.set(i, save.readInt()); save.close(); } } } }
From source file:com.codename1.impl.android.AndroidImplementation.java
/** * Gets the service properties. Will read properties from file so that * they are available even if CN1 is not initialized. * @param a//w w w . ja v a2 s . c o m * @return */ public static Map<String, String> getServiceProperties(Context a) { if (serviceProperties == null) { InputStream i = null; try { serviceProperties = new HashMap<String, String>(); i = a.openFileInput("CN1$AndroidServiceProperties"); if (i == null) { return serviceProperties; } DataInputStream is = new DataInputStream(i); int count = is.readInt(); for (int idx = 0; idx < count; idx++) { String key = is.readUTF(); String value = is.readUTF(); serviceProperties.put(key, value); } } catch (IOException ex) { Logger.getLogger(AndroidImplementation.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (i != null) i.close(); } catch (Throwable ex) { Logger.getLogger(AndroidImplementation.class.getName()).log(Level.SEVERE, null, ex); } } } return serviceProperties; }