/**
   * Test predict using code directly
   *
   * @throws XmppException
   * @throws XwsException
   * @throws InterruptedException
   * @throws Xws4jException
   */
  @Test
  public void testHivpredServiceDirectly()
      throws XmppException, XwsException, InterruptedException, Xws4jException {

    String sequence =
        "PQITLWQRPLVTIKIGCQLKEALLDTGADDTVLEEANLPGRWKPKMIGGIGGFIKVRQYDQILIEICGHKAIGTVLVGPTPVNIIGRNLLTQIGCTLNF";
    String predictionServer = "hivpred.ws1.bmc.uu.se";
    String predictionFunction = "predictSusceptibility";

    XwsManager xmpp = new XwsManager();

    // Connect if not connected (requires JID and password in preferences)
    if (!(xmpp.isConnected())) xmpp.connect();

    // Set up function
    IFunction hivFunction = xmpp.getFunction(predictionServer, predictionFunction);

    HIVPredInputType in = HivpredFactory.eINSTANCE.createHIVPredInputType();
    in.setSequence(sequence);

    DocumentRoot root = HivpredFactory.eINSTANCE.createDocumentRoot();
    root.setHIVPredInput(in);

    // Convert to DOM since inputElement must be this
    Element inputElement = EMFDOMConversion.getDomFromEMF(root);

    // Invoke sync service
    Element result = hivFunction.invokeSync(inputElement, 20000);

    assertNotNull("Result from hivpred is null", result);

    System.out.println(
        "Got good hivpred result from service: " + JavaDOMTools.w3cElementToString(result));

    // Convert output DOM to EMF
    //      EObject emfo = EMFDOMConversion.getEMFfromDOM(result);

    //    Element el = document.getDocumentElement();
    EObject emfo = EMFDOMConversion.getEMFfromDOMusingJavaDOMtools(result);

    if (!(emfo instanceof DocumentRoot)) {
      fail("Result from hivpred was not a HIVpred DocumentRoot.");
    }

    DocumentRoot docroot = (DocumentRoot) emfo;
    HIVPredOutputType hivOutput = docroot.getHIVPredOutput();
    assertNotNull(hivOutput);
    assertEquals(7, hivOutput.getResult().size());
  }
  @Test
  public void testPredictFileWithSingleLine()
      throws Xws4jException, XmppException, InterruptedException, URISyntaxException,
          MalformedURLException, IOException {

    URI uri = getClass().getResource("/testFiles/single.seq").toURI();
    URL url = FileLocator.toFileURL(uri.toURL());
    String path = url.getFile();

    System.out.println("Trying to predict file: " + path);

    HIVPredOutputType res = hivdrc.predictPI(path);
    assertNotNull(res);

    // File contains same string as in testPredictString() method
    assertEquals("", res.getErrorMessage());
    assertEquals(1, res.getMutNotInDataset().size());
    assertEquals("P1A", res.getMutNotInDataset().get(0).getName());
    assertEquals(2, res.getMutOutsideModelBoundaries().size());
    assertEquals("Q2A", res.getMutOutsideModelBoundaries().get(0).getName());
    assertEquals("I3A", res.getMutOutsideModelBoundaries().get(1).getName());

    assertEquals(7, res.getResult().size());
    assertEquals("amprenavir", res.getResult().get(0).getName());
    assertEquals(-9.344846031197962, res.getResult().get(0).getResult(), EPSILON);
    assertEquals("atazanavir", res.getResult().get(1).getName());
    assertEquals(-8.081778845481008, res.getResult().get(1).getResult(), EPSILON);
    assertEquals("indinavir", res.getResult().get(2).getName());
    assertEquals(-8.306376101045098, res.getResult().get(2).getResult(), EPSILON);
    assertEquals("lopinavir", res.getResult().get(3).getName());
    assertEquals(-8.789871555954795, res.getResult().get(3).getResult(), EPSILON);
    assertEquals("nelfinavir", res.getResult().get(4).getName());
    assertEquals(-7.661361493579009, res.getResult().get(4).getResult(), EPSILON);
    assertEquals("ritonavir", res.getResult().get(5).getName());
    assertEquals(-8.108639981136413, res.getResult().get(5).getResult(), EPSILON);
    //      assertEquals("saquinavir", res.getResult().get(6).getName());
    // TODO: fix misspelling in sus7.jar class PredictionResult
    // saquinanvir -> saquinavir
    assertEquals(-8.702355550536716, res.getResult().get(6).getResult(), EPSILON);

    System.out.println(res);
  }
  /**
   * Test predict using the hivpredmanager
   *
   * @throws Xws4jException
   * @throws XmppException
   * @throws InterruptedException
   */
  @Test
  public void testPredictString() throws Xws4jException, XmppException, InterruptedException {
    String seq =
        "AAAALWQRPLVTIKIGGQLKEALLDTGADDTVLEEMNLPGRWKPKMIGGIGGFIKVRQYDQILIEICGHKAIGTVLVGPTPVNIIGRNLLTQIGCTLNF";
    HIVPredOutputType res = hivdrc.predictPI(seq);
    assertNotNull(res);

    /*
    <?xml version="1.0" encoding="ASCII"?><hivpred:HIVPredOutput xmlns:hivpred="http://www.hivdrc.org/hivpred" errorMessage="">
       <hivpred:mutNotInDataset name="P1A"/>
       <hivpred:mutOutsideModelBoundaries name="Q2A"/>
       <hivpred:mutOutsideModelBoundaries name="I3A"/>
       <hivpred:result name="amprenavir" result="-9.344846031197962"/>
       <hivpred:result name="atazanavir" result="-8.081778845481008"/>
       <hivpred:result name="indinavir" result="-8.306376101045098"/>
       <hivpred:result name="lopinavir" result="-8.789871555954795"/>
       <hivpred:result name="nelfinavir" result="-7.661361493579009"/>
       <hivpred:result name="ritonavir" result="-8.108639981136413"/>
       <hivpred:result name="saquinanvir" result="-8.702355550536716"/>
    </hivpred:HIVPredOutput>
    */

    assertEquals("", res.getErrorMessage());
    assertEquals(1, res.getMutNotInDataset().size());
    assertEquals("P1A", res.getMutNotInDataset().get(0).getName());
    assertEquals(2, res.getMutOutsideModelBoundaries().size());
    assertEquals("Q2A", res.getMutOutsideModelBoundaries().get(0).getName());
    assertEquals("I3A", res.getMutOutsideModelBoundaries().get(1).getName());

    assertEquals(7, res.getResult().size());
    assertEquals("amprenavir", res.getResult().get(0).getName());
    assertEquals(-9.344846031197962, res.getResult().get(0).getResult(), EPSILON);
    assertEquals("atazanavir", res.getResult().get(1).getName());
    assertEquals(-8.081778845481008, res.getResult().get(1).getResult(), EPSILON);
    assertEquals("indinavir", res.getResult().get(2).getName());
    assertEquals(-8.306376101045098, res.getResult().get(2).getResult(), EPSILON);
    assertEquals("lopinavir", res.getResult().get(3).getName());
    assertEquals(-8.789871555954795, res.getResult().get(3).getResult(), EPSILON);
    assertEquals("nelfinavir", res.getResult().get(4).getName());
    assertEquals(-7.661361493579009, res.getResult().get(4).getResult(), EPSILON);
    assertEquals("ritonavir", res.getResult().get(5).getName());
    assertEquals(-8.108639981136413, res.getResult().get(5).getResult(), EPSILON);
    //      assertEquals("saquinavir", res.getResult().get(6).getName());
    // TODO: fix misspelling in sus7.jar class PredictionResult
    // saquinanvir -> saquinavir
    assertEquals(-8.702355550536716, res.getResult().get(6).getResult(), EPSILON);

    System.out.println(res);
  }