Beispiel #1
0
 private static void writeOutChildren(
     final DataOutputStream out,
     final SymWithProps propsym,
     final int min,
     final int max,
     final int childcount,
     final SeqSymmetry sym,
     final BioSeq seq)
     throws IOException {
   out.write(9);
   if (propsym != null && propsym.getProperty("cds min") != null) {
     out.write(propsym.getProperty("cds min").toString().getBytes());
   } else {
     out.write(Integer.toString(min).getBytes());
   }
   out.write(9);
   if (propsym != null && propsym.getProperty("cds max") != null) {
     out.write(propsym.getProperty("cds max").toString().getBytes());
   } else {
     out.write(Integer.toString(max).getBytes());
   }
   out.write(9);
   out.write(48);
   out.write(9);
   out.write(Integer.toString(childcount).getBytes());
   out.write(9);
   final int[] blockSizes = new int[childcount];
   final int[] blockStarts = new int[childcount];
   for (int i = 0; i < childcount; ++i) {
     final SeqSymmetry csym = sym.getChild(i);
     final SeqSpan cspan = csym.getSpan(seq);
     blockSizes[i] = cspan.getLength();
     blockStarts[i] = cspan.getMin() - min;
   }
   for (int i = 0; i < childcount; ++i) {
     out.write(Integer.toString(blockSizes[i]).getBytes());
     out.write(44);
   }
   out.write(9);
   for (int i = 0; i < childcount; ++i) {
     out.write(Integer.toString(blockStarts[i]).getBytes());
     out.write(44);
   }
 }
Beispiel #2
0
 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);
 }
Beispiel #3
0
 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);
   }
 }