예제 #1
0
  /**
   * Note: This is an exact copy of the method in ExpressionFileParser. Refactor to merge these two
   * parsers, or share a common base class.
   *
   * @param comment
   * @param dataset
   */
  private void parseDirective(String comment, IGVDataset dataset) {

    String tmp = comment.substring(1, comment.length());
    if (tmp.startsWith("track")) {
      ParsingUtils.parseTrackLine(tmp, dataset.getTrackProperties());

    } else if (tmp.startsWith("columns")) {
      parseColumnLine(tmp);
    } else {
      String[] tokens = tmp.split("=");
      if (tokens.length != 2) {
        return;
      }

      String key = tokens[0].trim().toLowerCase();
      if (key.equals("name")) {
        dataset.setName(tokens[1].trim());
      } else if (key.equals("type")) {

        try {
          dataset.setTrackType(TrackType.valueOf(tokens[1].trim().toUpperCase()));
        } catch (Exception exception) {

          // Ignore
        }
      } else if (key.equals("coords")) {

        startBase = Integer.parseInt(tokens[1].trim());
      }
    }
  }
예제 #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;
  }