private void parse( final DataInputStream dis, final GenometryModel gmodel, final AnnotatedSeqGroup seq_group, final String default_type) throws IOException { String type = default_type; String bedType = null; boolean use_item_rgb = false; final Thread thread = Thread.currentThread(); final BufferedReader reader = new BufferedReader(new InputStreamReader(dis)); String line; while ((line = reader.readLine()) != null && !thread.isInterrupted()) { if (!line.startsWith("#")) { if (line.length() == 0) { continue; } if (line.startsWith("track")) { this.track_line_parser.parseTrackLine(line); TrackLineParser.createTrackStyle( this.track_line_parser.getCurrentTrackHash(), default_type, "bed"); type = this.track_line_parser.getCurrentTrackHash().get("name"); final String item_rgb_string = this.track_line_parser.getCurrentTrackHash().get("itemrgb"); use_item_rgb = "on".equalsIgnoreCase(item_rgb_string); bedType = this.track_line_parser.getCurrentTrackHash().get("type"); } else { if (line.startsWith("browser")) { continue; } this.parseLine(line, seq_group, gmodel, type, use_item_rgb, bedType); } } } }
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); } }