示例#1
0
  private void processResource(Session session, Element element, HashMap additionalInformation) {

    String nodeName = element.getNodeName();
    boolean oldSession = nodeName.equals(SessionElement.DATA_FILE.getText());

    String label = getAttribute(element, SessionAttribute.LABEL.getText());
    String name = getAttribute(element, SessionAttribute.NAME.getText());
    String sampleId = getAttribute(element, SessionAttribute.SAMPLE_ID.getText());
    String description = getAttribute(element, SessionAttribute.DESCRIPTION.getText());
    String type = getAttribute(element, SessionAttribute.TYPE.getText());
    String coverage = getAttribute(element, SessionAttribute.COVERAGE.getText());
    String trackLine = getAttribute(element, SessionAttribute.TRACK_LINE.getText());
    String colorString = getAttribute(element, SessionAttribute.COLOR.getText());

    String relPathValue = getAttribute(element, SessionAttribute.RELATIVE_PATH.getText());
    boolean isRelativePath = ((relPathValue != null) && relPathValue.equalsIgnoreCase("true"));
    String serverURL = getAttribute(element, SessionAttribute.SERVER_URL.getText());

    // Older sessions used the "name" attribute for the path.
    String path = getAttribute(element, SessionAttribute.PATH.getText());

    if (oldSession && name != null) {
      path = name;
      int idx = name.lastIndexOf("/");
      if (idx > 0 && idx + 1 < name.length()) {
        name = name.substring(idx + 1);
      }
    }

    ResourceLocator resourceLocator;
    if (isRelativePath) {
      final String sessionPath = session.getPath();

      String absolutePath;
      if (sessionPath == null) {
        log.error("Null session path -- this is not expected");
        MessageUtils.showMessage("Unexpected error loading session: null session path");
        return;
      }
      absolutePath = FileUtils.getAbsolutePath(path, sessionPath);
      fullToRelPathMap.put(absolutePath, path);
      resourceLocator = new ResourceLocator(serverURL, absolutePath);

      // If the resourceLocator is relative, we assume coverage is as well
      if (coverage != null) {
        String absoluteCoveragePath = FileUtils.getAbsolutePath(coverage, sessionPath);
        resourceLocator.setCoverage(absoluteCoveragePath);
      }
    } else {
      resourceLocator = new ResourceLocator(serverURL, path);
      resourceLocator.setCoverage(coverage);
    }

    String url = getAttribute(element, SessionAttribute.URL.getText());
    if (url == null) {
      url = getAttribute(element, SessionAttribute.FEATURE_URL.getText());
    }
    resourceLocator.setUrl(url);

    String infolink = getAttribute(element, SessionAttribute.HYPERLINK.getText());
    if (infolink == null) {
      infolink = getAttribute(element, SessionAttribute.INFOLINK.getText());
    }
    resourceLocator.setInfolink(infolink);

    // Label is deprecated in favor of name.
    if (name != null) {
      resourceLocator.setName(name);
    } else {
      resourceLocator.setName(label);
    }

    resourceLocator.setSampleId(sampleId);

    resourceLocator.setDescription(description);
    // This test added to get around earlier bug in the writer
    if (type != null && !type.equals("local")) {
      resourceLocator.setType(type);
    }
    resourceLocator.setCoverage(coverage);
    resourceLocator.setTrackLine(trackLine);

    if (colorString != null) {
      try {
        Color c = ColorUtilities.stringToColor(colorString);
        resourceLocator.setColor(c);
      } catch (Exception e) {
        log.error("Error setting color: ", e);
      }
    }

    dataFiles.add(resourceLocator);

    NodeList elements = element.getChildNodes();
    process(session, elements, additionalInformation);
  }
示例#2
0
  private void processRootNode(Session session, Node node, HashMap additionalInformation) {

    if ((node == null) || (session == null)) {
      MessageUtils.showMessage("Invalid session file: root node not found");
      return;
    }

    String nodeName = node.getNodeName();
    if (!(nodeName.equalsIgnoreCase(SessionElement.GLOBAL.getText())
        || nodeName.equalsIgnoreCase(SessionElement.SESSION.getText()))) {
      MessageUtils.showMessage(
          "Session files must begin with a \"Global\" or \"Session\" element.  Found: " + nodeName);
    }
    process(session, node, additionalInformation);

    Element element = (Element) node;

    // Load the genome, which can be an ID, or a path or URL to a .genome or indexed fasta file.
    String genomeId = getAttribute(element, SessionAttribute.GENOME.getText());
    if (genomeId != null && genomeId.length() > 0) {
      if (genomeId.equals(GenomeManager.getInstance().getGenomeId())) {
        // We don't have to reload the genome, but the gene track for the current genome should be
        // restored.
        Genome genome = GenomeManager.getInstance().getCurrentGenome();
        IGV.getInstance().setGenomeTracks(genome.getGeneTrack());
      } else {
        // Selecting a genome will actually "reset" the session so we have to
        // save the path and restore it.
        String sessionPath = session.getPath();
        if (IGV.getInstance().getGenomeIds().contains(genomeId)) {
          IGV.getInstance().selectGenomeFromList(genomeId);
        } else {
          String genomePath = genomeId;
          if (!ParsingUtils.pathExists(genomePath)) {
            genomePath = FileUtils.getAbsolutePath(genomeId, session.getPath());
          }
          if (ParsingUtils.pathExists(genomePath)) {
            try {
              IGV.getInstance().loadGenome(genomePath, null);
            } catch (IOException e) {
              throw new RuntimeException("Error loading genome: " + genomeId);
            }
          } else {
            MessageUtils.showMessage("Warning: Could not locate genome: " + genomeId);
          }
        }
        session.setPath(sessionPath);
      }
    }

    session.setLocus(getAttribute(element, SessionAttribute.LOCUS.getText()));
    session.setGroupTracksBy(getAttribute(element, SessionAttribute.GROUP_TRACKS_BY.getText()));

    String removeEmptyTracks = getAttribute(element, "removeEmptyTracks");
    if (removeEmptyTracks != null) {
      try {
        Boolean b = Boolean.parseBoolean(removeEmptyTracks);
        session.setRemoveEmptyPanels(b);
      } catch (Exception e) {
        log.error("Error parsing removeEmptyTracks string: " + removeEmptyTracks, e);
      }
    }

    String versionString = getAttribute(element, SessionAttribute.VERSION.getText());
    try {
      version = Integer.parseInt(versionString);
    } catch (NumberFormatException e) {
      log.error("Non integer version number in session file: " + versionString);
    }
    session.setVersion(version);

    NodeList elements = element.getChildNodes();
    process(session, elements, additionalInformation);

    // ReferenceFrame.getInstance().invalidateLocationScale();
  }