Esempio n. 1
0
  /**
   * @param inputStream
   * @param session
   * @param sessionName @return
   * @throws RuntimeException
   */
  public void loadSession(InputStream inputStream, Session session, String sessionName) {

    log.debug("Load session");

    Document document = null;
    try {
      document = Utilities.createDOMDocumentFromXmlStream(inputStream);
    } catch (Exception e) {
      log.error("Load session error", e);
      throw new RuntimeException(e);
    }

    NodeList tracks = document.getElementsByTagName("Track");
    hasTrackElments = tracks.getLength() > 0;

    HashMap additionalInformation = new HashMap();
    additionalInformation.put(INPUT_FILE_KEY, sessionName);

    NodeList nodes = document.getElementsByTagName(SessionElement.GLOBAL.getText());
    if (nodes == null || nodes.getLength() == 0) {
      nodes = document.getElementsByTagName(SessionElement.SESSION.getText());
    }

    processRootNode(session, nodes.item(0), additionalInformation);

    // Add tracks not explicitly allocated to panels.  It is legal to define sessions with the
    // Resources
    // section only (no Panel or Track elements).
    addLeftoverTracks(trackDictionary.values());

    if (session.getGroupTracksBy() != null && session.getGroupTracksBy().length() > 0) {
      igv.setGroupByAttribute(session.getGroupTracksBy());
    }

    if (session.isRemoveEmptyPanels()) {
      igv.getMainPanel().removeEmptyDataPanels();
    }

    igv.resetOverlayTracks();
  }
Esempio n. 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();
  }