Esempio n. 1
0
  // This is VERY slow.
  // ABout 50% from DNATools.dnaToke
  // About 30% from StringBuffer.toString
  // About 20% from StringBuffer.<init>
  protected static String keyFromSyms(Symbol[] syms) {
    StringBuffer buf = new StringBuffer(syms.length);
    try {
      for (int i = 0; i < syms.length; i++) {
        buf.append(DNATools.dnaToken(syms[i]));
      }
    } catch (Exception e) {
      System.err.println("NmerCounter called with non-DNA symbol");
      System.exit(1);
    }

    return buf.toString();
  }
Esempio n. 2
0
  @Override
  protected void processResults() throws ServiceException {
    String seqs[] = getOutputs().get("sequences").split(">");
    String seq1 = seqs[0].substring(seqs[0].indexOf('\n')).replace("\n", "").trim();
    String seq2 = seqs[1].substring(seqs[1].indexOf('\n')).replace("\n", "").trim();

    try {
      if (isAa()) {
        setAlignedSequence1(
            ProteinTools.createGappedProteinSequence(seq1, getSequence1().getName()));
        setAlignedSequence2(
            ProteinTools.createGappedProteinSequence(seq2, getSequence2().getName()));
      } else {
        setAlignedSequence1(DNATools.createGappedDNASequence(seq1, getSequence1().getName()));
        setAlignedSequence2(DNATools.createGappedDNASequence(seq2, getSequence2().getName()));
      }
    } catch (IllegalSymbolException e) {
      e.printStackTrace();
      throw new AlignServiceException(getService(), getUrl(), e);
    }

    setScore(Double.parseDouble(getOutputs().get("score")));
  }
 /**
  * Test constructor to create a non-empty database.
  *
  * @throws BioException if iterator fails.
  */
 public void testNonEmptyConstructor() throws BioException {
   SimpleSymbolPropertyTableDB dbInit = new SimpleSymbolPropertyTableDB();
   SymbolPropertyTable t1 = new SimpleSymbolPropertyTable(ProteinTools.getAlphabet(), "protein");
   SymbolPropertyTable t2 = new SimpleSymbolPropertyTable(DNATools.getDNA(), "dna");
   dbInit.addTable(t1);
   dbInit.addTable(t2);
   SymbolPropertyTableDB db = new SimpleSymbolPropertyTableDB(dbInit.tableIterator());
   assertEquals("Database has wrong number of tables.", 2, db.numTables());
   SymbolPropertyTableIterator iterator = db.tableIterator();
   ArrayList tables = new ArrayList(2);
   while (iterator.hasNext()) {
     tables.add(iterator.nextTable());
   }
   assertEquals("Iterator returned wrong number of tables.", 2, tables.size());
   assertEquals("Iterator returned wrong table.", t1, tables.get(0));
   assertEquals("Iterator returned wrong table.", t2, tables.get(1));
 }
 /**
  * Test for {@link SimpleSymbolPropertyTableDB#addTable(SymbolPropertyTable)}.
  *
  * @throws IllegalIDException if {@link SymbolPropertyTableDB#table(String)} fails.
  */
 public void testAddTable() throws IllegalIDException {
   SimpleSymbolPropertyTableDB db = new SimpleSymbolPropertyTableDB();
   SymbolPropertyTable t1 = new SimpleSymbolPropertyTable(ProteinTools.getAlphabet(), "protein");
   SymbolPropertyTable t2 = new SimpleSymbolPropertyTable(DNATools.getDNA(), "dna");
   db.addTable(t1);
   assertEquals("Database has wrong number of tables.", 1, db.numTables());
   db.addTable(t2);
   assertEquals("Database has wrong number of tables.", 2, db.numTables());
   assertEquals("Database returned wrong table.", t1, db.table("protein"));
   assertEquals("Database returned wrong table.", t2, db.table("dna"));
   Set names = db.names();
   assertTrue("Table is missing.", names.contains("protein"));
   assertTrue("Table is missing.", names.contains("dna"));
   assertEquals("Database has wrong number of tables.", 2, names.size());
   try {
     db.addTable(null);
     fail("addTable must throw NullPointerException.");
   } catch (NullPointerException e) {
     e.printStackTrace();
   }
 }
Esempio n. 5
0
  @Override
  public boolean elementPasses(AlignmentPosStreamerPosition streamPos) {

    return streamPos.currentAp.getRef().equals(DNATools.c());
  }
Esempio n. 6
0
  private void dnaCommand(HttpServletRequest req, DazzleResponse resp, DazzleDataSource dds)
      throws IOException, DataSourceException, ServletException, DazzleException {

    DazzleReferenceSource drs = (DazzleReferenceSource) dds;

    List segments = DazzleTools.getSegments(dds, req, resp);
    if (segments.size() == 0) {
      throw new DazzleException(
          DASStatus.STATUS_BAD_COMMAND_ARGUMENTS, "No segments specified for dna command");
    }

    // Fetch and validate the requests.

    Map segmentResults = new HashMap();
    for (Iterator i = segments.iterator(); i.hasNext(); ) {
      Segment seg = (Segment) i.next();

      try {
        Sequence seq = drs.getSequence(seg.getReference());
        if (seq.getAlphabet() != DNATools.getDNA()) {
          throw new DazzleException(
              DASStatus.STATUS_SERVER_ERROR,
              "Sequence " + seg.toString() + " is not in the DNA alphabet");
        }
        if (seg.isBounded()) {
          if (seg.getMin() < 1 || seg.getMax() > seq.length()) {
            throw new DazzleException(
                DASStatus.STATUS_BAD_COORDS,
                "Segment " + seg.toString() + " doesn't fit sequence of length " + seq.length());
          }
        }
        segmentResults.put(seg, seq);
      } catch (NoSuchElementException ex) {
        throw new DazzleException(DASStatus.STATUS_BAD_REFERENCE, ex);
      } catch (DataSourceException ex) {
        throw new DazzleException(DASStatus.STATUS_SERVER_ERROR, ex);
      }
    }

    //
    // Looks okay -- generate the response document
    //

    XMLWriter xw = resp.startDasXML("DASDNA", "dasdna.dtd");

    try {
      xw.openTag("DASDNA");
      for (Iterator i = segmentResults.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry me = (Map.Entry) i.next();
        Segment seg = (Segment) me.getKey();
        Sequence seq = (Sequence) me.getValue();

        xw.openTag("SEQUENCE");
        xw.attribute("id", seg.getReference());
        xw.attribute("version", drs.getLandmarkVersion(seg.getReference()));
        if (seg.isBounded()) {
          xw.attribute("start", "" + seg.getStart());
          xw.attribute("stop", "" + seg.getStop());
        } else {
          xw.attribute("start", "" + 1);
          xw.attribute("stop", "" + seq.length());
        }

        SymbolList syms = seq;
        if (seg.isBounded()) {
          syms = syms.subList(seg.getMin(), seg.getMax());
        }
        if (seg.isInverted()) {
          syms = DNATools.reverseComplement(syms);
        }

        xw.openTag("DNA");
        xw.attribute("length", "" + syms.length());

        for (int pos = 1; pos <= syms.length(); pos += 60) {
          int maxPos = Math.min(syms.length(), pos + 59);
          xw.println(syms.subStr(pos, maxPos));
        }

        xw.closeTag("DNA");
        xw.closeTag("SEQUENCE");
      }
      xw.closeTag("DASDNA");
      xw.close();
    } catch (Exception ex) {
      throw new DazzleException(ex, "Error writing DNA document");
    }
  }