private void annotationParsed(final SeqSymmetry bedline_sym) { final BioSeq seq = bedline_sym.getSpan(0).getBioSeq(); if (this.create_container_annot) { String type = this.track_line_parser.getCurrentTrackHash().get("name"); if (type == null) { type = this.default_type; } Map<String, SeqSymmetry> type2csym = this.seq2types.get(seq); if (type2csym == null) { type2csym = new HashMap<String, SeqSymmetry>(); this.seq2types.put(seq, type2csym); } SimpleSymWithProps parent_sym = (SimpleSymWithProps) type2csym.get(type); if (parent_sym == null) { parent_sym = new SimpleSymWithProps(); parent_sym.addSpan(new SimpleSeqSpan(0, seq.getLength(), seq)); parent_sym.setProperty("method", type); parent_sym.setProperty("preferred_formats", BedParser.pref_list); parent_sym.setProperty("container sym", Boolean.TRUE); seq.addAnnotation(parent_sym); type2csym.put(type, parent_sym); } parent_sym.addChild(bedline_sym); } else { seq.addAnnotation(bedline_sym); } }
private static void writeOutFile( final DataOutputStream out, final BioSeq seq, final SeqSpan span, final SeqSymmetry sym, final SymWithProps propsym) throws IOException { out.write(seq.getID().getBytes()); out.write(9); final int min = span.getMin(); final int max = span.getMax(); out.write(Integer.toString(min).getBytes()); out.write(9); out.write(Integer.toString(max).getBytes()); final int childcount = sym.getChildCount(); if (!span.isForward() || childcount > 0 || propsym != null) { out.write(9); if (propsym != null) { if (propsym.getProperty("name") != null) { out.write(((String) propsym.getProperty("name")).getBytes()); } else if (propsym.getProperty("id") != null) { out.write(((String) propsym.getProperty("id")).getBytes()); } } out.write(9); if (propsym != null && propsym.getProperty("score") != null) { out.write(propsym.getProperty("score").toString().getBytes()); } else if (sym instanceof Scored) { out.write(Float.toString(((Scored) sym).getScore()).getBytes()); } else { out.write(48); } out.write(9); if (span.isForward()) { out.write(43); } else { out.write(45); } if (childcount > 0) { writeOutChildren(out, propsym, min, max, childcount, sym, seq); } } out.write(10); }
private void parseLine( final String line, final AnnotatedSeqGroup seq_group, final GenometryModel gmodel, final String type, final boolean use_item_rgb, final String bedType) throws NumberFormatException, IOException { final boolean bedDetail = "bedDetail".equals(bedType); String detailId = null; String detailDescription = null; String[] fields = BedParser.tab_regex.split(line); int field_count = fields.length; if (field_count == 1) { fields = BedParser.line_regex.split(line); } if (bedDetail) { detailId = fields[field_count - 2]; detailDescription = fields[field_count - 1]; field_count -= 2; } if (field_count < 3) { return; } String seq_name = null; String annot_name = null; String itemRgb = ""; int thick_min = Integer.MIN_VALUE; int thick_max = Integer.MIN_VALUE; float score = Float.NEGATIVE_INFINITY; int[] blockSizes = null; int[] blockStarts = null; int[] blockMins = null; int[] blockMaxs = null; final boolean includes_bin_field = field_count > 6 && (fields[6].startsWith("+") || fields[6].startsWith("-") || fields[6].startsWith(".")); int findex = 0; if (includes_bin_field) { ++findex; } seq_name = fields[findex++]; BioSeq seq = seq_group.getSeq(seq_name); if (seq == null && seq_name.indexOf(59) > -1) { String seqid = seq_name.substring(0, seq_name.indexOf(59)); String version = seq_name.substring(seq_name.indexOf(59) + 1); if (gmodel.getSeqGroup(version) == seq_group || seq_group.getID().equals(version)) { seq = seq_group.getSeq(seqid); if (seq != null) { seq_name = seqid; } } else if (gmodel.getSeqGroup(seqid) == seq_group || seq_group.getID().equals(seqid)) { final String temp = seqid; seqid = version; version = temp; seq = seq_group.getSeq(seqid); if (seq != null) { seq_name = seqid; } } } if (seq == null) { seq = seq_group.addSeq(seq_name, 0); } final int beg = Integer.parseInt(fields[findex++]); final int end = Integer.parseInt(fields[findex++]); if (field_count >= 4) { annot_name = parseName(fields[findex++]); if (annot_name == null || annot_name.length() == 0) { annot_name = seq_group.getUniqueID(); } } if (field_count >= 5) { score = parseScore(fields[findex++]); } boolean forward; if (field_count >= 6) { forward = !fields[findex++].equals("-"); } else { forward = (beg <= end); } final int min = Math.min(beg, end); final int max = Math.max(beg, end); if (field_count >= 8) { thick_min = Integer.parseInt(fields[findex++]); thick_max = Integer.parseInt(fields[findex++]); } if (field_count >= 9) { itemRgb = fields[findex++]; } else { ++findex; } if (field_count >= 12) { final int blockCount = Integer.parseInt(fields[findex++]); blockSizes = parseIntArray(fields[findex++]); if (blockCount != blockSizes.length) { System.out.println( "WARNING: block count does not agree with block sizes. Ignoring " + annot_name + " on " + seq_name); return; } blockStarts = parseIntArray(fields[findex++]); if (blockCount != blockStarts.length) { System.out.println( "WARNING: block size does not agree with block starts. Ignoring " + annot_name + " on " + seq_name); return; } blockMins = makeBlockMins(min, blockStarts); blockMaxs = makeBlockMaxs(blockSizes, blockMins); } else { blockMins = new int[] {min}; blockMaxs = new int[] {max}; } if (max > seq.getLength()) { seq.setLength(max); } SymWithProps bedline_sym = null; bedline_sym = (bedDetail ? new UcscBedDetailSym( type, seq, min, max, annot_name, score, forward, thick_min, thick_max, blockMins, blockMaxs, detailId, detailDescription) : new UcscBedSym( type, seq, min, max, annot_name, score, forward, thick_min, thick_max, blockMins, blockMaxs)); if (use_item_rgb && itemRgb != null) { Color c = null; try { c = TrackLineParser.reformatColor(itemRgb); } catch (Exception e) { throw new IOException("Could not parse a color from String '" + itemRgb + "'"); } if (c != null) { bedline_sym.setProperty("itemrgb", c); } } this.symlist.add(bedline_sym); if (this.annotate_seq) { this.annotationParsed(bedline_sym); } if (annot_name != null) { seq_group.addToIndex(annot_name, bedline_sym); } }
@Override public List<? extends SeqSymmetry> getRegion(final SeqSpan overlapSpan) throws Exception { this.init(); final BioSeq seq = overlapSpan.getBioSeq(); if (!seq.equals(this.saveSeq) || this.saveSym == null) { final Iterator<Map<Integer, List<List<Long>>>> binIter = this.getBinIter(seq.toString()); if (binIter == null) { this.saveSym = new GraphSym(new int[0], new int[0], new float[0], this.featureName, seq); } else { final int[] xList = new int[32768]; for (int i = 0; i < 32768; ++i) { xList[i] = i * 16384; } final int[] wList = new int[32768]; Arrays.fill(wList, 16384); final float[] yList = new float[32768]; Arrays.fill(yList, 0.0f); float largestY = Float.MIN_VALUE; int indexLargest = -1; while (binIter.hasNext()) { final Map<Integer, List<List<Long>>> binWrapper = binIter.next(); final int binNo = binWrapper.keySet().iterator().next(); final int[] region = getRegion(binNo); int yValue = 0; for (final List<Long> chunkWrapper : binWrapper.get(binNo)) { if (chunkWrapper != null) { yValue += (int) (getUncompressedLength(chunkWrapper.get(0), chunkWrapper.get(1)) * 16384L / (region[1] - region[0])); } } if (1 + region[1] - region[0] == 16384 && yValue > 0.0f && (yValue > largestY || indexLargest == -1)) { indexLargest = region[0] / 16384; largestY = yValue; } for (int j = region[0] / 16384; j < (region[1] + 1) / 16384; ++j) { final float[] array = yList; final int n = j; array[n] += yValue; } } indexLargest = -1; if (indexLargest != -1) { try { final float realAvg = this.getRealAvg( new SimpleSeqSpan(indexLargest * 16384, (indexLargest + 1) * 16384, seq)); if (realAvg > 0.0f) { final float ratio = realAvg / yList[indexLargest]; for (int k = 0; k < yList.length; ++k) { final float[] array2 = yList; final int n2 = k; array2[n2] *= ratio; } } } catch (Exception x) { Logger.getLogger(this.getClass().getName()) .log(Level.SEVERE, "fail loading BAM segment " + this.uri, x); } } this.saveSym = new GraphSym(xList, wList, yList, this.featureName, seq); } this.saveSeq = seq; } final List<SeqSymmetry> symList = new ArrayList<SeqSymmetry>(); symList.add(this.saveSym); return symList; }