public TDFGroup createGroup(String name) { if (groupCache.containsKey(name)) { throw new RuntimeException("Group: " + name + " already exists"); } TDFGroup group = new TDFGroup(name); groupCache.put(name, group); return group; }
public TDFGroup(String name, ByteBuffer byteBuffer) throws IOException { super(name); fill(byteBuffer); }
void fill(ByteBuffer byteBuffer) throws IOException { readAttributes(byteBuffer); } }
/** * Test of createGroup method, of class IBFWriter. */ @Test public void testCreateGroup() { File testFile = new File("test1.tdf"); testFile.deleteOnExit(); String groupName = "/chr1"; TDFWriter writer = new TDFWriter(testFile, "hg18", type, trackLine, trackNames, wfs, false); TDFGroup group = writer.createGroup(groupName); group.setAttribute("attKey", "attValue"); group.setAttribute("attKey2", "attValue2"); writer.closeFile(); TDFReader reader = TDFReader.getReader(testFile.getAbsolutePath()); group = reader.getGroup(groupName); assertEquals(groupName, group.getName()); assertEquals(2, group.attributes.size()); assertEquals("attValue", group.attributes.get("attKey")); assertEquals("attValue2", group.attributes.get("attKey2")); reader.close(); }
private Double getValue(WindowFunction wf) { if (!valueCache.containsKey(wf)) { TDFGroup rootGroup = getGroup("/"); String maxString = rootGroup.getAttribute(wf.getValue()); try { valueCache.put(wf, Double.parseDouble(maxString)); } catch (Exception e) { log.info("Warning: value '" + wf.toString() + "' not found in tdf value " + getPath()); valueCache.put(wf, null); } } return valueCache.get(wf); }
private void writeGroups() throws IOException { for (TDFGroup group : groupCache.values()) { long position = bytesWritten; BufferedByteWriter buffer = new BufferedByteWriter(); group.write(buffer); write(buffer.getBytes()); int nBytes = (int) (bytesWritten - position); groupIndex.put(group.getName(), new IndexEntry(position, nBytes)); } }
public TDFWriter(File f, String genomeId, TrackType trackType, String trackLine, String[] trackNames, Collection<WindowFunction> windowFunctions, boolean compressed) throws IOException { if (f.getName().endsWith(".tdf")) { this.file = f; } else { this.file = new File(f.getAbsolutePath() + ".tdf"); } this.compressed = compressed; fos = new BufferedOutputStream(new FileOutputStream(file)); writeHeader(genomeId, trackType, trackLine, trackNames, windowFunctions); TDFGroup rootGroup = new TDFGroup("/"); groupCache.put(rootGroup.getName(), rootGroup); }
/** * Called to set inital parameters. It is required that this be called * prior to writing the file */ @Override public void setTrackParameters(TrackType trackType, String trackLine, String[] trackNames) throws IOException { if (trackLine != null) { System.out.println(trackLine); } if (outputFile != null && writer == null) { writer = new TDFWriter(outputFile, genome.getId(), trackType, trackLine, trackNames, windowFunctions, compressed); nTracks = trackNames.length; // Convert genome coordinates from bp to kbp int genomeLength = (int) (genome.getLength() / 1000); genomeZoom = new Zoom(Globals.CHR_ALL, 0, genomeLength); TDFGroup rootGroup = writer.getRootGroup(); rootGroup.setAttribute("genome", genome.getId()); rootGroup.setAttribute("maxZoom", String.valueOf(nZoom)); } }
void write(BufferedByteWriter dos) throws IOException { writeAttributes(dos); }
private Double getValue(WindowFunction wf) { if (!valueCache.containsKey(wf)) { TDFGroup rootGroup = getGroup("/"); String maxString = rootGroup.getAttribute(wf.getDisplayName()); try { valueCache.put(wf, Double.parseDouble(maxString)); } catch (Exception e) { log.info("Warning: value '" + wf.toString() + "' not found in tdf value " + getPath()); valueCache.put(wf, null); } } return valueCache.get(wf); }
private void writeGroups() throws IOException { for (TDFGroup group : groupCache.values()) { long position = bytesWritten; BufferedByteWriter buffer = new BufferedByteWriter(); group.write(buffer); write(buffer.getBytes()); int nBytes = (int) (bytesWritten - position); groupIndex.put(group.getName(), new IndexEntry(position, nBytes)); } }
/** * Called to set initial parameters. It is required that this be called * prior to writing the file */ public void setTrackParameters(TrackType trackType, String trackLine, String[] trackNames, boolean computeWholeGenome) { if (trackLine != null) { log.info(trackLine); } if (outputFile != null && writer == null) { writer = new TDFWriter(outputFile, genome.getId(), trackType, trackLine, trackNames, windowFunctions, compressed); nTracks = trackNames.length; // Convert genome coordinates from bp to kbp if (computeWholeGenome) { int genomeLength = (int) (genome.getNominalLength() / 1000); genomeZoom = new Zoom(Globals.CHR_ALL, 0, genomeLength); } TDFGroup rootGroup = writer.getRootGroup(); rootGroup.setAttribute("genome", genome.getId()); rootGroup.setAttribute("maxZoom", String.valueOf(nZoom)); } }
void write(BufferedByteWriter dos) throws IOException { writeAttributes(dos); }
maxPrecomputedZoom = Integer.parseInt(rootGroup.getAttribute("maxZoom")); } catch (Exception e) { log.error("Error reading attribute 'maxZoom'", e); String dataGenome = rootGroup.getAttribute("genome"); log.error("Unknown genome " + rootGroup.getAttribute("genome")); throw new RuntimeException("Unknown genome " + rootGroup.getAttribute("genome")); String totalCountString = rootGroup.getAttribute("totalCount"); if (totalCountString != null) { totalCount = Integer.parseInt(totalCountString);
writer.getRootGroup().setAttribute("chromosomes", chrString.toString()); writer.getRootGroup().setAttribute(entry.getKey(), entry.getValue()); group.setAttribute(TDFGroup.USE_PERCENTILE_AUTOSCALING, "true"); for (WindowFunction wf : allDataFunctions) { group.setAttribute(wf.getDisplayName(), String.valueOf(allDataStats.getValue(wf)));
public TDFGroup getRootGroup() { if (!groupCache.containsKey("/")) { groupCache.put("/", new TDFGroup("/")); } return groupCache.get("/"); }
public TDFGroup(String name, ByteBuffer byteBuffer) throws IOException { super(name); fill(byteBuffer); }
void fill(ByteBuffer byteBuffer) throws IOException { readAttributes(byteBuffer); } }
private void init() { this.availableFunctions = reader.getWindowFunctions(); if(this.availableFunctions != null) { this.availableFunctions.add(WindowFunction.none); // Always available => raw data } TDFGroup rootGroup = reader.getGroup("/"); try { maxPrecomputedZoom = Integer.parseInt(rootGroup.getAttribute("maxZoom")); } catch (Exception e) { log.error("Error reading attribute 'maxZoom'", e); } try { String dataGenome = rootGroup.getAttribute("genome"); // TODO -- throw exception if data genome != current genome } catch (Exception e) { log.error("Unknown genome " + rootGroup.getAttribute("genome")); throw new RuntimeException("Unknown genome " + rootGroup.getAttribute("genome")); } try { String totalCountString = rootGroup.getAttribute("totalCount"); if (totalCountString != null) { totalCount = Integer.parseInt(totalCountString); } } catch (Exception e) { log.error("Error reading attribute 'totalCount'", e); } intChrMap(); boolean normalizeCounts = PreferencesManager.getPreferences().getAsBoolean(Constants.NORMALIZE_COVERAGE); setNormalize(normalizeCounts); }