/*
  * Author: Daniel Cameron
  */
 @Test
 public void testCaseEquivalence() {
   DNACompoundSet dnacs = DNACompoundSet.getDNACompoundSet();
   SubstitutionMatrix<NucleotideCompound> dnaTest =
       new SimpleSubstitutionMatrix<NucleotideCompound>(
           dnacs, "# Test\nA C G T\nA 5 0 0 0\nC 0 5 0 0\nG 0 0 5 0\nT 0 0 0 1\n", "DNA Test");
   @SuppressWarnings("unused")
   short[][] matrix = dnaTest.getMatrix();
   assertEquals(
       dnaTest.getValue(dnacs.getCompoundForString("G"), dnacs.getCompoundForString("g")), 5);
   assertEquals(
       dnaTest.getValue(dnacs.getCompoundForString("A"), dnacs.getCompoundForString("g")), 0);
   assertEquals(
       dnaTest.getValue(dnacs.getCompoundForString("g"), dnacs.getCompoundForString("G")), 5);
   assertEquals(
       dnaTest.getValue(dnacs.getCompoundForString("g"), dnacs.getCompoundForString("A")), 0);
 }
 @Test
 public void testToString() {
   SubstitutionMatrix<NucleotideCompound> matrix =
       new SimpleSubstitutionMatrix<NucleotideCompound>(
           DNACompoundSet.getDNACompoundSet(),
           "# Test\nA C  G T\nA 5  0 0 0\nC 0 5 0 0 \nG 0 0 5 0\n    T 0     0 0 1\n",
           "DNAtest");
   assertEquals(matrix.toString().substring(0, 6), "# Test");
   assertEquals(
       matrix.toString(),
       String.format("# Test%n  A C G T%nA 5 0 0 0%nC 0 5 0 0%nG 0 0 5 0%nT 0 0 0 1%n"));
 }
 @Test
 public void test() throws CompoundNotFoundException {
   NucleotideCompound A = new DNASequence("A").getCompoundAt(1);
   NucleotideCompound a = new DNASequence("a").getCompoundAt(1);
   NucleotideCompound c = new DNASequence("c").getCompoundAt(1);
   SubstitutionMatrix<NucleotideCompound> matrix =
       new SimpleSubstitutionMatrix<NucleotideCompound>(
           DNACompoundSet.getDNACompoundSet(), (short) 1, (short) 0);
   assertEquals(1, (matrix.getValue(A, A)));
   assertEquals(1, (matrix.getValue(a, a)));
   assertEquals(1, (matrix.getValue(A, a)));
   assertEquals(0, (matrix.getValue(a, c)));
 }
 @Test
 public void testSimpleSubstitutionMatrixCompoundSetOfCStringString() {
   DNACompoundSet dnacs = DNACompoundSet.getDNACompoundSet();
   SubstitutionMatrix<NucleotideCompound> dnaTest =
       new SimpleSubstitutionMatrix<NucleotideCompound>(
           dnacs, "# Test\nA C G T\nA 5 0 0 0\nC 0 5 0 0\nG 0 0 5 0\nT 0 0 0 1\n", "DNA Test");
   short[][] matrix = dnaTest.getMatrix();
   assertEquals(matrix[1][1], 5);
   assertEquals(matrix[3][3], 1);
   assertEquals(matrix[3][1], 0);
   assertEquals(dnaTest.getMatrixAsString().substring(2, 9), "A C G T");
   assertEquals(
       dnaTest.getValue(dnacs.getCompoundForString("G"), dnacs.getCompoundForString("G")), 5);
   assertEquals(
       dnaTest.getValue(dnacs.getCompoundForString("A"), dnacs.getCompoundForString("G")), 0);
 }
  /** Test of process method, of class GenbankReader. */
  @Test
  public void testProcess() throws Throwable {
    /*
     * Method 1: With the GenbankProxySequenceReader
     */
    // Try with the GenbankProxySequenceReader
    GenbankProxySequenceReader<AminoAcidCompound> genbankProteinReader =
        new GenbankProxySequenceReader<AminoAcidCompound>(
            System.getProperty("java.io.tmpdir"),
            "NP_000257",
            AminoAcidCompoundSet.getAminoAcidCompoundSet());
    ProteinSequence proteinSequence = new ProteinSequence(genbankProteinReader);
    genbankProteinReader
        .getHeaderParser()
        .parseHeader(genbankProteinReader.getHeader(), proteinSequence);
    logger.info(
        "Sequence({},{}) = {}...",
        proteinSequence.getAccession(),
        proteinSequence.getLength(),
        proteinSequence.getSequenceAsString().substring(0, 10));

    GenbankProxySequenceReader<NucleotideCompound> genbankDNAReader =
        new GenbankProxySequenceReader<NucleotideCompound>(
            System.getProperty("java.io.tmpdir"), "NM_001126", DNACompoundSet.getDNACompoundSet());
    DNASequence dnaSequence = new DNASequence(genbankDNAReader);
    genbankDNAReader.getHeaderParser().parseHeader(genbankDNAReader.getHeader(), dnaSequence);
    logger.info(
        "Sequence({},{}) = {}...",
        dnaSequence.getAccession(),
        dnaSequence.getLength(),
        dnaSequence.getSequenceAsString().substring(0, 10));
    /*
     * Method 2: With the GenbankReaderHelper
     */
    // Try with the GenbankReaderHelper
    ClasspathResource dnaResource = new ClasspathResource("NM_000266.gb", true);
    // File dnaFile = new File("src/test/resources/NM_000266.gb");
    // File protFile = new File("src/test/resources/BondFeature.gb");
    ClasspathResource protResource = new ClasspathResource("BondFeature.gb");

    LinkedHashMap<String, DNASequence> dnaSequences =
        GenbankReaderHelper.readGenbankDNASequence(dnaResource.getInputStream());
    for (DNASequence sequence : dnaSequences.values()) {
      logger.info("DNA Sequence: {}", sequence.getSequenceAsString());
    }

    LinkedHashMap<String, ProteinSequence> protSequences =
        GenbankReaderHelper.readGenbankProteinSequence(protResource.getInputStream());
    for (ProteinSequence sequence : protSequences.values()) {
      logger.info("Protein Sequence: {}", sequence.getSequenceAsString());
    }
    /*
     * Method 3: With the GenbankReader Object
     */
    // Try reading with the GanbankReader

    GenbankReader<DNASequence, NucleotideCompound> dnaReader =
        new GenbankReader<DNASequence, NucleotideCompound>(
            dnaResource.getInputStream(),
            new GenericGenbankHeaderParser<DNASequence, NucleotideCompound>(),
            new DNASequenceCreator(DNACompoundSet.getDNACompoundSet()));
    dnaSequences = dnaReader.process();

    logger.info("DNA Sequence: {}", dnaSequences);

    GenbankReader<ProteinSequence, AminoAcidCompound> protReader =
        new GenbankReader<ProteinSequence, AminoAcidCompound>(
            protResource.getInputStream(),
            new GenericGenbankHeaderParser<ProteinSequence, AminoAcidCompound>(),
            new ProteinSequenceCreator(AminoAcidCompoundSet.getAminoAcidCompoundSet()));
    protSequences = protReader.process();

    logger.info("Protein Sequence: {}", protSequences);
  }