/** * A method to set the output file name to a series of numbered files, using a pattern like: * * <p>fileName = String.format("%s_%03d.%s", fName, fNumber, ext); * * <p>When fName includes an extension, it is first removed and saved into ext. * * @param fName a file path + name (with or without an extension). */ private static void createOutputStream(String fName) throws Exception { fName = FilenameUtils.normalize(fName); String name = FilenameUtils.removeExtension(fName); String ext = FilenameUtils.getExtension(fName); if (oSerializeFormat.equals("turtle")) { ext = "ttl"; } else if (oSerializeFormat.equals("Ntriples")) { ext = "nt"; } else if (ext.equals("")) { ext = "txt"; } fName = String.format("%s_%03d.%s", name, ++oFileNumber, ext); oFile = new File(fName); try { oStream.close(); oStream = new PrintStream(new FileOutputStream(oFile)); if (oSerializeFormat.equals("turtle")) { oStream.println(SparqlPrefixes.ttlMappingPrefix()); oStream.println(); if (oFileNumber == 1) { oStream.println(loomInfo.ttlSignature()); oStream.println(); } } } catch (Exception e) { log.fatal("Cannot create output file stream: {}", oFile.getAbsolutePath()); throw e; } }
private static void readBowtieResults( String fileName, HashMap<String, ArrayList<MappingInfo>> map) throws Exception { BufferedReader bf = Utils.getFile(fileName, "bout"); if (bf != null) { String line = null; int counter = 0; while ((line = bf.readLine()) != null) { if (counter % 1000000 == 0) { System.err.println("Read " + counter + " mapping records from " + fileName); } String[] splitLine = line.trim().split("\\s+"); MappingInfo m = new MappingInfo(); String contigID = splitLine[2]; Boolean isFwd = null; if (splitLine[1].contains("-")) { isFwd = false; } else if (splitLine[1].contains("+")) { isFwd = true; } m.readID = splitLine[0].replaceAll("/", "_"); m.start = 1; m.end = SUB_LEN; m.contigStart = Integer.parseInt(splitLine[3]); if (isFwd) { m.contigEnd = m.contigStart + splitLine[4].length() - 1; } else { m.contigEnd = m.contigStart; m.contigStart = m.contigEnd + splitLine[4].length() - 1; } if (map.get(contigID) == null) { map.put(contigID, new ArrayList<MappingInfo>(NUM_READS_PER_CTG)); } map.get(contigID).add(m); counter++; } bf.close(); } }