Ejemplo n.º 1
0
  private void autoscaleGroup(List<Track> trackList) {

    List<ReferenceFrame> frames =
        FrameManager.isGeneListMode()
            ? FrameManager.getFrames()
            : Arrays.asList(FrameManager.getDefaultFrame());

    List<Range> inViewRanges = new ArrayList<Range>();

    synchronized (trackList) {
      for (Track track : trackList) {
        if (track instanceof ScalableTrack) {
          for (ReferenceFrame frame : frames) {
            Range range = ((ScalableTrack) track).getInViewRange(frame);
            if (range != null) {
              inViewRanges.add(range);
            }
          }
        }
      }

      if (inViewRanges.size() > 0) {

        Range inter = computeScale(inViewRanges);

        for (Track track : trackList) {

          DataRange dr = track.getDataRange();
          float min = Math.min(0, inter.min);
          float base = Math.max(min, dr.getBaseline());
          float max = inter.max;
          // Pathological case where min ~= max  (no data in view)
          if (max - min <= (2 * Float.MIN_VALUE)) {
            max = min + 1;
          }

          DataRange newDR = new DataRange(min, base, max, dr.isDrawBaseline());
          newDR.setType(dr.getType());
          track.setDataRange(newDR);
        }
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Process a track element. This should return a single track, but could return multiple tracks
   * since the uniqueness of the track id is not enforced.
   *
   * @param session
   * @param element
   * @param additionalInformation
   * @return
   */
  private List<Track> processTrack(
      Session session, Element element, HashMap additionalInformation) {

    String id = getAttribute(element, SessionAttribute.ID.getText());

    // TODo -- put in utility method, extacts attributes from element **Definitely need to do this
    HashMap<String, String> tAttributes = new HashMap();
    HashMap<String, String> drAttributes = null;

    NamedNodeMap tNodeMap = element.getAttributes();
    for (int i = 0; i < tNodeMap.getLength(); i++) {
      Node node = tNodeMap.item(i);
      String value = node.getNodeValue();
      if (value != null && value.length() > 0) {
        tAttributes.put(node.getNodeName(), value);
      }
    }

    if (element.hasChildNodes()) {
      drAttributes = new HashMap();
      Node childNode = element.getFirstChild();
      Node sibNode = childNode.getNextSibling();
      String sibName = sibNode.getNodeName();
      if (sibName.equals(SessionElement.DATA_RANGE.getText())) {
        NamedNodeMap drNodeMap = sibNode.getAttributes();
        for (int i = 0; i < drNodeMap.getLength(); i++) {
          Node node = drNodeMap.item(i);
          String value = node.getNodeValue();
          if (value != null && value.length() > 0) {
            drAttributes.put(node.getNodeName(), value);
          }
        }
      }
    }

    // Get matching tracks.
    List<Track> matchedTracks = trackDictionary.get(id);

    if (matchedTracks == null) {
      log.info("Warning.  No tracks were found with id: " + id + " in session file");
    } else {
      for (final Track track : matchedTracks) {

        // Special case for sequence & gene tracks,  they need to be removed before being placed.
        if (version >= 4 && track == geneTrack || track == seqTrack) {
          igv.removeTracks(Arrays.asList(track));
        }

        track.restorePersistentState(tAttributes);
        if (drAttributes != null) {
          DataRange dr = track.getDataRange();
          dr.restorePersistentState(drAttributes);
          track.setDataRange(dr);
        }
      }
      trackDictionary.remove(id);
    }

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

    return matchedTracks;
  }