示例#1
0
  /**
   * Add a feature to this map. Note that the start of the feature should be a smaller number than
   * the stop of the feature, regardless of the strand. The only case where start is larger than the
   * stop is when the feature runs across the start/stop boundary, for example 6899-10 on a 7000bp
   * plasmid.
   *
   * @param type one of the following: origin_of_replication, promoter, terminator,
   *     selectable_marker, regulatory_sequence, tag, other_gene, reporter_gene,
   *     unique_restriction_site, restriction_site.
   * @param name the name of the feature, such as EcoRI.
   * @param start the start position of the feature. Must be between 1 and the length of the
   *     plasmid.
   * @param stop the end position of the feature. Must be between 1 and the length of the plasmid.
   * @param strand the strand of the feature. Can be Plasmid.FORWARD, Plasmid.REVERSE, or
   *     Plasmid.NO_DIRECTION.
   */
  public void addFeature(String type, String name, int start, int stop, int strand) {
    // add the feature to the plasmid.
    int decoration;
    int label;
    Color color;
    // String slot;

    if (start > size) {
      start = size;
    }
    if (start < 1) {
      start = 1;
    }

    if (stop > size) {
      stop = size;
    }
    if (stop < 1) {
      stop = 1;
    }

    try {
      color = getFeatureColor(type);
      decoration = getFeatureDecoration(type, strand);
      label = getLabelType();
      addItemToLegend(type, strand);
    } catch (NullPointerException e) {
      color = new Color(0, 0, 128); // navy
      if (colorScheme == REGULAR) {
        color = new Color(0, 0, 128); // navy
      } else if (colorScheme == INVERSE) {
        color = new Color(0, 128, 128); // teal
      }
      decoration = DECORATION_STANDARD;
      label = LABEL;
    }

    // create a feature and a feature range
    // then figure out which feature slot to put the feature in.
    Feature feature = new Feature(showShading);
    FeatureRange featureRange = new FeatureRange(feature, start, stop);
    featureRange.setDecoration(decoration);
    featureRange.setColor(color);
    featureRange.setOpacity(opacity);
    featureRange.setShowLabel(label);
    if ((showPositions)
        && ((type.equalsIgnoreCase("restriction_site"))
            || (type.equalsIgnoreCase("unique_restriction_site")))) {
      featureRange.setLabel(name + " " + start);
    } else {
      if (addCategoryInfo) {
        try {
          featureRange.setLabel(name + (String) FEATURE_CATEGORIES.get(type));
        } catch (NullPointerException e) {
          featureRange.setLabel(name);
        }
      } else {
        featureRange.setLabel(name);
      }
    }

    if ((type.equalsIgnoreCase("restriction_site"))
        || (type.equalsIgnoreCase("unique_restriction_site"))) {
      if (restrictionSlot == null) {
        restrictionSlot = new FeatureSlot(DIRECT_STRAND, showShading);
        restrictionSlot.setFeatureThickness(1f);
      }
      feature.setFeatureSlot(restrictionSlot);
    } else if ((strand == NO_DIRECTION) || (strand == FORWARD)) {
      if (forwardSlot0 == null) {
        forwardSlot0 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot0);
      } else if (forwardSlot0.isRoom(feature)) {
        feature.setFeatureSlot(forwardSlot0);
      } else if (forwardSlot1 == null) {
        forwardSlot1 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot1);
      } else if (forwardSlot1.isRoom(feature)) {
        feature.setFeatureSlot(forwardSlot1);
      } else if (forwardSlot2 == null) {
        forwardSlot2 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot2);
      } else if (forwardSlot2.isRoom(feature)) {
        feature.setFeatureSlot(forwardSlot2);
      } else if (forwardSlot3 == null) {
        forwardSlot3 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot3);
      } else if (forwardSlot3.isRoom(feature)) {
        feature.setFeatureSlot(forwardSlot3);
      } else if (forwardSlot4 == null) {
        forwardSlot4 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot4);
      } else if (forwardSlot4.isRoom(feature)) {
        feature.setFeatureSlot(forwardSlot4);
      } else if (forwardSlot5 == null) {
        forwardSlot5 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot5);
      } else if (forwardSlot5.isRoom(feature)) {
        feature.setFeatureSlot(forwardSlot5);
      } else if (forwardSlot6 == null) {
        forwardSlot6 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot6);
      } else if (forwardSlot6.isRoom(feature)) {
        feature.setFeatureSlot(forwardSlot6);
      } else if (forwardSlot7 == null) {
        forwardSlot7 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot7);
      } else {
        feature.setFeatureSlot(forwardSlot7);
      }

    } else if (strand == REVERSE) {
      if (reverseSlot0 == null) {
        reverseSlot0 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot0);
      } else if (reverseSlot0.isRoom(feature)) {
        feature.setFeatureSlot(reverseSlot0);
      } else if (reverseSlot1 == null) {
        reverseSlot1 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot1);
      } else if (reverseSlot1.isRoom(feature)) {
        feature.setFeatureSlot(reverseSlot1);
      } else if (reverseSlot2 == null) {
        reverseSlot2 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot2);
      } else if (reverseSlot2.isRoom(feature)) {
        feature.setFeatureSlot(reverseSlot2);
      } else if (reverseSlot3 == null) {
        reverseSlot3 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot3);
      } else if (reverseSlot3.isRoom(feature)) {
        feature.setFeatureSlot(reverseSlot3);
      } else if (reverseSlot4 == null) {
        reverseSlot4 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot4);
      } else if (reverseSlot4.isRoom(feature)) {
        feature.setFeatureSlot(reverseSlot4);
      } else if (reverseSlot5 == null) {
        reverseSlot5 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot5);
      } else if (reverseSlot5.isRoom(feature)) {
        feature.setFeatureSlot(reverseSlot5);
      } else if (reverseSlot6 == null) {
        reverseSlot6 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot6);
      } else if (reverseSlot6.isRoom(feature)) {
        feature.setFeatureSlot(reverseSlot6);
      } else if (reverseSlot7 == null) {
        reverseSlot7 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot7);
      } else {
        feature.setFeatureSlot(reverseSlot7);
      }
    }
  }