/* Establish the currentRange of bases covered by the
    currentFeature of this renderer
 */
 public double[] establishRange(SeqFeatureI sf, int pos, int tier, boolean use_set) {
   double range[];
   if (sf == null || (!use_set && (sf.canHaveChildren()))) {
     range = baseEditor.getRangeAtPosition(tier, pos);
   } else {
     range = new double[2];
     range[0] = (double) baseEditor.basePairToPos(sf.getLow());
     range[1] = (double) baseEditor.basePairToPos(sf.getHigh());
   }
   return range;
 }
예제 #2
0
  private String getDisplayName(SeqFeatureI sf) {
    String display_name = "";

    // Annot
    if (sf instanceof AnnotatedFeatureI) {
      display_name = sf.getName();
    }

    // Not Annot
    else {
      // FeatPair
      FeatureSetI fset =
          (sf.canHaveChildren() ? (FeatureSetI) sf : (FeatureSetI) sf.getRefFeature());
      // cant do as seqfeature as getHitSequence() is in FeatureSet and not
      // SeqFeature and furthermore cant do a getHitFeature().getRefSequence()
      // as FeatureSet has no hit feature yet it has hit sequence
      // SeqFeatureI fset = sf.canHaveChildren() ? sf : sf.getRefFeature();
      SequenceI seq = (fset != null ? fset.getHitSequence() : null);
      SeqFeatureI featPair = null; // FeaturePairI fp;

      if (fset != null && fset.size() > 0 && (fset.getFeatureAt(0).hasHitFeature())) {
        featPair = fset.getFeatureAt(0);
      } else if (sf.hasHitFeature()) {
        featPair = sf; // fp = (FeaturePairI) sf;
      } // else {//fp = null; } // not necasary - already null

      if (seq == null && featPair != null) seq = featPair.getHitFeature().getRefSequence();
      if (seq == null) seq = sf.getFeatureSequence();

      if (seq != null) {
        display_name = seq.getName() != null ? seq.getName() : "";
      } else if (featPair != null) {
        SeqFeatureI hit = featPair.getHitFeature();
        display_name = hit.getName() != null ? hit.getName() : "";
      }
      /* NOT FeaturePair
         this will only be reached if not an annot, not a FS w fps
         and not a FeaturePair (or if fp hit name is "")
         in otherwords a seqfeature result
         added getName in for chado gene predics which are leaf seq feats
      */
      // shouldnt we check getName != null before using biotype??
      else display_name = getBioTypeForDisplay(sf);
    }
    return display_name;
  }
  /**
   * Gets all the annotations in a particular feature set
   *
   * @param featureSet
   * @return
   */
  public static Set<SeqFeatureI> getAnnotations(SeqFeatureI featureSet) {
    HashSet<SeqFeatureI> result = new HashSet<SeqFeatureI>();

    if (featureSet.isTranscript()) {

      if (featureSet.isContainedByRefSeq())
        // only add if its fully in range
        result.add(featureSet);

    } else if (featureSet.isAnnotTop() && !featureSet.hasKids()) {
      // only add if its fully in range
      if (featureSet.isContainedByRefSeq()) result.add(featureSet);

    } else {
      for (int i = 0, size = featureSet.getFeatures().size(); i < size; i++) {
        SeqFeatureI feature = featureSet.getFeatureAt(i);
        if (feature.canHaveChildren()) {
          result.addAll(getAnnotations(feature));
        }
      }
    }

    return result;
  }
  /**
   * Get component to be rendered, if pos outside of current range getFeatureAtPosition and reset
   * currentRange, if feature is non null and not an instance of FeatureSetI then its an exon, and
   * set isExon flag
   */
  public Component getBaseComponent(int position, TierI tier, Orientation o) {

    transcript = null;

    int bp = tier.getBasePair(position);
    int oldPos = position;

    // We need to change the position if dealing with aa view
    if (tier.getType() == SequenceType.AA) {
      int offset = getOffset(position, tier);
      bp += offset * tier.getStrand().toInt();
      position = tier.getPosition(bp);
    }

    char base = tier.charAt(position);

    if (tier.featureExsitsAt(position, TierI.Level.BOTTOM)) {
      this.state = State.EXON;
      SeqFeatureI feature = tier.featureAt(position, TierI.Level.BOTTOM);
      Transcript parentClone = null;
      Transcript otherParentClone = null;

      if (tier.getType() == SequenceType.AA
          && feature.getParent() != null
          && feature.getParent().isTranscript()) {

        FeatureSetI parent = feature.getParent();
        int index = parent.getFeatureIndex(feature);

        int start = parent.getEnd();
        // the transcript start might be different than the lowest exon start
        // when in the middle of an edit
        if (parent.canHaveChildren()) {
          for (int i = 0; i < parent.size(); i++) {
            SeqFeatureI sf = parent.getFeatureAt(i);
            if ((Strand.valueOf(sf.getStrand()) == Strand.FORWARD && sf.getStart() < start)
                || (Strand.valueOf(sf.getStrand()) == Strand.REVERSE && sf.getStart() > start))
              start = sf.getStart();
          }
        }

        int translationStart = parent.getTranslationStart();
        int translationEnd = parent.getTranslationEnd();
        int translationPos = parent.getFeaturePosition(translationStart);
        int oldstart = start;
        start += ((translationPos - 1) % 3) * parent.getStrand();

        // Tring to avoid all the recalculation...
        if (feature.getParent() == currentParent
            && start == currentStart
            && featureStart == feature.getStart()
            && featureEnd == feature.getEnd()) {
          parentClone = currentParentClone;
          otherParentClone = currentParentClone2;
        } else {
          // need to get a full translation so that we can get the amino acids
          // in the UTR region
          parentClone = (Transcript) feature.getParent().clone();
          otherParentClone = (Transcript) feature.getParent().clone();

          if (!parentClone.setTranslationStart(start)) {
            start = oldstart;
            TranslationI cds = otherParentClone.getTranslation();
            cds.calcTranslationStartForLongestPeptide();
            translationStart = otherParentClone.getTranslationStart();
            translationPos = otherParentClone.getFeaturePosition(translationStart);
            start += ((translationPos - 1) % 3) * otherParentClone.getStrand();
            parentClone.setTranslationStart(start);
          }

          parentClone.setTranslationEnd(parentClone.getEnd());
          parentClone.setPeptideSequence(null);

          String translation = parentClone.translate();
          SequenceI sequence = parentClone.getPeptideSequence();

          currentParent = (Transcript) feature.getParent();
          currentParentClone = parentClone;
          currentParentClone2 = otherParentClone;
          currentStart = start;
          featureStart = feature.getStart();
          featureEnd = feature.getEnd();

          if (otherParentClone.getFeatureContaining(translationEnd) == null) {
            TranslationI cds = otherParentClone.getTranslation();
            cds.setTranslationEndFromStart();
          }
        }

        SeqFeatureI sf = parentClone.getFeatureAt(index);

        if (bp >= sf.getLow() && bp <= sf.getHigh()) {
          base = getPeptide(bp, sf);
        } else {
          base = '\0';
        }

        if (otherParentClone != null) {
          feature = otherParentClone.getFeatureAt(index);
        }

      } else if (tier.getType() == SequenceType.AA
          && feature.getParent() != null
          && !feature.getParent().isTranscript()) {
        base = '\0';
      }

      if (isUTR(bp, feature, tier)) {
        this.state = State.UTR;
      }

      if (isTranslationStart(bp, feature)) {
        this.state = State.TRANSLATION_START;
      }

      if (isTranslationEnd(bp, feature)) {
        this.state = State.TRANSLATION_END;
      }

      // Can have an error or a shift on a position but not both
      if (isSequencingErrorPosition(bp, feature, tier.getType())) {
        this.state = State.ERROR;
        // set base to the base of the new sequence?
      }

      if (isShiftPosition(bp, feature, tier.getType())) {
        this.state = State.SHIFT;
      }

    } else if (tier.featureExsitsAt(position, TierI.Level.TOP)) {
      SeqFeatureI feature = tier.featureAt(position, Level.TOP);
      this.state = State.INTRON;
      if (tier.getType() == SequenceType.AA) {
        base = '\0';
      }

      int start = feature.getEnd();
      int end = feature.getStart();

      if (feature.canHaveChildren()) {
        for (int i = 0; i < feature.size(); i++) {
          SeqFeatureI sf = feature.getFeatureAt(i);
          if ((Strand.valueOf(sf.getStrand()) == Strand.FORWARD && sf.getStart() < start)
              || (Strand.valueOf(sf.getStrand()) == Strand.REVERSE && sf.getStart() > start))
            start = sf.getStart();

          if ((Strand.valueOf(sf.getStrand()) == Strand.FORWARD && sf.getEnd() > end)
              || (Strand.valueOf(sf.getStrand()) == Strand.REVERSE && sf.getEnd() < end))
            end = sf.getEnd();
        }
      }

      if (bp <= Math.min(start, end) || bp >= Math.max(start, end)) {
        this.state = State.OUT;
        base = '\0';
      }
    } else {
      this.state = State.OUT;
      base = '\0';
    }

    if (!(state == State.SHIFT || state == State.ERROR)
        && getRegionLow() <= position
        && position <= getRegionHigh()) {
      this.state = State.SELECTED;
      base = tier.charAt(oldPos);
    }

    init(base);
    return this;
  }