List of usage examples for java.io DataInputStream close
public void close() throws IOException
From source file:eu.cloud4soa.soa.jaxrs.test.Initializer.java
private void createApplicationInstance() throws FileNotFoundException { URL fileURL = this.getClass().getClassLoader().getResource("SimpleWar.war"); if (fileURL == null) { throw new FileNotFoundException("SimpleWar.war"); }/*from w ww . j a va2 s . c o m*/ ByteArrayOutputStream bas = new ByteArrayOutputStream(); File file = new File(fileURL.getPath()); file.length(); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); DataInputStream dis = new DataInputStream(bis); //Calculate digest from InputStream // InputStream tempIs = new FileInputStream(file); String tempFileDigest = null; try { FileInputStream tempFis = new FileInputStream(file); tempFileDigest = DigestUtils.sha256Hex(tempFis); } catch (IOException ex) { logger.error(ex.getMessage()); } applicationInstance = new ApplicationInstance(); applicationInstance.setAcronym("C4Sv1.0"); applicationInstance.setApplicationcode("C4Sv1.0"); applicationInstance.setDigest(tempFileDigest); applicationInstance.setProgramminglanguage("JAVA"); applicationInstance.setProgramminglanguageVersion("1.6"); applicationInstance.setSizeQuantity(new Float(file.length())); applicationInstance.setVersion("1.0"); applicationInstance.setArchiveFileName("SimpleWar"); applicationInstance.setArchiveExtensionName(".war"); DBStorageComponentInstance dbStorageComponentInstance = new DBStorageComponentInstance(); dbStorageComponentInstance.setDbname("c4sDB"); dbStorageComponentInstance.setDbuser("c4sDBuser"); dbStorageComponentInstance.setDbpassword("c4sDBpassword"); dbStorageComponentInstance.setDbtype("MySQL"); SqlDbCategoryInstance sqlDbCategoryInstance = new SqlDbCategoryInstance(); sqlDbCategoryInstance.setTitle("MySQL"); dbStorageComponentInstance.setRelatedhwcategoryInstance(sqlDbCategoryInstance); ArrayList<SoftwareComponentInstance> arrayList = new ArrayList<SoftwareComponentInstance>(); arrayList.add(dbStorageComponentInstance); applicationInstance.setSoftwareComponents(arrayList); ArrayList<ServiceQualityInstance> serviceQualityInstances = new ArrayList<ServiceQualityInstance>() { }; LatencyInstance latencyInstance = new LatencyInstance(); latencyInstance.setHasTimeRangeValue(1f, 2f); UptimeInstance uptimeInstance = new UptimeInstance(); uptimeInstance.setHasPercentage(99f); serviceQualityInstances.add(latencyInstance); serviceQualityInstances.add(uptimeInstance); applicationInstance.setServiceQualities(serviceQualityInstances); //zeginis--> SoftwareCategoryInstance autoscaling = new SoftwareCategoryInstance("autoscaling", "Enable the automatic scaling of the reserources when needed"); applicationInstance.createAndAddSoftwareComponent("", "", "", "", autoscaling); HardwareComponentInstance communicationalComponent = applicationInstance .createAndAddHardwareComponent(HardwareCategoryType.NetworkCategory); // NetworkResourceInstance networkResourceInstance = (NetworkResourceInstance) communicationalComponent.getRelatedhwcategoryInstance(); NetworkResourceInstance networkResourceInstance = (NetworkResourceInstance) communicationalComponent; networkResourceInstance.setMinBandwidthValue(1000f); networkResourceInstance.setMaxLatencyValue(4f); HardwareComponentInstance boxComponent = applicationInstance .createAndAddHardwareComponent(HardwareCategoryType.HttpRequestHandlerCategory); // HttpRequestsHandlerInstance boxInstance = (HttpRequestsHandlerInstance) boxComponent.getRelatedhwcategoryInstance(); HttpRequestsHandlerInstance boxInstance = (HttpRequestsHandlerInstance) boxComponent; boxInstance.setMinHTTPRequests(10f); HardwareComponentInstance computeComponent = applicationInstance .createAndAddHardwareComponent(HardwareCategoryType.ComputationalCategory); // ComputeInstance computeInstance = (ComputeInstance) computeComponent.getRelatedhwcategoryInstance(); ComputeInstance computeInstance = (ComputeInstance) computeComponent; computeInstance.setArchitecture("64 bit"); computeInstance.setMinCacheValue(64f); computeInstance.setMinHasCores(2f); computeInstance.setMinMemoryValue(1024f); // computeInstance.setMinSpeedValue(4f); HardwareComponentInstance storageComponent = applicationInstance .createAndAddHardwareComponent(HardwareCategoryType.StorageCategory); // StorageResourceInstance storageResourceInstance = (StorageResourceInstance) storageComponent.getRelatedhwcategoryInstance(); StorageResourceInstance storageResourceInstance = (StorageResourceInstance) storageComponent; storageResourceInstance.setTitle("googleStorage"); storageResourceInstance.setMaxCapacityValue(12000f); storageResourceInstance.setMaxBandwidthValue(1000f); try { fis.close(); bis.close(); dis.close(); } catch (IOException ex) { logger.error(ex.getMessage()); } }
From source file:fi.mikuz.boarder.util.FileProcessor.java
public static GraphicalSoundboardHolder loadUnlimitedSoundboardBoard(File boardDir, String boardName) throws IOException { GraphicalSoundboardHolder holder = new GraphicalSoundboardHolder(); GraphicalSoundboard gsb = new GraphicalSoundboard(); DataInputStream in = new DataInputStream(new FileInputStream(boardDir + "/graphicalBoard")); BufferedReader br = new BufferedReader(new InputStreamReader(in), 8192); String line;/* w ww . j ava 2s.c o m*/ line = br.readLine(); gsb.setPlaySimultaneously(Boolean.parseBoolean(line.substring(0, line.indexOf("1")))); gsb.setBoardVolume( Float.valueOf(line.substring(line.indexOf("1") + 3, line.indexOf("2"))).floatValue()); gsb.setUseBackgroundImage( Boolean.parseBoolean(line.substring(line.indexOf("2") + 3, line.indexOf("3")))); gsb.setBackgroundColor( Integer.valueOf(line.substring(line.indexOf("3") + 3, line.indexOf("4"))).intValue()); File backgroundImagePath = new File(line.substring(line.indexOf("4") + 3, line.indexOf("5"))); if (backgroundImagePath.toString().contains("local/")) { backgroundImagePath = new File(SoundboardMenu.mSbDir + "/" + boardName, backgroundImagePath.toString().substring(6, backgroundImagePath.toString().length())); } else if (backgroundImagePath.toString().equals("na")) { backgroundImagePath = null; } gsb.setBackgroundImagePath(backgroundImagePath); gsb.setBackgroundX( Float.valueOf(line.substring(line.indexOf("5") + 3, line.indexOf("6"))).floatValue()); gsb.setBackgroundY( Float.valueOf(line.substring(line.indexOf("6") + 3, line.indexOf("7"))).floatValue()); gsb.setBackgroundWidthHeight(null, Float.valueOf(line.substring(line.indexOf("7") + 3, line.indexOf("8"))).floatValue(), Float.valueOf(line.substring(line.indexOf("8") + 3, line.indexOf("9"))).floatValue()); gsb.setScreenOrientation( Integer.valueOf(line.substring(line.indexOf("9") + 3, line.indexOf("10"))).intValue()); gsb.setAutoArrange(Boolean.parseBoolean(line.substring(line.indexOf("10") + 4, line.indexOf("11")))); gsb.setAutoArrangeColumns( Integer.valueOf(line.substring(line.indexOf("11") + 4, line.indexOf("12"))).intValue()); gsb.setAutoArrangeRows(Integer.valueOf(line.substring(line.indexOf("12") + 4, line.length())).intValue()); while ((line = br.readLine()) != null) { GraphicalSound sound = new GraphicalSound(); sound.setName(line.substring(0, line.indexOf("1")).replaceAll("lineBreak", "\n")); File soundPath = new File(line.substring(line.indexOf("1") + 3, line.indexOf("2"))); if (soundPath.toString().contains("local/")) { sound.setPath(new File(SoundboardMenu.mSbDir + "/" + boardName, soundPath.toString().substring(6, soundPath.toString().length()))); } else { sound.setPath(soundPath); } sound.setVolumeLeft( Float.valueOf(line.substring(line.indexOf("2") + 3, line.indexOf("3"))).floatValue()); sound.setVolumeRight( Float.valueOf(line.substring(line.indexOf("3") + 3, line.indexOf("4"))).floatValue()); sound.setNameFrameX( Float.valueOf(line.substring(line.indexOf("4") + 3, line.indexOf("5"))).floatValue()); sound.setNameFrameY( Float.valueOf(line.substring(line.indexOf("5") + 3, line.indexOf("6"))).floatValue()); sound.setHideImageOrText(Integer.valueOf(line.substring(line.indexOf("8") + 3, line.indexOf("9")))); File imagePath = new File(line.substring(line.indexOf("9") + 3, line.indexOf("10"))); if (imagePath.toString().contains("local/")) { sound.setImagePath(new File(SoundboardMenu.mSbDir + "/" + boardName, imagePath.toString().substring(6, imagePath.toString().length()))); } else { sound.setImagePath(imagePath); } sound.setImageX( Float.valueOf(line.substring(line.indexOf("10") + 4, line.indexOf("11"))).floatValue()); sound.setImageY( Float.valueOf(line.substring(line.indexOf("11") + 4, line.indexOf("12"))).floatValue()); sound.setImageWidthHeight(null, Float.valueOf(line.substring(line.indexOf("12") + 4, line.indexOf("13"))).floatValue(), Float.valueOf(line.substring(line.indexOf("13") + 4, line.indexOf("14"))).floatValue()); sound.setHideImageOrText( Integer.valueOf(line.substring(line.indexOf("14") + 4, line.indexOf("15")))); sound.setNameTextColorInt( Integer.valueOf(line.substring(line.indexOf("15") + 4, line.indexOf("16")))); sound.setNameFrameInnerColorInt( Integer.valueOf(line.substring(line.indexOf("16") + 4, line.indexOf("17")))); sound.setNameFrameBorderColorInt( Integer.valueOf(line.substring(line.indexOf("17") + 4, line.indexOf("18")))); sound.setShowNameFrameInnerPaint( Boolean.parseBoolean(line.substring(line.indexOf("18") + 4, line.indexOf("19")))); sound.setShowNameFrameBorderPaint( Boolean.parseBoolean(line.substring(line.indexOf("19") + 4, line.indexOf("20")))); sound.setLinkNameAndImage( Boolean.parseBoolean(line.substring(line.indexOf("20") + 4, line.indexOf("21")))); sound.setNameSize(Float.valueOf(line.substring(line.indexOf("21") + 4, line.indexOf("22")))); sound.setAutoArrangeColumn( Integer.valueOf(line.substring(line.indexOf("22") + 4, line.indexOf("23")))); sound.setAutoArrangeRow( Integer.valueOf(line.substring(line.indexOf("23") + 4, line.indexOf("24")))); File activeImagePath = new File(line.substring(line.indexOf("24") + 4, line.indexOf("25"))); if (activeImagePath.toString().contains("local/")) { sound.setActiveImagePath(new File(SoundboardMenu.mSbDir + "/" + boardName, activeImagePath.toString().substring(6, activeImagePath.toString().length()))); } else { sound.setActiveImagePath(activeImagePath); } sound.setSecondClickAction(Integer.valueOf(line.substring(line.indexOf("25") + 4, line.length()))); if (sound.getImagePath().getAbsolutePath().equals("/")) sound.setImagePath(null); if (sound.getActiveImagePath().getAbsolutePath().equals("/")) sound.setActiveImagePath(null); gsb.addSound(sound); } in.close(); holder.getBoardList().add(gsb); return holder; }
From source file:com.portfolio.data.provider.MysqlAdminProvider.java
@Override public Object postPortfolioZip(MimeType mimeType, MimeType mimeType2, HttpServletRequest httpServletRequest, int userId, int groupId, String modelId) throws FileNotFoundException, IOException { if (!credential.isAdmin(userId)) throw new RestWebApplicationException(Status.FORBIDDEN, "No admin right"); DataInputStream inZip = new DataInputStream(httpServletRequest.getInputStream()); ByteArrayOutputStream byte2 = new ByteArrayOutputStream(); StringBuffer outTrace = new StringBuffer(); String portfolioId = null;//from w w w. j a v a2 s . c om portfolioId = httpServletRequest.getParameter("portfolio"); String foldersfiles = null; String filename; String[] xmlFiles; String[] allFiles; String[] ImgFiles; int formDataLength = httpServletRequest.getContentLength(); byte[] buff = new byte[formDataLength]; // Recuperation de l'heure laquelle le zip est cr //Calendar cal = Calendar.getInstance(); //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss_S"); //String now = sdf.format(cal.getTime()); this.genererPortfolioUuidPreliminaire(); javax.servlet.http.HttpSession session = httpServletRequest.getSession(true); String ppath = session.getServletContext().getRealPath(File.separator); String outsideDir = ppath.substring(0, ppath.lastIndexOf(File.separator)) + "_files" + File.separator; File outsideDirectoryFile = new File(outsideDir); System.out.println(outsideDir); // if the directory does not exist, create it if (!outsideDirectoryFile.exists()) { outsideDirectoryFile.mkdir(); } //Creation du zip filename = outsideDir + "xml_" + this.portfolioUuidPreliminaire + ".zip"; FileOutputStream outZip = new FileOutputStream(filename); int len; while ((len = inZip.read(buff)) != -1) { outZip.write(buff, 0, len); } inZip.close(); outZip.close(); //-- unzip -- foldersfiles = unzip(filename, outsideDir + this.portfolioUuidPreliminaire + File.separator); //TODO Attention si plusieurs XML dans le fichier xmlFiles = findFiles(outsideDir + this.portfolioUuidPreliminaire + File.separator, "xml"); allFiles = findFiles(outsideDir + this.portfolioUuidPreliminaire + File.separator, null); for (int i = 0; i < allFiles.length; i++) { portfolioRessourcesImportPath.add(allFiles[i]); String tmpFileName = allFiles[i].substring(allFiles[i].lastIndexOf(File.separator) + 1); String uuid = tmpFileName.substring(0, tmpFileName.indexOf("_")); portfolioRessourcesImportUuid.add(uuid); tmpFileName = allFiles[i].substring(allFiles[i].lastIndexOf(File.separator) + 1); String lang; try { int tmpPos = tmpFileName.indexOf("_"); lang = tmpFileName.substring(tmpPos + 1, tmpPos + 3); } catch (Exception ex) { lang = ""; } InputStream is = new FileInputStream(allFiles[i]); byte b[] = new byte[is.available()]; is.read(b); String extension; try { extension = tmpFileName.substring(tmpFileName.lastIndexOf(".") + 1); } catch (Exception ex) { extension = null; } // trop long //String tmpMimeType = FileUtils.getMimeType("file://"+allFiles[i]); String tmpMimeType = FileUtils.getMimeTypeFromExtension(extension); // Attention on initialise la ligne file // avec l'UUID d'origine de l'asmContext parent // Il sera mis jour avec l'UUID asmContext final dans writeNode try { UUID tmpUuid = UUID.fromString(uuid); if (tmpUuid.toString().equals(uuid)) this.putFile(uuid, lang, tmpFileName, outsideDir, tmpMimeType, extension, b.length, b, userId); } catch (Exception ex) { // Le nom du fichier ne commence pas par un UUID, // ce n'est donc pas une ressource } } //TODO Supprimer le zip quand a fonctionnera bien //--- Read xml fileL ---- for (int i = 0; i < xmlFiles.length; i++) { BufferedReader br = new BufferedReader(new FileReader(new File(xmlFiles[i]))); String line; StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) { sb.append(line.trim()); } String xml = "?"; xml = sb.toString(); if (xml.contains("<portfolio id=")) { try { Object returnValue = postPortfolio(new MimeType("text/xml"), new MimeType("text/xml"), xml, userId, groupId, null); return returnValue; } catch (MimeTypeParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return false; }
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/*ww w . ja v a2s .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 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:com.chinamobile.bcbsp.partition.HashWithBalancerWritePartition.java
/** * This method is used to partition graph vertexes. Writing Each vertex to the * corresponding partition. In this method calls recordParse method to create * an HeadNode object. The last call partitioner's getPartitionId method to * calculate the HeadNode belongs to partition's id. If the HeadNode belongs * local partition then written to the local partition or send it to the * appropriate partition.// w w w. j a v a 2 s . co m * @param recordReader The recordreader of the split. * @throws IOException The io exception * @throws InterruptedException The Interrupted Exception */ @Override public void write(RecordReader recordReader) throws IOException, InterruptedException { int headNodeNum = 0; int local = 0; int send = 0; int lost = 0; ThreadPool tpool = new ThreadPool(this.sendThreadNum); int staffNum = this.staff.getStaffNum(); BytesWritable kbytes = new BytesWritable(); int ksize = 0; BytesWritable vbytes = new BytesWritable(); int vsize = 0; DataOutputBuffer bb = new DataOutputBuffer(); int bufferSize = (int) ((this.TotalCacheSize * CONTAINERNUMBER * CONTAINERNUMBER) * PART); int dataBufferSize = (this.TotalCacheSize * CONTAINERNUMBER * CONTAINERNUMBER) / (this.staff.getStaffNum() + this.sendThreadNum); byte[] buffer = new byte[bufferSize]; int bufindex = 0; SerializationFactory sFactory = new SerializationFactory(new Configuration()); Serializer<IntWritable> psserializer = sFactory.getSerializer(IntWritable.class); byte[] pidandsize = new byte[TIME * CONTAINERNUMBER * CONTAINERNUMBER]; int psindex = 0; BytesWritable pidbytes = new BytesWritable(); int psize = 0; BytesWritable sizebytes = new BytesWritable(); int ssize = 0; try { this.keyserializer.open(bb); this.valueserializer.open(bb); psserializer.open(bb); } catch (IOException e) { throw e; } String path = "/tmp/bcbsp/" + this.staff.getJobID() + "/" + this.staff.getStaffID(); File dir = new File("/tmp/bcbsp/" + this.staff.getJobID()); dir.mkdir(); dir = new File("/tmp/bcbsp/" + this.staff.getJobID() + "/" + this.staff.getStaffID()); dir.mkdir(); ArrayList<File> files = new ArrayList<File>(); try { File file = new File(path + "/" + "data" + ".txt"); files.add(file); DataOutputStream dataWriter = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(path + "/" + "data" + ".txt", true))); DataInputStream dataReader = new DataInputStream( new BufferedInputStream(new FileInputStream(path + "/" + "data" + ".txt"))); File filet = new File(path + "/" + "pidandsize" + ".txt"); files.add(filet); DataOutputStream psWriter = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(path + "/" + "pidandsize" + ".txt", true))); DataInputStream psReader = new DataInputStream( new BufferedInputStream(new FileInputStream(path + "/" + "pidandsize" + ".txt"))); while (recordReader != null && recordReader.nextKeyValue()) { headNodeNum++; Text key = new Text(recordReader.getCurrentKey().toString()); Text value = new Text(recordReader.getCurrentValue().toString()); int pid = -1; Text vertexID = this.recordParse.getVertexID(key); if (vertexID != null) { pid = this.partitioner.getPartitionID(vertexID); } else { lost++; continue; } if (this.counter.containsKey(pid)) { this.counter.put(pid, (this.counter.get(pid) + 1)); } else { this.counter.put(pid, 1); } bb.reset(); this.keyserializer.serialize(key); kbytes.set(bb.getData(), 0, bb.getLength()); ksize = kbytes.getLength(); bb.reset(); this.valueserializer.serialize(value); vbytes.set(bb.getData(), 0, bb.getLength()); vsize = vbytes.getLength(); bb.reset(); psserializer.serialize(new IntWritable(ksize + vsize)); sizebytes.set(bb.getData(), 0, bb.getLength()); ssize = sizebytes.getLength(); bb.reset(); psserializer.serialize(new IntWritable(pid)); pidbytes.set(bb.getData(), 0, bb.getLength()); psize = pidbytes.getLength(); if ((pidandsize.length - psindex) > (ssize + psize)) { System.arraycopy(sizebytes.getBytes(), 0, pidandsize, psindex, ssize); psindex += ssize; System.arraycopy(pidbytes.getBytes(), 0, pidandsize, psindex, psize); psindex += psize; } else { psWriter.write(pidandsize, 0, psindex); psindex = 0; System.arraycopy(sizebytes.getBytes(), 0, pidandsize, psindex, ssize); psindex += ssize; System.arraycopy(pidbytes.getBytes(), 0, pidandsize, psindex, psize); psindex += psize; } if ((buffer.length - bufindex) > (ksize + vsize)) { System.arraycopy(kbytes.getBytes(), 0, buffer, bufindex, ksize); bufindex += ksize; System.arraycopy(vbytes.getBytes(), 0, buffer, bufindex, vsize); bufindex += vsize; } else if (buffer.length < (ksize + vsize)) { dataWriter.write(buffer, 0, bufindex); bufindex = 0; LOG.info("This is a super record"); dataWriter.write(kbytes.getBytes(), 0, ksize); dataWriter.write(vbytes.getBytes(), 0, vsize); } else { dataWriter.write(buffer, 0, bufindex); bufindex = 0; System.arraycopy(kbytes.getBytes(), 0, buffer, bufindex, ksize); bufindex += ksize; System.arraycopy(vbytes.getBytes(), 0, buffer, bufindex, vsize); bufindex += vsize; } } if (psindex != 0) { psWriter.write(pidandsize, 0, psindex); } if (bufindex != 0) { dataWriter.write(buffer, 0, bufindex); bufindex = 0; } dataWriter.close(); dataWriter = null; psWriter.close(); psWriter = null; buffer = null; pidandsize = null; this.ssrc.setDirFlag(new String[] { "3" }); this.ssrc.setCounter(this.counter); HashMap<Integer, Integer> hashBucketToPartition = this.sssc.loadDataInBalancerBarrier(ssrc, Constants.PARTITION_TYPE.HASH); this.staff.setHashBucketToPartition(hashBucketToPartition); byte[][] databuf = new byte[staffNum][dataBufferSize]; int[] databufindex = new int[staffNum]; try { IntWritable pid = new IntWritable(); IntWritable size = new IntWritable(); int belongPid = 0; while (true) { size.readFields(psReader); pid.readFields(psReader); belongPid = hashBucketToPartition.get(pid.get()); if (belongPid != this.staff.getPartition()) { send++; } else { local++; } if ((databuf[belongPid].length - databufindex[belongPid]) > size.get()) { dataReader.read(databuf[belongPid], databufindex[belongPid], size.get()); databufindex[belongPid] += size.get(); } else if (databuf[belongPid].length < size.get()) { LOG.info("This is a super record"); byte[] tmp = new byte[size.get()]; dataReader.read(tmp, 0, size.get()); if (belongPid == this.staff.getPartition()) { DataInputStream reader = new DataInputStream( new BufferedInputStream(new ByteArrayInputStream(tmp))); try { boolean stop = true; while (stop) { Text key = new Text(); key.readFields(reader); Text value = new Text(); value.readFields(reader); if (key.getLength() > 0 && value.getLength() > 0) { Vertex vertex = this.recordParse.recordParse(key.toString(), value.toString()); if (vertex == null) { lost++; continue; } this.staff.getGraphData().addForAll(vertex); } else { stop = false; } } } catch (IOException e) { LOG.info("IO exception: " + e.getStackTrace()); } } else { ThreadSignle t = tpool.getThread(); while (t == null) { t = tpool.getThread(); } t.setWorker( this.workerAgent.getWorker(staff.getJobID(), staff.getStaffID(), belongPid)); t.setJobId(staff.getJobID()); t.setTaskId(staff.getStaffID()); t.setBelongPartition(belongPid); BytesWritable data = new BytesWritable(); data.set(tmp, 0, size.get()); t.setData(data); LOG.info("Using Thread is: " + t.getThreadNumber()); t.setStatus(true); } tmp = null; } else { if (belongPid == this.staff.getPartition()) { DataInputStream reader = new DataInputStream(new BufferedInputStream( new ByteArrayInputStream(databuf[belongPid], 0, databufindex[belongPid]))); try { boolean stop = true; while (stop) { Text key = new Text(); key.readFields(reader); Text value = new Text(); value.readFields(reader); if (key.getLength() > 0 && value.getLength() > 0) { Vertex vertex = this.recordParse.recordParse(key.toString(), value.toString()); if (vertex == null) { lost++; continue; } this.staff.getGraphData().addForAll(vertex); } else { stop = false; } } } catch (IOException e) { LOG.info("IO exception: " + e.getStackTrace()); } } else { ThreadSignle t = tpool.getThread(); while (t == null) { t = tpool.getThread(); } t.setWorker( this.workerAgent.getWorker(staff.getJobID(), staff.getStaffID(), belongPid)); t.setJobId(staff.getJobID()); t.setTaskId(staff.getStaffID()); t.setBelongPartition(belongPid); BytesWritable data = new BytesWritable(); data.set(databuf[belongPid], 0, databufindex[belongPid]); t.setData(data); LOG.info("Using Thread is: " + t.getThreadNumber()); t.setStatus(true); } databufindex[belongPid] = 0; dataReader.read(databuf[belongPid], databufindex[belongPid], size.get()); databufindex[belongPid] += size.get(); } } } catch (EOFException ex) { LOG.error("[write]", ex); } for (int i = 0; i < staffNum; i++) { if (databufindex[i] != 0) { if (i == this.staff.getPartition()) { DataInputStream reader = new DataInputStream( new BufferedInputStream(new ByteArrayInputStream(databuf[i], 0, databufindex[i]))); try { boolean stop = true; while (stop) { Text key = new Text(); key.readFields(reader); Text value = new Text(); value.readFields(reader); if (key.getLength() > 0 && value.getLength() > 0) { Vertex vertex = this.recordParse.recordParse(key.toString(), value.toString()); if (vertex == null) { lost++; continue; } this.staff.getGraphData().addForAll(vertex); } else { stop = false; } } } catch (IOException e) { LOG.info("IO exception: " + e.getStackTrace()); } } else { ThreadSignle t = tpool.getThread(); while (t == null) { t = tpool.getThread(); } t.setWorker(this.workerAgent.getWorker(staff.getJobID(), staff.getStaffID(), i)); t.setJobId(staff.getJobID()); t.setTaskId(staff.getStaffID()); t.setBelongPartition(i); BytesWritable data = new BytesWritable(); data.set(databuf[i], 0, databufindex[i]); t.setData(data); LOG.info("Using Thread is: " + t.getThreadNumber()); t.setStatus(true); } } } dataReader.close(); dataReader = null; psReader.close(); psReader = null; for (File f : files) { f.delete(); } dir.delete(); dir = new File(path.substring(0, path.lastIndexOf('/'))); dir.delete(); tpool.cleanup(); tpool = null; databuf = null; databufindex = null; this.counter = null; LOG.info("The number of vertices that were read from the input file: " + headNodeNum); LOG.info("The number of vertices that were put into the partition: " + local); LOG.info("The number of vertices that were sent to other partitions: " + send); LOG.info("The number of verteices in the partition that cound not be " + "parsed:" + lost); } catch (IOException e) { throw e; } catch (InterruptedException e) { throw e; } finally { for (File f : files) { f.delete(); } dir.delete(); dir = new File(path.substring(0, path.lastIndexOf('/'))); dir.delete(); } }
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//www.j a v a 2 s . c om 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:com.portfolio.data.provider.MysqlDataProvider.java
@Override public Object postPortfolioZip(MimeType mimeType, MimeType mimeType2, HttpServletRequest httpServletRequest, int userId, int groupId, String modelId, int substid) throws IOException { if (!credential.isAdmin(userId) && !credential.isCreator(userId)) throw new RestWebApplicationException(Status.FORBIDDEN, "No admin right"); boolean isMultipart = ServletFileUpload.isMultipartContent(httpServletRequest); // Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(); // Configure a repository (to ensure a secure temp location is used) ServletContext servletContext = httpServletRequest.getSession().getServletContext(); File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir"); factory.setRepository(repository);/*from w w w. j a v a 2s.c om*/ // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); DataInputStream inZip = null; // Parse the request try { List<FileItem> items = upload.parseRequest(httpServletRequest); // Process the uploaded items Iterator<FileItem> iter = items.iterator(); while (iter.hasNext()) { FileItem item = iter.next(); if (!item.isFormField()) { inZip = new DataInputStream(item.getInputStream()); break; } } } catch (FileUploadException e) { // TODO Auto-generated catch block e.printStackTrace(); } String foldersfiles = null; String filename; String[] xmlFiles; String[] allFiles; // int formDataLength = httpServletRequest.getContentLength(); byte[] buff = new byte[0x100000]; // 1MB buffer // Recuperation de l'heure laquelle le zip est cr //Calendar cal = Calendar.getInstance(); //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss_S"); //String now = sdf.format(cal.getTime()); this.genererPortfolioUuidPreliminaire(); javax.servlet.http.HttpSession session = httpServletRequest.getSession(true); String ppath = session.getServletContext().getRealPath("/"); String outsideDir = ppath.substring(0, ppath.lastIndexOf(File.separator)) + "_files" + File.separator; File outsideDirectoryFile = new File(outsideDir); System.out.println(outsideDir); // if the directory does not exist, create it if (!outsideDirectoryFile.exists()) { outsideDirectoryFile.mkdir(); } //Creation du zip filename = outsideDir + "xml_" + this.portfolioUuidPreliminaire + ".zip"; FileOutputStream outZip = new FileOutputStream(filename); int len; while ((len = inZip.read(buff)) != -1) { outZip.write(buff, 0, len); } inZip.close(); outZip.close(); //-- unzip -- foldersfiles = unzip(filename, outsideDir + this.portfolioUuidPreliminaire + File.separator); //TODO Attention si plusieurs XML dans le fichier xmlFiles = findFiles(outsideDir + this.portfolioUuidPreliminaire + File.separator, "xml"); allFiles = findFiles(outsideDir + this.portfolioUuidPreliminaire + File.separator, null); ////// Lecture du fichier de portfolio StringBuffer outTrace = new StringBuffer(); //// Importation du portfolio //--- Read xml fileL ---- ///// Pour associer l'ancien uuid -> nouveau, pour les fichiers HashMap<String, String> resolve = new HashMap<String, String>(); String portfolioUuid = "erreur"; boolean hasLoaded = false; try { for (int i = 0; i < xmlFiles.length; i++) { String xmlFilepath = xmlFiles[i]; String xmlFilename = xmlFilepath.substring(xmlFilepath.lastIndexOf(File.separator)); if (xmlFilename.contains("_")) continue; // Case when we add an xml in the portfolio BufferedReader br = new BufferedReader(new FileReader(new File(xmlFilepath))); String line; StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) { sb.append(line.trim()); } String xml = "?"; xml = sb.toString(); portfolioUuid = UUID.randomUUID().toString(); if (xml.contains("<portfolio")) // Le porfolio (peux mieux faire) { Document doc = DomUtils.xmlString2Document(xml, outTrace); Node rootNode = (doc.getElementsByTagName("portfolio")).item(0); if (rootNode == null) throw new Exception("Root Node (portfolio) not found !"); else { rootNode = (doc.getElementsByTagName("asmRoot")).item(0); String uuid = UUID.randomUUID().toString(); insertMysqlPortfolio(portfolioUuid, uuid, 0, userId); writeNode(rootNode, portfolioUuid, null, userId, 0, uuid, null, 0, 0, false, resolve); } updateMysqlPortfolioActive(portfolioUuid, true); /// Finalement on cre un rle designer int groupid = postCreateRole(portfolioUuid, "designer", userId); /// Ajoute la personne dans ce groupe putUserGroup(Integer.toString(groupid), Integer.toString(userId)); hasLoaded = true; } } } catch (Exception e) { e.printStackTrace(); } if (hasLoaded) for (int i = 0; i < allFiles.length; i++) { String fullPath = allFiles[i]; String tmpFileName = allFiles[i].substring(allFiles[i].lastIndexOf(File.separator) + 1); int index = tmpFileName.indexOf("_"); if (index == -1) index = tmpFileName.indexOf("."); int last = tmpFileName.lastIndexOf(File.separator); if (last == -1) last = 0; String uuid = tmpFileName.substring(last, index); // tmpFileName = allFiles[i].substring(allFiles[i].lastIndexOf(File.separator)+1); String lang; try { // int tmpPos = tmpFileName.indexOf("_"); lang = tmpFileName.substring(index + 1, index + 3); if ("un".equals(lang)) // Hack sort of fixing previous implementation lang = "en"; } catch (Exception ex) { lang = ""; } InputStream is = new FileInputStream(allFiles[i]); byte b[] = new byte[is.available()]; is.read(b); String extension; try { extension = tmpFileName.substring(tmpFileName.lastIndexOf(".") + 1); } catch (Exception ex) { extension = null; } // trop long //String tmpMimeType = FileUtils.getMimeType("file://"+allFiles[i]); String tmpMimeType = FileUtils.getMimeTypeFromExtension(extension); // Attention on initialise la ligne file // avec l'UUID d'origine de l'asmContext parent // Il sera mis jour avec l'UUID asmContext final dans writeNode try { UUID tmpUuid = UUID.fromString(uuid); /// base uuid String resolved = resolve.get(uuid); /// New uuid String sessionval = session.getId(); String user = (String) session.getAttribute("user"); // String test = outsideDir+File.separator+this.portfolioUuidPreliminaire+File.separator+tmpFileName; // File file = new File(outsideDir+File.separator+this.portfolioUuidPreliminaire+File.separator+tmpFileName); File file = new File(fullPath); // server backend // fileserver String backend = session.getServletContext().getInitParameter("backendserver"); if (resolved != null) { /// Have to send it in FORM, compatibility with regular file posting PostForm.sendFile(sessionval, backend, user, resolved, lang, file); /// No need to fetch resulting ID, since we provided it /* InputStream objReturn = connect.getInputStream(); StringWriter idResponse = new StringWriter(); IOUtils.copy(objReturn, idResponse); fileid = idResponse.toString(); //*/ } /* if(tmpUuid.toString().equals(uuid)) this.putFile(uuid,lang,tmpFileName,outsideDir,tmpMimeType,extension,b.length,b,userId); //*/ } catch (Exception ex) { // Le nom du fichier ne commence pas par un UUID, // ce n'est donc pas une ressource ex.printStackTrace(); } } File zipfile = new File(filename); zipfile.delete(); File zipdir = new File(outsideDir + this.portfolioUuidPreliminaire + File.separator); zipdir.delete(); return portfolioUuid; }
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/*ww w.j a va 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 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);//from w w w. j a 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(); } } } }