Example #1
0
 public void addSequence(final Sequence sequence, final boolean check_for_equal_length) {
   if (check_for_equal_length
       && (getNumberOfSequences() > 0)
       && (getLength() != sequence.getLength())) {
     final String msg =
         "Attempt to a sequence of length "
             + sequence.getLength()
             + " to alignment of length "
             + getLength();
     throw new IllegalArgumentException(msg);
   }
   getSequences().add(sequence);
 }
 @Test
 public void testDeepCopy() {
   Sequence copy = sequence.deepCopy();
   assertNotSame(sequence, copy);
   assertEquals(sequence.getLength(), copy.getLength());
   assertEquals(sequence.getMarkups(), copy.getMarkups());
   assertNotSame(sequence.getMarkups(), copy.getMarkups());
   assertEquals(sequence.getMetadata(), copy.getMetadata());
   assertNotSame(sequence.getMetadata(), copy.getMetadata());
   assertEquals(sequence.getMotifs(), copy.getMotifs());
   assertNotSame(sequence.getMotifs(), copy.getMotifs());
   assertEquals(sequence.getOptions().getBaseUrl(), copy.getOptions().getBaseUrl());
   assertNotSame(sequence.getOptions(), copy.getOptions());
   assertEquals(sequence.getRegions(), copy.getRegions());
   assertNotSame(sequence.getRegions(), copy.getRegions());
 }
 @Test
 public void testDeserializeFromJsonO14640() throws Exception {
   ObjectMapper objectMapper = new ObjectMapper();
   objectMapper.configure(ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
   TypeFactory typeFactory = objectMapper.getTypeFactory();
   InputStream inputStream = getClass().getResourceAsStream("/O14640.json");
   List<Sequence> sequences =
       objectMapper.readValue(
           inputStream, typeFactory.constructCollectionType(List.class, Sequence.class));
   assertNotNull(sequences);
   assertEquals(1, sequences.size());
   Sequence s = sequences.get(0);
   assertEquals(695, s.getLength());
   assertEquals(5, s.getRegions().size());
   assertEquals(0, s.getMarkups().size());
   assertEquals(7, s.getMotifs().size());
   assertEquals("uniprot", s.getMetadata().get("database"));
 }
  public void drawSequence(
      Graphics2D g,
      Sequence seq,
      int start,
      int end,
      int x1,
      int y1,
      double width,
      int height,
      boolean showScores,
      boolean displayBoxes,
      boolean displayText,
      Vector pid,
      int seqnum,
      AlignViewport av,
      Hashtable props,
      int intpid[][]) {
    LinkedHashMap conf = av.getGFFConfig();
    boolean confchanged = false;
    int length = seq.getLength();

    Color currentColor = Color.white;

    g.setColor(Color.black);

    int prevx = -1;
    int prevy = -1;

    int prevpixel = 0;

    if (!(seq instanceof GFF)) {
      return;
    }
    height -= 2;

    GFF gff = (GFF) seq;

    double minscore = gff.getMinScore();
    double maxscore = gff.getMaxScore();

    minscore = (int) (minscore - (maxscore - minscore + 1) * 0.1);
    maxscore = (int) (maxscore + (maxscore - minscore + 1) * 0.1);

    if (gff.getType().equals("Patient_Flow")) {
      minscore = 1600;
    }
    // System.out.println("Min/Max " + minscore + " " + maxscore);
    Vector feat = gff.overlaps(start, end);

    // System.out.println("Got features " + feat.size());

    int prev = -1;
    for (int i = 0; i < feat.size(); i++) {

      SequenceFeature sftmp = (SequenceFeature) feat.elementAt(i);

      int coord = sftmp.getStart();

      if (coord >= minscore) {
        Color c = Color.black;

        String key = sftmp.getType();
        if (key.indexOf("::") > 0) {
          key = key.substring(0, key.indexOf("::"));
          sftmp.setType(key);
        }
        if (conf != null && conf.containsKey(sftmp.getType())) {
          c = (Color) (conf.get(sftmp.getType()));
          g.setColor(c);
        } else {

          // c = new
          // Color((int)(Math.random()*200+50),(int)(Math.random()*200+50),(int)(Math.random()*200+50));
          c = Color.black;
          conf.put(sftmp.getType(), c);
          g.setColor(c);
          confchanged = true;
        }

        Vector tmpf = new Vector();

        if (sftmp.getFeatures() != null) {
          tmpf = sftmp.getFeatures();
        } else {
          tmpf.addElement(sftmp);
        }

        int tmpheight = height;
        double score = sftmp.getScore();

        tmpheight = (int) ((score - minscore + 1) * (height) / (maxscore - minscore + 1));

        int tmpx = x1 + (int) ((coord - start) * width) + 1;
        int tmpy = y1 + height - tmpheight + 1;

        if (prevx == -1) {
          prevx = tmpx;
          prevy = tmpy;
        }

        if (tmpx - prevx <= 2) {
          g.drawLine(prevx, prevy, tmpx, tmpy);
        }

        prevx = tmpx;
        prevy = tmpy;
      }
      i++;
    }
  }