@Test
    public void testParseTrackLine() {
        String trackLine = "track type=bigWig name=\"Track 196\" visibility=2 " +
                "description=\" CD34 - H3K27me3 - hg19 - 18.7 M/20.9 M - 61P7DAAXX.6\" " +
                "maxHeightPixels=70 viewLimits=0:18 windowingFunction=mean autoScale=off " +
                "bigDataUrl=http://www.broadinstitute.org/epigenomics/dataportal/track_00196.portal.bw " +
                "color=255,0,0";

        TrackProperties props = new TrackProperties();
        ParsingUtils.parseTrackLine(trackLine, props);
        assertEquals("Track 196", props.getName());
        assertEquals(Track.DisplayMode.EXPANDED, props.getDisplayMode());
        assertEquals(" CD34 - H3K27me3 - hg19 - 18.7 M/20.9 M - 61P7DAAXX.6", props.getDescription());
        assertEquals(70, props.getHeight());
        assertEquals(0, props.getMinValue(), 1.0e-9);
        assertEquals(18, props.getMaxValue(), 1.0e-9);
        assertEquals(WindowFunction.mean, props.getWindowingFunction());
        assertEquals(false, props.isAutoScale());
        assertEquals(new Color(255, 0, 0), props.getColor());
        assertEquals("http://www.broadinstitute.org/epigenomics/dataportal/track_00196.portal.bw", props.getDataURL());
    }
Beispiel #2
0
  /**
   * Load all features in this file.
   *
   * @param reader
   * @param maxLines
   * @return
   */
  public List<org.broad.tribble.Feature> loadFeatures(BufferedReader reader, int maxLines) {

    List<org.broad.tribble.Feature> features = new ArrayList<org.broad.tribble.Feature>();
    String nextLine = null;

    int nLines = 0;
    try {
      while ((nextLine = reader.readLine()) != null) {
        nextLine = nextLine.trim();
        if (nextLine.length() == 0) continue;
        nLines++;
        if ((maxLines > 0) && (nLines > maxLines)) {
          break;
        }

        try {
          if (nextLine.startsWith("#")) {
            if (nextLine.startsWith("#type")) {
              String[] tokens = Globals.equalPattern.split(nextLine);
              if (tokens.length > 1) {
                try {
                  // TODO: type is not currently used, is there any reason to keep this?
                  TrackType type = TrackType.valueOf(tokens[1]);
                } catch (Exception e) {
                  log.error("Error converting track type: " + tokens[1]);
                }
              }
            } else if (nextLine.startsWith("#track")) {
              TrackProperties tp = new TrackProperties();
              ParsingUtils.parseTrackLine(nextLine, tp);
              setTrackProperties(tp);
              if (tp.isGffTags()) {
                gffTags = true;
              }
            } else if (nextLine.startsWith("#coords")) {
              try {
                String[] tokens = Globals.equalPattern.split(nextLine);
                startBase = Integer.parseInt(tokens[1]);
              } catch (Exception e) {
                log.error("Error parsing coords line: " + nextLine, e);
              }

            } else if (nextLine.startsWith("#gffTags")) {
              gffTags = true;
            }
          } else {
            Feature feature = parseLine(nextLine);
            if (feature != null) {
              features.add(feature);
            }
          }

        } catch (NumberFormatException e) {

          // Expected condition -- for example comments.  don't log as it slows down
          // the parsing and is not useful information.
        }
      }
    } catch (java.io.EOFException e) {

      // This exception is due to a known bug with java zip library.  Not
      // in general a real error, and nothing we can do about it in any
      // event.
      return features;
    } catch (Exception e) {
      if (nextLine != null && nLines != 0) {
        throw new ParserException(e.getMessage(), e, nLines, nextLine);
      } else {
        throw new RuntimeException(e);
      }
    }

    // TODO -- why is this test here?  This will break igvtools processing of expression files
    // if (IGV.hasInstance() || Globals.isTesting()) {
    FeatureDB.addFeatures(features);
    // }
    return features;
  }