@Test
  public void testDNAtoRNA() {
    BiojavaSequence seq = null;
    try {
      seq = biojava.loadSequence(TestData.getPathToDNAFastaSequence());
    } catch (IOException e1) {
      LogUtils.debugTrace(logger, e1);
      fail(e1.getMessage());
    } catch (Exception e) {
      LogUtils.debugTrace(logger, e);
      fail(e.getMessage());
    }

    assertNotNull(seq);

    assertTrue(seq instanceof BiojavaDNASequence);
    BiojavaDNASequence dnaSeq = (BiojavaDNASequence) seq;

    try {
      assertEquals("GATTACA", seq.getPlainSequence().trim().toUpperCase());
      BiojavaRNASequence rnaSeq;
      rnaSeq = biojava.DNAtoRNA(dnaSeq);
      assertEquals("GAUUACA", rnaSeq.getPlainSequence().trim().toUpperCase());
    } catch (IOException e) {
      LogUtils.debugTrace(logger, e);
      fail(e.getMessage());
    } catch (Exception e) {
      LogUtils.debugTrace(logger, e);
      fail(e.getMessage());
    }
  }
  @Test
  public void testLoadFastaSequences() {
    BiojavaSequence seq = null;
    try {
      // Test read Protein as fasta
      seq = biojava.loadSequence(TestData.getPathToAAFastaSequence());
      assertNotNull(seq);
      assertEquals("SEQUENCE", seq.getPlainSequence().trim().toUpperCase());

      // Test read DNA as fasta
      seq = biojava.loadSequence(TestData.getPathToDNAFastaSequence());
      assertNotNull(seq);
      assertEquals("GATTACA", seq.getPlainSequence().trim().toUpperCase());

      /*
                  //Test read RNA as fasta
                  seq = biojava.loadSequence( TestData.getPathToRNAFastaSequence() );
                  assertNotNull( seq );
                  assertEquals( "GAUUACA", seq.getPlainSequence().trim().toUpperCase() );
      */
    } catch (IOException e) {
      fail(e.getMessage());
    } catch (Exception e) {
      LogUtils.debugTrace(logger, e);
      fail(e.getMessage());
    }
  }
  @Test
  public void testDNAtoProtein() {
    BiojavaSequence seq = null;
    seq = biojava.createSequence("CTCCTCGCGAAACGATACGAT");

    assertNotNull(seq);

    assertTrue(seq instanceof BiojavaDNASequence);
    BiojavaDNASequence dnaSeq = (BiojavaDNASequence) seq;

    try {

      BiojavaAASequence rnaSeq = biojava.DNAToProtein(dnaSeq);
      assertEquals("LLAKRYD", rnaSeq.getPlainSequence().trim().toUpperCase());

    } catch (IOException e) {
      LogUtils.debugTrace(logger, e);
      fail(e.getMessage());
    } catch (Exception e) {
      LogUtils.debugTrace(logger, e);
      fail(e.getMessage());
    }
  }
  @Test
  public void testToFasta() {
    BiojavaSequence seq = null;
    try {
      seq = biojava.loadSequence(TestData.getPathToAAFastaSequence());
      //            seq = biojava.loadSequence( TestData.getPathToFosbFastaSequence() );
    } catch (IOException e) {
      LogUtils.debugTrace(logger, e);
      fail(e.getMessage());
    } catch (Exception e) {
      LogUtils.debugTrace(logger, e);
      fail(e.getMessage());
    }
    assertNotNull(seq);
    //        assertEquals( "Sequence", seq.getName());

    try {
      assertEquals("SEQUENCE", seq.getPlainSequence().trim());
    } catch (IOException e) {
      LogUtils.debugTrace(logger, e);
      fail(e.getMessage());
    }
  }
  /*
      @Test
      public void testRNAtoDNA() {

          BiojavaSequence seq = biojava.createSequence("GAUUACA");

          assertNotNull(seq);

          assertTrue(seq instanceof BiojavaRNASequence);
          BiojavaRNASequence rnaSeq = (BiojavaRNASequence) seq;

          try {
              //Check correctly read
              assertEquals( "GAUUACA", rnaSeq.getPlainSequence().trim().toUpperCase() );

              BiojavaDNASequence dnaSeq = biojava.RNAtoDNA(rnaSeq);

              //Check correctly converted
              assertEquals( "GATTACA", dnaSeq.getPlainSequence().trim().toUpperCase() );
          } catch (IOException e) {
              LogUtils.debugTrace(logger, e);
              fail(e.getMessage());
          } catch (Exception e) {
              LogUtils.debugTrace(logger, e);
              fail(e.getMessage());
          }
      }
  */
  @Test
  public void testLoadFastaSequenceCollection() throws BioclipseException, IOException {
    BiojavaSequenceList sequenceCollection = null;
    sequenceCollection = biojava.loadSequences(TestData.getPathToMultipleSequences());
    assertNotNull(sequenceCollection);
    assertEquals(2, sequenceCollection.size());

    // Check individual sequences
    BiojavaSequence seq1 = sequenceCollection.get(0);
    BiojavaSequence seq2 = sequenceCollection.get(1);

    try {
      assertEquals(341, seq1.getPlainSequence().length());
      assertEquals(342, seq2.getPlainSequence().length());
    } catch (IOException e) {
      LogUtils.debugTrace(logger, e);
      fail(e.getMessage());
    }
  }
Example #6
0
  public void runTest(
      String testID,
      IMolecule mol,
      IReturner<List<? extends ITestResult>> returner,
      IProgressMonitor monitor)
      throws BioclipseException {

    ICDKManager cdk = net.bioclipse.cdk.business.Activator.getDefault().getJavaCDKManager();

    IDSTest test = getTest(testID);
    List<? extends ITestResult> ret = null;
    try {

      // Preprocess the molecule
      ICDKMolecule cdkmol = cdk.asCDKMolecule(mol);

      // Clone the mol
      IAtomContainer clonedAC = null;
      try {
        clonedAC = (IAtomContainer) cdkmol.getAtomContainer().clone();
      } catch (CloneNotSupportedException e) {
        logger.error("Could not clone mol: " + cdkmol);
        return;
      }

      ICDKMolecule clonedMol = new CDKMolecule(clonedAC);
      ret = test.runWarningTest(clonedMol, monitor);

    } catch (Exception e) {
      // in case of error...
      LogUtils.debugTrace(logger, e);
      ITestResult er = new SimpleResult("Error: " + e.getMessage(), ITestResult.ERROR);
      er.setDetailedMessage(e.getMessage());
      List<ITestResult> trlist = new ArrayList<ITestResult>();
      trlist.add(er);
      monitor.done();
      returner.completeReturn(trlist);
      return;
    }

    monitor.done();
    returner.completeReturn(ret);
  }
  public static ChoiceGenerator getGeneratorsFromExtensionPoint() {
    ChoiceGenerator choiseGenerator = new ChoiceGenerator();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint generatorExtensionPoint = registry.getExtensionPoint(EP_GENERATOR);
    if (generatorExtensionPoint != null) {
      IExtension[] generatorExtensions = generatorExtensionPoint.getExtensions();

      for (IExtension extension : generatorExtensions) {

        for (IConfigurationElement element : extension.getConfigurationElements()) {
          try {
            final IGenerator generator = (IGenerator) element.createExecutableExtension("class");
            choiseGenerator.add(generator);
          } catch (CoreException e) {
            LogUtils.debugTrace(Logger.getLogger(ChoiceGenerator.class), e);
          }
        }
      }
    }
    return choiseGenerator;
  }
  /**
   * This method is called when 'Finish' button is pressed in the wizard. We will create an
   * operation and run it using wizard as execution context.
   */
  public boolean performFinish() {
    try {
      Options opts = new Options(new String[0]);
      opts.setDefaultURL(serverPage.getSelectedServer() + "/services/NMRShiftDB");
      Service service = new Service();
      Call call = (Call) service.createCall();
      call.setOperationName("doSearch");
      call.setTargetEndpointAddress(new URL(opts.getURL()));
      DocumentBuilder builder;
      builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      SOAPBodyElement[] input = new SOAPBodyElement[1];
      Document doc = builder.newDocument();
      Element cdataElem;
      cdataElem = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "doSearch");
      Element reqElem;
      reqElem = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "searchstring");

      /*DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      Node node = db.parse(new ByteArrayInputStream(new Convertor(true,"").cdkAtomContainerToCMLMolecule(ac).toXML().getBytes()));*/
      Node node =
          DOMConverter.convert(
                  new nu.xom.Document(new Convertor(true, "").cdkAtomContainerToCMLMolecule(ac)),
                  builder.getDOMImplementation())
              .getFirstChild();
      reqElem.appendChild(doc.importNode(node, true));
      Element reqElem2;
      reqElem2 = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "searchtype");
      Node node2;
      node2 = doc.createTextNode("--");
      reqElem2.appendChild(node2);
      Element reqElem3;
      reqElem3 = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "searchfield");
      Node node3;
      node3 = doc.createTextNode(NmrshiftdbUtils.replaceSpaces(serverPage.selectedOption()));
      reqElem3.appendChild(node3);
      cdataElem.appendChild(reqElem);
      cdataElem.appendChild(reqElem2);
      cdataElem.appendChild(reqElem3);
      input[0] = new SOAPBodyElement(cdataElem);
      Vector elems = (Vector) call.invoke(input);
      SOAPBodyElement elem = (SOAPBodyElement) elems.get(0);
      Element e = elem.getAsDOM();
      CMLBuilder cmlbuilder = new CMLBuilder();
      CMLElement cmlElement = (CMLElement) cmlbuilder.parseString(XMLUtils.ElementToString(e));
      if (cmlElement.getChildCount() > 0) {
        IFolder folder = NmrshiftdbUtils.createVirtualFolder();
        for (int i = 0; i < cmlElement.getChildCount(); i++) {
          net.bioclipse.specmol.Activator.getDefault()
              .getJavaSpecmolManager()
              .saveSpecmol(
                  new JumboSpecmol((CMLCml) cmlElement.getChildCMLElements().get(i)),
                  folder.getFile(
                      ((CMLMolecule)
                                  cmlElement
                                      .getChildCMLElements()
                                      .get(i)
                                      .getChildCMLElement("molecule", 0))
                              .getId()
                          + "."
                          + SpectrumEditor.CML_TYPE));
        }
      } else {
        MessageDialog.openInformation(
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            "No results",
            "No spectra in NMRShiftDB for this structure!");
      }
    } catch (Exception ex) {
      LogUtils.handleException(ex, logger);
    }
    return true;
  }