From: <lol...@us...> - 2011-06-01 18:47:35
|
Revision: 894 http://treebase.svn.sourceforge.net/treebase/?rev=894&view=rev Author: loloyohe Date: 2011-06-01 18:47:29 +0000 (Wed, 01 Jun 2011) Log Message: ----------- Test for NexmlMatrixConverter class for function fromTreeBaseToXml(CharacterMatrix). This is the function that calls the poplulateXmlMatrix() function Added Paths: ----------- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java Added: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java (rev 0) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-01 18:47:29 UTC (rev 894) @@ -0,0 +1,64 @@ +package org.cipres.treebase.domain.nexus; + +import junit.framework.Assert; + +import org.cipres.treebase.dao.AbstractDAOTest; +import org.cipres.treebase.domain.matrix.CharacterMatrix; +import org.cipres.treebase.domain.nexus.nexml.NexmlMatrixConverter; +import org.cipres.treebase.domain.nexus.NexusDataSet; +import org.cipres.treebase.domain.study.Study; +import org.cipres.treebase.domain.taxon.TaxonLabelHome; +import org.nexml.model.DocumentFactory; +import org.nexml.model.Document; + +public class NexmlMatrixConverterTest extends AbstractDAOTest { + private TaxonLabelHome mTaxonLabelHome; + + /** + * Test for {@link org.cipres.treebase.domain.nexus.nexml.NexmlMatrixConverter#fromTreeBaseToXml(CharacterMatrix)}. + */ + public void testNexmlMatrixConverter() { + String testName = "testNexmlMatrixConverter"; + //signal beginning of test + if (logger.isInfoEnabled()) { + logger.info("\n\t\tRunning Test: " + testName); + } + + long studyId = 1787; + Study study = (Study)loadObject(Study.class, studyId); + NexusDataSet nexusDataSet = new NexusDataSet(); + + Document doc = DocumentFactory.safeCreateDocument(); + nexusDataSet.setNexmlProject(doc); + NexmlMatrixConverter nmc = new NexmlMatrixConverter(study,getTaxonLabelHome(),doc); + for (org.cipres.treebase.domain.matrix.Matrix matrix : nexusDataSet.getMatrices() ) { + if ( matrix instanceof CharacterMatrix ) { + //fromTreeBaseToXml(CharacterMatrix) is main method being tested here--it uses populateXmlMatrix() function + String xml = ((Document) nmc.fromTreeBaseToXml((CharacterMatrix)matrix)).getXmlString(); + System.out.println(xml); + Assert.assertNotNull(xml); + } + } + //signal that test is over + if (logger.isInfoEnabled()) { + logger.info(testName + " - end "); + } + } + + /** + * Return the TaxonLabelHome field. + * + * @return TaxonLabelHome mTaxonLabelHome + */ + public TaxonLabelHome getTaxonLabelHome() { + return mTaxonLabelHome; + } + + /** + * Set the TaxonLabelHome field. + */ + public void setTaxonLabelHome(TaxonLabelHome pNewTaxonLabelHome) { + mTaxonLabelHome = pNewTaxonLabelHome; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lol...@us...> - 2011-06-02 19:55:15
|
Revision: 896 http://treebase.svn.sourceforge.net/treebase/?rev=896&view=rev Author: loloyohe Date: 2011-06-02 19:55:09 +0000 (Thu, 02 Jun 2011) Log Message: ----------- Modified Paths: -------------- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-02 15:58:44 UTC (rev 895) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-02 19:55:09 UTC (rev 896) @@ -4,7 +4,10 @@ import org.cipres.treebase.dao.AbstractDAOTest; import org.cipres.treebase.domain.matrix.CharacterMatrix; +import org.cipres.treebase.domain.matrix.Matrix; +import org.cipres.treebase.domain.matrix.StandardMatrix; import org.cipres.treebase.domain.nexus.nexml.NexmlMatrixConverter; +import org.cipres.treebase.domain.nexus.nexml.NexmlDocumentConverter; import org.cipres.treebase.domain.nexus.NexusDataSet; import org.cipres.treebase.domain.study.Study; import org.cipres.treebase.domain.taxon.TaxonLabelHome; @@ -29,8 +32,11 @@ NexusDataSet nexusDataSet = new NexusDataSet(); Document doc = DocumentFactory.safeCreateDocument(); + NexmlDocumentConverter ndc = new NexmlDocumentConverter(study,getTaxonLabelHome(),doc); + NexmlMatrixConverter nmc = new NexmlMatrixConverter (study,getTaxonLabelHome(),ndc.fromTreeBaseToXml(study)); + nexusDataSet = ndc.fromXmlToTreeBase(doc); nexusDataSet.setNexmlProject(doc); - NexmlMatrixConverter nmc = new NexmlMatrixConverter(study,getTaxonLabelHome(),doc); + for (org.cipres.treebase.domain.matrix.Matrix matrix : nexusDataSet.getMatrices() ) { if ( matrix instanceof CharacterMatrix ) { //fromTreeBaseToXml(CharacterMatrix) is main method being tested here--it uses populateXmlMatrix() function @@ -38,7 +44,11 @@ System.out.println(xml); Assert.assertNotNull(xml); } + else { + System.out.println("im not working"); + } } + //signal that test is over if (logger.isInfoEnabled()) { logger.info(testName + " - end "); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2011-06-06 14:18:26
|
Revision: 900 http://treebase.svn.sourceforge.net/treebase/?rev=900&view=rev Author: rvos Date: 2011-06-06 14:18:19 +0000 (Mon, 06 Jun 2011) Log Message: ----------- This is pretty much how to convert treebase matrices to nexml ones. Modified Paths: -------------- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-04 03:36:27 UTC (rev 899) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-06 14:18:19 UTC (rev 900) @@ -1,18 +1,20 @@ package org.cipres.treebase.domain.nexus; +import java.util.List; + import junit.framework.Assert; import org.cipres.treebase.dao.AbstractDAOTest; import org.cipres.treebase.domain.matrix.CharacterMatrix; -import org.cipres.treebase.domain.matrix.Matrix; -import org.cipres.treebase.domain.matrix.StandardMatrix; -import org.cipres.treebase.domain.nexus.nexml.NexmlMatrixConverter; import org.cipres.treebase.domain.nexus.nexml.NexmlDocumentConverter; -import org.cipres.treebase.domain.nexus.NexusDataSet; import org.cipres.treebase.domain.study.Study; import org.cipres.treebase.domain.taxon.TaxonLabelHome; +import org.nexml.model.CategoricalMatrix; +import org.nexml.model.ContinuousMatrix; import org.nexml.model.DocumentFactory; import org.nexml.model.Document; +import org.nexml.model.Matrix; +import org.nexml.model.MolecularMatrix; public class NexmlMatrixConverterTest extends AbstractDAOTest { private TaxonLabelHome mTaxonLabelHome; @@ -29,30 +31,26 @@ long studyId = 1787; Study study = (Study)loadObject(Study.class, studyId); - NexusDataSet nexusDataSet = new NexusDataSet(); Document doc = DocumentFactory.safeCreateDocument(); NexmlDocumentConverter ndc = new NexmlDocumentConverter(study,getTaxonLabelHome(),doc); - NexmlMatrixConverter nmc = new NexmlMatrixConverter (study,getTaxonLabelHome(),ndc.fromTreeBaseToXml(study)); - nexusDataSet = ndc.fromXmlToTreeBase(doc); - nexusDataSet.setNexmlProject(doc); - - for (org.cipres.treebase.domain.matrix.Matrix matrix : nexusDataSet.getMatrices() ) { - if ( matrix instanceof CharacterMatrix ) { - //fromTreeBaseToXml(CharacterMatrix) is main method being tested here--it uses populateXmlMatrix() function - String xml = ((Document) nmc.fromTreeBaseToXml((CharacterMatrix)matrix)).getXmlString(); - System.out.println(xml); - Assert.assertNotNull(xml); + Document document = ndc.fromTreeBaseToXml(study); + List<Matrix<?>> matrices = document.getMatrices(); + Assert.assertTrue(matrices.size() != 0 ); + for ( Matrix<?> matrix : matrices ) { + if ( matrix instanceof MolecularMatrix ) { + System.out.println(matrix.getId() + " is a molecular character state matrix"); } + else if ( matrix instanceof ContinuousMatrix ) { + System.out.println(matrix.getId() + " is a continuous-valued character matrix"); + } + else if ( matrix instanceof CategoricalMatrix ) { + System.out.println(matrix.getId() + " is a categorical character state matrix"); + } else { - System.out.println("im not working"); + System.out.println("This should not ever happen."); } } - - //signal that test is over - if (logger.isInfoEnabled()) { - logger.info(testName + " - end "); - } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2011-06-08 14:02:59
|
Revision: 903 http://treebase.svn.sourceforge.net/treebase/?rev=903&view=rev Author: rvos Date: 2011-06-08 14:02:50 +0000 (Wed, 08 Jun 2011) Log Message: ----------- Updated this to demonstrate how char set creation should work. Modified Paths: -------------- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-08 14:01:38 UTC (rev 902) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-08 14:02:50 UTC (rev 903) @@ -1,11 +1,15 @@ package org.cipres.treebase.domain.nexus; +import java.util.Collection; import java.util.List; +import java.util.Set; import junit.framework.Assert; import org.cipres.treebase.dao.AbstractDAOTest; +import org.cipres.treebase.domain.matrix.CharSet; import org.cipres.treebase.domain.matrix.CharacterMatrix; +import org.cipres.treebase.domain.matrix.ColumnRange; import org.cipres.treebase.domain.nexus.nexml.NexmlDocumentConverter; import org.cipres.treebase.domain.study.Study; import org.cipres.treebase.domain.taxon.TaxonLabelHome; @@ -15,6 +19,7 @@ import org.nexml.model.Document; import org.nexml.model.Matrix; import org.nexml.model.MolecularMatrix; +import org.nexml.model.Subset; public class NexmlMatrixConverterTest extends AbstractDAOTest { private TaxonLabelHome mTaxonLabelHome; @@ -26,30 +31,85 @@ String testName = "testNexmlMatrixConverter"; //signal beginning of test if (logger.isInfoEnabled()) { - logger.info("\n\t\tRunning Test: " + testName); + logger.info("Running Test: " + testName); } long studyId = 1787; - Study study = (Study)loadObject(Study.class, studyId); - Document doc = DocumentFactory.safeCreateDocument(); - NexmlDocumentConverter ndc = new NexmlDocumentConverter(study,getTaxonLabelHome(),doc); - Document document = ndc.fromTreeBaseToXml(study); - List<Matrix<?>> matrices = document.getMatrices(); - Assert.assertTrue(matrices.size() != 0 ); - for ( Matrix<?> matrix : matrices ) { - if ( matrix instanceof MolecularMatrix ) { - System.out.println(matrix.getId() + " is a molecular character state matrix"); + // this is the full study as it is stored by the database + Study tbStudy = (Study)loadObject(Study.class, studyId); + + // these are the character state matrices that are part of the study + Set<org.cipres.treebase.domain.matrix.Matrix> tbMatrices = tbStudy.getMatrices(); + + // this is an object representation of a NeXML document + Document nexDoc = DocumentFactory.safeCreateDocument(); + + // the converter populates the NeXML document with the contents of the treebase study + NexmlDocumentConverter ndc = new NexmlDocumentConverter(tbStudy,getTaxonLabelHome(),nexDoc); + ndc.fromTreeBaseToXml(tbStudy); // here is where the conversion happens + + // these are the NeXML matrices that were created from the study + List<Matrix<?>> nexMatrices = nexDoc.getMatrices(); + + // there most be more than zero matrices because every treebase study has at least one matrix + Assert.assertTrue(nexMatrices.size() != 0 ); + + // now we're going to match up the NeXML matrices with their equivalent treebase ones + for ( Matrix<?> nexMatrix : nexMatrices ) { + + // the xml id is the same as the primary key of the equivalent matrix stored by treebase + String nexId = nexMatrix.getId(); + boolean foundEquivalentMatrix = false; + + // iterate over all treebase matrices for the study + for ( org.cipres.treebase.domain.matrix.Matrix tbMatrix : tbMatrices ) { + String tbId = "M" + tbMatrix.getId(); + + // although there is a class DistanceMatrix, it is my belief that we don't actually have + // any distance matrices stored, nor can we convert them to NeXML + Assert.assertTrue("TreeBASE matrix "+tbId+" must be a character matrix, not a distance matrix", tbMatrix instanceof CharacterMatrix); + + // if true, the matrices are equivalent + if ( nexId.equals(tbId) ) { + foundEquivalentMatrix = true; + Assert.assertTrue("NeXML matrix "+nexId+ " is one of the known subclasses", + nexMatrix instanceof CategoricalMatrix || nexMatrix instanceof MolecularMatrix || nexMatrix instanceof ContinuousMatrix); + + // we have to coerce the tbMatrix into a character matrix to get its character sets + CharacterMatrix tbCharacterMatrix = (CharacterMatrix)tbMatrix; + Set<CharSet> tbCharSets = tbCharacterMatrix.getCharSets(); + + // a treebase matrix has zero or more character sets, we must iterate over them + for ( CharSet tbCharSet : tbCharSets ) { + + // the coordinates of the character set are defined by a collection of column ranges that we iterate over + Collection<ColumnRange> tbColumnRanges = tbCharSet.getColumns(tbCharacterMatrix); + for ( ColumnRange tbColumnRange : tbColumnRanges ) { + + // these are the beginning and end of the range + int start = tbColumnRange.getStartColIndex(); + int stop = tbColumnRange.getEndColIndex(); + + // this is how we increment from beginning to end. This number is probably either 1, for a + // contiguous range, or 3 for codon positions + int inc = tbColumnRange.getRepeatInterval(); + + // this is how we create the equivalent nexml character set + Subset nexSubset = nexMatrix.createSubset(tbCharSet.getLabel()); + + // we have to assign character objects to the subset. Here we get the full list + List<org.nexml.model.Character> nexCharacters = nexMatrix.getCharacters(); + + // now we iterate over the coordinates and assign the nexml characters to the set + for ( int i = start; i <= stop; i += inc ) { + nexSubset.addThing(nexCharacters.get(i)); + } + } + } + } } - else if ( matrix instanceof ContinuousMatrix ) { - System.out.println(matrix.getId() + " is a continuous-valued character matrix"); - } - else if ( matrix instanceof CategoricalMatrix ) { - System.out.println(matrix.getId() + " is a categorical character state matrix"); - } - else { - System.out.println("This should not ever happen."); - } + Assert.assertTrue("Searched for equivalent to NeXML matrix "+nexId, foundEquivalentMatrix); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2011-06-10 14:52:00
|
Revision: 907 http://treebase.svn.sourceforge.net/treebase/?rev=907&view=rev Author: rvos Date: 2011-06-10 14:51:54 +0000 (Fri, 10 Jun 2011) Log Message: ----------- Now using a study ID that actually has character sets, and added some defensive programming to prevent null pointer exceptions in cases where no increment has been defined for the column range (in which case we default to an increment of 1, i.e. a contiguous range). Modified Paths: -------------- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-10 14:46:37 UTC (rev 906) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-10 14:51:54 UTC (rev 907) @@ -34,7 +34,7 @@ logger.info("Running Test: " + testName); } - long studyId = 1787; + long studyId = 794; // this study seems to have character sets // this is the full study as it is stored by the database Study tbStudy = (Study)loadObject(Study.class, studyId); @@ -91,12 +91,19 @@ int start = tbColumnRange.getStartColIndex(); int stop = tbColumnRange.getEndColIndex(); - // this is how we increment from beginning to end. This number is probably either 1, for a - // contiguous range, or 3 for codon positions - int inc = tbColumnRange.getRepeatInterval(); + // this is how we increment from beginning to end. This number is probably either null, for a + // contiguous range, or perhaps 3 for codon positions + int inc = 1; + // need to do this to prevent nullpointerexceptions + if ( null != tbColumnRange.getRepeatInterval() ) { + inc = tbColumnRange.getRepeatInterval(); + } + // this is how we create the equivalent nexml character set - Subset nexSubset = nexMatrix.createSubset(tbCharSet.getLabel()); + // you will need to update CharSet to get the new implementation of getLabel(), which + // returns the same value as getTitle() + Subset nexSubset = nexMatrix.createSubset(tbCharSet.getLabel()); // we have to assign character objects to the subset. Here we get the full list List<org.nexml.model.Character> nexCharacters = nexMatrix.getCharacters(); @@ -110,6 +117,7 @@ } } Assert.assertTrue("Searched for equivalent to NeXML matrix "+nexId, foundEquivalentMatrix); + System.out.println(nexDoc.getXmlString()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lol...@us...> - 2011-06-13 16:47:41
|
Revision: 915 http://treebase.svn.sourceforge.net/treebase/?rev=915&view=rev Author: loloyohe Date: 2011-06-13 16:47:34 +0000 (Mon, 13 Jun 2011) Log Message: ----------- Added a second JUnit test testNexmlCharSets(). It verifies if the title and coordinates of a treebase character set and nexml character set match up. Modified Paths: -------------- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-13 15:10:50 UTC (rev 914) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-13 16:47:34 UTC (rev 915) @@ -26,6 +26,8 @@ /** * Test for {@link org.cipres.treebase.domain.nexus.nexml.NexmlMatrixConverter#fromTreeBaseToXml(CharacterMatrix)}. + * Finds an equivalent, created NexmlMatrix within a NeXML document to go with the matrix + * fetched from the TreeBASE database. */ public void testNexmlMatrixConverter() { String testName = "testNexmlMatrixConverter"; @@ -38,10 +40,10 @@ // this is the full study as it is stored by the database Study tbStudy = (Study)loadObject(Study.class, studyId); - + // these are the character state matrices that are part of the study Set<org.cipres.treebase.domain.matrix.Matrix> tbMatrices = tbStudy.getMatrices(); - + // this is an object representation of a NeXML document Document nexDoc = DocumentFactory.safeCreateDocument(); @@ -61,11 +63,11 @@ // the xml id is the same as the primary key of the equivalent matrix stored by treebase String nexId = nexMatrix.getId(); boolean foundEquivalentMatrix = false; - + // iterate over all treebase matrices for the study for ( org.cipres.treebase.domain.matrix.Matrix tbMatrix : tbMatrices ) { String tbId = "M" + tbMatrix.getId(); - + // although there is a class DistanceMatrix, it is my belief that we don't actually have // any distance matrices stored, nor can we convert them to NeXML Assert.assertTrue("TreeBASE matrix "+tbId+" must be a character matrix, not a distance matrix", tbMatrix instanceof CharacterMatrix); @@ -85,6 +87,7 @@ // the coordinates of the character set are defined by a collection of column ranges that we iterate over Collection<ColumnRange> tbColumnRanges = tbCharSet.getColumns(tbCharacterMatrix); + for ( ColumnRange tbColumnRange : tbColumnRanges ) { // these are the beginning and end of the range @@ -122,6 +125,114 @@ } /** + * Test for {@link org.cipres.treebase.domain.nexus.nexml.NexmlMatrixConverter#}. + * It verifies that NexmlCharSets have the same name and coordinates as those in the + * TreeBASE matrix. + */ + public void testNexmlMatrixCharSets() { + String testName = "testNexmlCharSets"; + //signal beginning of test + if (logger.isInfoEnabled()) { + logger.info("Running Test: " + testName); + } + long studyId = 2000; + + // this is the full study as it is stored by the database + Study tbStudy = (Study)loadObject(Study.class, studyId); + + // these are the character state matrices that are part of the study + Set<org.cipres.treebase.domain.matrix.Matrix> tbMatrices = tbStudy.getMatrices(); + + // this is an object representation of a NeXML document + Document nexDoc = DocumentFactory.safeCreateDocument(); + + // the converter populates the NeXML document with the contents of the treebase study + NexmlDocumentConverter ndc = new NexmlDocumentConverter(tbStudy,getTaxonLabelHome(),nexDoc); + ndc.fromTreeBaseToXml(tbStudy); // here is where the conversion happens + + // these are the NeXML matrices that were created from the study + List<Matrix<?>> nexMatrices = nexDoc.getMatrices(); + + // there most be more than zero matrices because every treebase study has at least one matrix + Assert.assertTrue(nexMatrices.size() != 0 ); + + // now we're going to match up the NeXML matrices with their equivalent treebase ones + for ( Matrix<?> nexMatrix : nexMatrices ) { + + // the xml id is the same as the primary key of the equivalent matrix stored by treebase + String nexId = nexMatrix.getId(); + boolean foundEquivalentMatrix = false; + + // iterate over all treebase matrices for the study + for ( org.cipres.treebase.domain.matrix.Matrix tbMatrix : tbMatrices ) { + String tbId = "M" + tbMatrix.getId(); + + // if true, the matrices are equivalent + if ( nexId.equals(tbId) ) { + foundEquivalentMatrix = true; + Assert.assertTrue("NeXML matrix "+nexId+ " is one of the known subclasses", + nexMatrix instanceof CategoricalMatrix || nexMatrix instanceof MolecularMatrix || nexMatrix instanceof ContinuousMatrix); + + // we have to coerce the tbMatrix into a character matrix to get its character sets + CharacterMatrix tbCharacterMatrix = (CharacterMatrix)tbMatrix; + Set<CharSet> tbCharSets = tbCharacterMatrix.getCharSets(); + + // a treebase matrix has zero or more character sets, we must iterate over them + for ( CharSet tbCharSet : tbCharSets ) { + + // the coordinates of the character set are defined by a collection of column ranges that we iterate over + Collection<ColumnRange> tbColumnRanges = tbCharSet.getColumns(tbCharacterMatrix); + + for ( ColumnRange tbColumnRange : tbColumnRanges ) { + + // these are the beginning and end of the range + int tbStart = tbColumnRange.getStartColIndex(); + int tbStop = tbColumnRange.getEndColIndex(); + + // this is how we increment from beginning to end. This number is probably either null, for a + // contiguous range, or perhaps 3 for codon positions + int tbInc = 1; + + // need to do this to prevent nullpointerexceptions + if ( null != tbColumnRange.getRepeatInterval()) { + + tbInc = tbColumnRange.getRepeatInterval(); + } + // this is how we create the equivalent nexml character set + Subset nexSubset = nexMatrix.createSubset(tbCharSet.getLabel()); + + //get names of TreeBASE and NeXML character set + String tbCharSetName = tbCharSet.getLabel(); + String nexCharSetName = nexSubset.getLabel(); + + //verify that the names are the same + Assert.assertTrue(tbCharSetName.equals(nexCharSetName)); + + // we have to assign character objects to the subset. Here we get the full list + List<org.nexml.model.Character> nexCharacters = nexMatrix.getCharacters(); + + // now we iterate over the coordinates and assign the nexml characters to the set + //and verify coordinates of TreeBASE characterset and nexml characterset + //are the same + for ( int i = tbStart; i <= tbStop; i += tbInc ) { + nexSubset.addThing(nexCharacters.get(i)); + + //declare coordinate index + int nexCharSetCoordinate = nexCharacters.indexOf(nexCharacters.get(i)); + int tbCharSetCoordinate = tbColumnRange.getStartColIndex() + i; + + //Assert.assertTrue( nexCharSetCoordinate == tbCharSetCoordinate ); + //if (nexCharSetCoordinate == tbCharSetCoordinate){ + // System.out.println("I work"); + //} + } + } + } + } + } + } + } + /** * Return the TaxonLabelHome field. * * @return TaxonLabelHome mTaxonLabelHome This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2011-06-14 13:06:19
|
Revision: 916 http://treebase.svn.sourceforge.net/treebase/?rev=916&view=rev Author: rvos Date: 2011-06-14 13:06:13 +0000 (Tue, 14 Jun 2011) Log Message: ----------- Offset was added twice. Modified Paths: -------------- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-13 16:47:34 UTC (rev 915) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-14 13:06:13 UTC (rev 916) @@ -161,7 +161,6 @@ // the xml id is the same as the primary key of the equivalent matrix stored by treebase String nexId = nexMatrix.getId(); - boolean foundEquivalentMatrix = false; // iterate over all treebase matrices for the study for ( org.cipres.treebase.domain.matrix.Matrix tbMatrix : tbMatrices ) { @@ -169,7 +168,6 @@ // if true, the matrices are equivalent if ( nexId.equals(tbId) ) { - foundEquivalentMatrix = true; Assert.assertTrue("NeXML matrix "+nexId+ " is one of the known subclasses", nexMatrix instanceof CategoricalMatrix || nexMatrix instanceof MolecularMatrix || nexMatrix instanceof ContinuousMatrix); @@ -219,12 +217,8 @@ //declare coordinate index int nexCharSetCoordinate = nexCharacters.indexOf(nexCharacters.get(i)); - int tbCharSetCoordinate = tbColumnRange.getStartColIndex() + i; - - //Assert.assertTrue( nexCharSetCoordinate == tbCharSetCoordinate ); - //if (nexCharSetCoordinate == tbCharSetCoordinate){ - // System.out.println("I work"); - //} + int tbCharSetCoordinate = i; // you added the offset twice + Assert.assertTrue( nexCharSetCoordinate == tbCharSetCoordinate ); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lol...@us...> - 2011-06-16 02:13:52
|
Revision: 918 http://treebase.svn.sourceforge.net/treebase/?rev=918&view=rev Author: loloyohe Date: 2011-06-16 02:13:46 +0000 (Thu, 16 Jun 2011) Log Message: ----------- Ensures coordinates in Nexml matrix and treebase matrix are equal. Checks if there are cases in which there are studies with no character sets. Still need to test with studies that have no associated char sets though. Modified Paths: -------------- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-14 19:14:38 UTC (rev 917) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-16 02:13:46 UTC (rev 918) @@ -135,54 +135,56 @@ if (logger.isInfoEnabled()) { logger.info("Running Test: " + testName); } - long studyId = 2000; + long studyId = 794; // this is the full study as it is stored by the database Study tbStudy = (Study)loadObject(Study.class, studyId); - // these are the character state matrices that are part of the study - Set<org.cipres.treebase.domain.matrix.Matrix> tbMatrices = tbStudy.getMatrices(); + //check if study has character state matrices exist + if (tbStudy.getMatrices() != null) { + // these are the character state matrices that are part of the study + Set<org.cipres.treebase.domain.matrix.Matrix> tbMatrices = tbStudy.getMatrices(); - // this is an object representation of a NeXML document - Document nexDoc = DocumentFactory.safeCreateDocument(); + // this is an object representation of a NeXML document + Document nexDoc = DocumentFactory.safeCreateDocument(); - // the converter populates the NeXML document with the contents of the treebase study - NexmlDocumentConverter ndc = new NexmlDocumentConverter(tbStudy,getTaxonLabelHome(),nexDoc); - ndc.fromTreeBaseToXml(tbStudy); // here is where the conversion happens + // the converter populates the NeXML document with the contents of the treebase study + NexmlDocumentConverter ndc = new NexmlDocumentConverter(tbStudy,getTaxonLabelHome(),nexDoc); + ndc.fromTreeBaseToXml(tbStudy); // here is where the conversion happens - // these are the NeXML matrices that were created from the study - List<Matrix<?>> nexMatrices = nexDoc.getMatrices(); + // these are the NeXML matrices that were created from the study + List<Matrix<?>> nexMatrices = nexDoc.getMatrices(); - // there most be more than zero matrices because every treebase study has at least one matrix - Assert.assertTrue(nexMatrices.size() != 0 ); + // there most be more than zero matrices because every treebase study has at least one matrix + Assert.assertTrue(nexMatrices.size() != 0 ); - // now we're going to match up the NeXML matrices with their equivalent treebase ones - for ( Matrix<?> nexMatrix : nexMatrices ) { + // now we're going to match up the NeXML matrices with their equivalent treebase ones + for ( Matrix<?> nexMatrix : nexMatrices ) { - // the xml id is the same as the primary key of the equivalent matrix stored by treebase - String nexId = nexMatrix.getId(); + // the xml id is the same as the primary key of the equivalent matrix stored by treebase + String nexId = nexMatrix.getId(); - // iterate over all treebase matrices for the study - for ( org.cipres.treebase.domain.matrix.Matrix tbMatrix : tbMatrices ) { - String tbId = "M" + tbMatrix.getId(); + // iterate over all treebase matrices for the study + for ( org.cipres.treebase.domain.matrix.Matrix tbMatrix : tbMatrices ) { + String tbId = "M" + tbMatrix.getId(); - // if true, the matrices are equivalent - if ( nexId.equals(tbId) ) { - Assert.assertTrue("NeXML matrix "+nexId+ " is one of the known subclasses", + // if true, the matrices are equivalent + if ( nexId.equals(tbId) ) { + Assert.assertTrue("NeXML matrix "+nexId+ " is one of the known subclasses", nexMatrix instanceof CategoricalMatrix || nexMatrix instanceof MolecularMatrix || nexMatrix instanceof ContinuousMatrix); - // we have to coerce the tbMatrix into a character matrix to get its character sets - CharacterMatrix tbCharacterMatrix = (CharacterMatrix)tbMatrix; - Set<CharSet> tbCharSets = tbCharacterMatrix.getCharSets(); + // we have to coerce the tbMatrix into a character matrix to get its character sets + CharacterMatrix tbCharacterMatrix = (CharacterMatrix)tbMatrix; + Set<CharSet> tbCharSets = tbCharacterMatrix.getCharSets(); - // a treebase matrix has zero or more character sets, we must iterate over them - for ( CharSet tbCharSet : tbCharSets ) { + // a treebase matrix has zero or more character sets, we must iterate over them + for ( CharSet tbCharSet : tbCharSets ) { - // the coordinates of the character set are defined by a collection of column ranges that we iterate over - Collection<ColumnRange> tbColumnRanges = tbCharSet.getColumns(tbCharacterMatrix); + // the coordinates of the character set are defined by a collection of column ranges that we iterate over + Collection<ColumnRange> tbColumnRanges = tbCharSet.getColumns(tbCharacterMatrix); + + for ( ColumnRange tbColumnRange : tbColumnRanges ) { - for ( ColumnRange tbColumnRange : tbColumnRanges ) { - // these are the beginning and end of the range int tbStart = tbColumnRange.getStartColIndex(); int tbStop = tbColumnRange.getEndColIndex(); @@ -217,14 +219,18 @@ //declare coordinate index int nexCharSetCoordinate = nexCharacters.indexOf(nexCharacters.get(i)); - int tbCharSetCoordinate = i; // you added the offset twice + int tbCharSetCoordinate = i; Assert.assertTrue( nexCharSetCoordinate == tbCharSetCoordinate ); } + } } } } } } + else { + System.out.println("This study has no associated character sets!"); + } } /** * Return the TaxonLabelHome field. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lol...@us...> - 2011-06-16 20:52:29
|
Revision: 919 http://treebase.svn.sourceforge.net/treebase/?rev=919&view=rev Author: loloyohe Date: 2011-06-16 20:52:22 +0000 (Thu, 16 Jun 2011) Log Message: ----------- NexmlMatrixConverterTest ensures that if there character sets are associated with the study of interest. The previous commit only checked if matrices were associated with the study. This is tested with a study that has matrices but not associated character sets. Modified Paths: -------------- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-16 02:13:46 UTC (rev 918) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-16 20:52:22 UTC (rev 919) @@ -135,48 +135,46 @@ if (logger.isInfoEnabled()) { logger.info("Running Test: " + testName); } - long studyId = 794; + long studyId = 1787; // this is the full study as it is stored by the database Study tbStudy = (Study)loadObject(Study.class, studyId); - //check if study has character state matrices exist - if (tbStudy.getMatrices() != null) { - // these are the character state matrices that are part of the study - Set<org.cipres.treebase.domain.matrix.Matrix> tbMatrices = tbStudy.getMatrices(); + // these are the character state matrices that are part of the study + Set<org.cipres.treebase.domain.matrix.Matrix> tbMatrices = tbStudy.getMatrices(); - // this is an object representation of a NeXML document - Document nexDoc = DocumentFactory.safeCreateDocument(); + // this is an object representation of a NeXML document + Document nexDoc = DocumentFactory.safeCreateDocument(); - // the converter populates the NeXML document with the contents of the treebase study - NexmlDocumentConverter ndc = new NexmlDocumentConverter(tbStudy,getTaxonLabelHome(),nexDoc); - ndc.fromTreeBaseToXml(tbStudy); // here is where the conversion happens + // the converter populates the NeXML document with the contents of the treebase study + NexmlDocumentConverter ndc = new NexmlDocumentConverter(tbStudy,getTaxonLabelHome(),nexDoc); + ndc.fromTreeBaseToXml(tbStudy); // here is where the conversion happens - // these are the NeXML matrices that were created from the study - List<Matrix<?>> nexMatrices = nexDoc.getMatrices(); + // these are the NeXML matrices that were created from the study + List<Matrix<?>> nexMatrices = nexDoc.getMatrices(); - // there most be more than zero matrices because every treebase study has at least one matrix - Assert.assertTrue(nexMatrices.size() != 0 ); + // there most be more than zero matrices because every treebase study has at least one matrix + Assert.assertTrue(nexMatrices.size() != 0 ); - // now we're going to match up the NeXML matrices with their equivalent treebase ones - for ( Matrix<?> nexMatrix : nexMatrices ) { + // now we're going to match up the NeXML matrices with their equivalent treebase ones + for ( Matrix<?> nexMatrix : nexMatrices ) { - // the xml id is the same as the primary key of the equivalent matrix stored by treebase - String nexId = nexMatrix.getId(); + // the xml id is the same as the primary key of the equivalent matrix stored by treebase + String nexId = nexMatrix.getId(); - // iterate over all treebase matrices for the study - for ( org.cipres.treebase.domain.matrix.Matrix tbMatrix : tbMatrices ) { - String tbId = "M" + tbMatrix.getId(); + // iterate over all treebase matrices for the study + for ( org.cipres.treebase.domain.matrix.Matrix tbMatrix : tbMatrices ) { + String tbId = "M" + tbMatrix.getId(); - // if true, the matrices are equivalent - if ( nexId.equals(tbId) ) { - Assert.assertTrue("NeXML matrix "+nexId+ " is one of the known subclasses", - nexMatrix instanceof CategoricalMatrix || nexMatrix instanceof MolecularMatrix || nexMatrix instanceof ContinuousMatrix); + // if true, the matrices are equivalent + if ( nexId.equals(tbId) ) { + Assert.assertTrue("NeXML matrix "+nexId+ " is one of the known subclasses", + nexMatrix instanceof CategoricalMatrix || nexMatrix instanceof MolecularMatrix || nexMatrix instanceof ContinuousMatrix); - // we have to coerce the tbMatrix into a character matrix to get its character sets - CharacterMatrix tbCharacterMatrix = (CharacterMatrix)tbMatrix; - Set<CharSet> tbCharSets = tbCharacterMatrix.getCharSets(); - + // we have to coerce the tbMatrix into a character matrix to get its character sets + CharacterMatrix tbCharacterMatrix = (CharacterMatrix)tbMatrix; + Set<CharSet> tbCharSets = tbCharacterMatrix.getCharSets(); + if (tbCharSets.isEmpty() != true) { // a treebase matrix has zero or more character sets, we must iterate over them for ( CharSet tbCharSet : tbCharSets ) { @@ -225,12 +223,13 @@ } } } + else { + System.out.println("This study has no associated character sets!"); + } } } } - else { - System.out.println("This study has no associated character sets!"); - } + } /** * Return the TaxonLabelHome field. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2011-06-17 14:00:51
|
Revision: 921 http://treebase.svn.sourceforge.net/treebase/?rev=921&view=rev Author: rvos Date: 2011-06-17 14:00:40 +0000 (Fri, 17 Jun 2011) Log Message: ----------- If the NexmlMatrixConverter (so NOT this test class) functions correctly, it must have now implemented the logic from testNexmlMatrixConverter so that the tests in testNexmlMatrixCharSets. Modified Paths: -------------- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-17 02:28:54 UTC (rev 920) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-17 14:00:40 UTC (rev 921) @@ -10,6 +10,7 @@ import org.cipres.treebase.domain.matrix.CharSet; import org.cipres.treebase.domain.matrix.CharacterMatrix; import org.cipres.treebase.domain.matrix.ColumnRange; +import org.cipres.treebase.domain.matrix.PhyloChar; import org.cipres.treebase.domain.nexus.nexml.NexmlDocumentConverter; import org.cipres.treebase.domain.study.Study; import org.cipres.treebase.domain.taxon.TaxonLabelHome; @@ -135,7 +136,7 @@ if (logger.isInfoEnabled()) { logger.info("Running Test: " + testName); } - long studyId = 1787; + long studyId = 794; // this is the full study as it is stored by the database Study tbStudy = (Study)loadObject(Study.class, studyId); @@ -174,9 +175,18 @@ // we have to coerce the tbMatrix into a character matrix to get its character sets CharacterMatrix tbCharacterMatrix = (CharacterMatrix)tbMatrix; Set<CharSet> tbCharSets = tbCharacterMatrix.getCharSets(); + + // NexmlMatrixConverter must have assigned character objects to zero or more subsets. Here we get the full list of characters + List<org.nexml.model.Character> nexCharacters = nexMatrix.getCharacters(); + Assert.assertEquals("The number of characters in the NeXML matrix must match that of the TreeBASE matrix", (Integer)tbMatrix.getnChar(), (Integer)nexCharacters.size()); + if (tbCharSets.isEmpty() != true) { // a treebase matrix has zero or more character sets, we must iterate over them for ( CharSet tbCharSet : tbCharSets ) { + + // this is how we fetch the equivalent nexml character set + Subset nexSubset = nexMatrix.getSubset(tbCharSet.getLabel()); + Assert.assertNotNull("If NexmlMatrixConverter works correctly, a Subset is returned", nexSubset); // the coordinates of the character set are defined by a collection of column ranges that we iterate over Collection<ColumnRange> tbColumnRanges = tbCharSet.getColumns(tbCharacterMatrix); @@ -196,30 +206,35 @@ tbInc = tbColumnRange.getRepeatInterval(); } - // this is how we create the equivalent nexml character set - Subset nexSubset = nexMatrix.createSubset(tbCharSet.getLabel()); + + // The NexmlMatrixConverter should have created a Subset for each tbCharSet + if ( null != nexSubset ) { - //get names of TreeBASE and NeXML character set - String tbCharSetName = tbCharSet.getLabel(); - String nexCharSetName = nexSubset.getLabel(); - - //verify that the names are the same - Assert.assertTrue(tbCharSetName.equals(nexCharSetName)); - - // we have to assign character objects to the subset. Here we get the full list - List<org.nexml.model.Character> nexCharacters = nexMatrix.getCharacters(); - - // now we iterate over the coordinates and assign the nexml characters to the set - //and verify coordinates of TreeBASE characterset and nexml characterset - //are the same - for ( int i = tbStart; i <= tbStop; i += tbInc ) { - nexSubset.addThing(nexCharacters.get(i)); - - //declare coordinate index - int nexCharSetCoordinate = nexCharacters.indexOf(nexCharacters.get(i)); - int tbCharSetCoordinate = i; - Assert.assertTrue( nexCharSetCoordinate == tbCharSetCoordinate ); + //get names of TreeBASE and NeXML character set + String tbCharSetName = tbCharSet.getLabel(); + String nexCharSetName = nexSubset.getLabel(); + + //verify that the names are the same + Assert.assertTrue("The NeXML character set must have copied the label of the TreeBASE character set",tbCharSetName.equals(nexCharSetName)); + + // now we iterate over the coordinates in this column range + //and verify whether correct character objects are returned + for ( int i = tbStart; i <= tbStop; i += tbInc ) { + + // get the nexml character that should have been created + org.nexml.model.Character nexCharacter = nexCharacters.get(i); + Assert.assertNotNull("The NeXML Character should not be null if there as an index into it in this set", nexCharacter); + Assert.assertTrue("The Subset should contain the character at index i", nexSubset.containsThing(nexCharacter)); + + //get the treebase character for the index in this column range + PhyloChar tbCharacter = tbCharacterMatrix.getCharacter(i); + Assert.assertNotNull("The TreeBASE PhyloChar should not be null if there as an index into it in this set", tbCharacter); + Assert.assertEquals("If the TreeBASE character has a label, then the NeXML character's label should match it", tbCharacter.getLabel(), nexCharacter.getLabel()); + } } + else { + System.out.println("NexmlMatrixConverter failed to create a Subset"); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2011-06-17 15:30:27
|
Revision: 922 http://treebase.svn.sourceforge.net/treebase/?rev=922&view=rev Author: rvos Date: 2011-06-17 15:30:21 +0000 (Fri, 17 Jun 2011) Log Message: ----------- Slight re-ordering. Modified Paths: -------------- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-17 14:00:40 UTC (rev 921) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-06-17 15:30:21 UTC (rev 922) @@ -188,6 +188,13 @@ Subset nexSubset = nexMatrix.getSubset(tbCharSet.getLabel()); Assert.assertNotNull("If NexmlMatrixConverter works correctly, a Subset is returned", nexSubset); + //get names of TreeBASE and NeXML character set + String tbCharSetName = tbCharSet.getLabel(); + String nexCharSetName = nexSubset.getLabel(); + + //verify that the names are the same + Assert.assertEquals("The NeXML character set must have copied the label of the TreeBASE character set",tbCharSetName,nexCharSetName); + // the coordinates of the character set are defined by a collection of column ranges that we iterate over Collection<ColumnRange> tbColumnRanges = tbCharSet.getColumns(tbCharacterMatrix); @@ -208,14 +215,7 @@ } // The NexmlMatrixConverter should have created a Subset for each tbCharSet - if ( null != nexSubset ) { - - //get names of TreeBASE and NeXML character set - String tbCharSetName = tbCharSet.getLabel(); - String nexCharSetName = nexSubset.getLabel(); - - //verify that the names are the same - Assert.assertTrue("The NeXML character set must have copied the label of the TreeBASE character set",tbCharSetName.equals(nexCharSetName)); + if ( null != nexSubset ) { // now we iterate over the coordinates in this column range //and verify whether correct character objects are returned This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lol...@us...> - 2011-07-20 14:54:51
|
Revision: 933 http://treebase.svn.sourceforge.net/treebase/?rev=933&view=rev Author: loloyohe Date: 2011-07-20 14:54:45 +0000 (Wed, 20 Jul 2011) Log Message: ----------- Wrote unit test to help track down issue of bug #3303002. Unit test added was testNexmlEmptyMatrix() Modified Paths: -------------- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-07-19 21:21:03 UTC (rev 932) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-07-20 14:54:45 UTC (rev 933) @@ -6,25 +6,47 @@ import junit.framework.Assert; +import mesquite.lib.Annotatable; + import org.cipres.treebase.dao.AbstractDAOTest; +import org.cipres.treebase.dao.jdbc.DiscreteMatrixElementJDBC; +import org.cipres.treebase.dao.jdbc.MatrixColumnJDBC; +import org.cipres.treebase.domain.Annotation; import org.cipres.treebase.domain.matrix.CharSet; import org.cipres.treebase.domain.matrix.CharacterMatrix; import org.cipres.treebase.domain.matrix.ColumnRange; +import org.cipres.treebase.domain.matrix.ContinuousMatrixElement; +import org.cipres.treebase.domain.matrix.DiscreteChar; +import org.cipres.treebase.domain.matrix.DiscreteMatrix; +import org.cipres.treebase.domain.matrix.DiscreteMatrixElement; +import org.cipres.treebase.domain.matrix.MatrixColumn; +import org.cipres.treebase.domain.matrix.MatrixElement; +import org.cipres.treebase.domain.matrix.MatrixRow; import org.cipres.treebase.domain.matrix.PhyloChar; +import org.cipres.treebase.domain.matrix.RowSegment; import org.cipres.treebase.domain.nexus.nexml.NexmlDocumentConverter; +import org.cipres.treebase.domain.nexus.nexml.NexmlObjectConverter; import org.cipres.treebase.domain.study.Study; import org.cipres.treebase.domain.taxon.TaxonLabelHome; import org.nexml.model.CategoricalMatrix; +import org.nexml.model.Character; +import org.nexml.model.CharacterState; import org.nexml.model.ContinuousMatrix; import org.nexml.model.DocumentFactory; import org.nexml.model.Document; import org.nexml.model.Matrix; +import org.nexml.model.MatrixCell; import org.nexml.model.MolecularMatrix; +import org.nexml.model.OTU; +import org.nexml.model.OTUs; import org.nexml.model.Subset; public class NexmlMatrixConverterTest extends AbstractDAOTest { private TaxonLabelHome mTaxonLabelHome; + private static final int MAX_GRANULAR_NCHAR = 1000; + private static final int MAX_GRANULAR_NTAX = 30; + /** * Test for {@link org.cipres.treebase.domain.nexus.nexml.NexmlMatrixConverter#fromTreeBaseToXml(CharacterMatrix)}. * Finds an equivalent, created NexmlMatrix within a NeXML document to go with the matrix @@ -52,6 +74,7 @@ NexmlDocumentConverter ndc = new NexmlDocumentConverter(tbStudy,getTaxonLabelHome(),nexDoc); ndc.fromTreeBaseToXml(tbStudy); // here is where the conversion happens + // these are the NeXML matrices that were created from the study List<Matrix<?>> nexMatrices = nexDoc.getMatrices(); @@ -125,7 +148,87 @@ } } + + /** + * Test for {@link org.cipres.treebase.domain.nexus.nexml.NexmlMatrixConverter#}. + * This verfies that all row-segment annotation are expressed for a particular study. + */ + public void testNexmlEmptyMatrix() { + String testName = "testNexmlEmptyMatrix()"; + //signal beginning of test + if (logger.isInfoEnabled()) { + logger.info("Running Test: " + testName); + } + + long studyId = 586; //this study is known to output an empty Nexml matrix + + // this is the full study as it is stored by the database + Study tbStudy = (Study)loadObject(Study.class, studyId); + + // these are the character state matrices that are part of the study + Set<org.cipres.treebase.domain.matrix.Matrix> tbMatrices = tbStudy.getMatrices(); + + + // this is an object representation of a NeXML document + Document nexDoc = DocumentFactory.safeCreateDocument(); + + // the converter populates the NeXML document with the contents of the treebase study + NexmlDocumentConverter ndc = new NexmlDocumentConverter(tbStudy,getTaxonLabelHome(),nexDoc); + + ndc.fromTreeBaseToXml(tbStudy); // here is where the conversion happens + + + // these are the NeXML matrices that were created from the study + List<Matrix<?>> nexMatrices = nexDoc.getMatrices(); + + //returns true if matrix contains no elements + boolean nexTest = nexMatrices.isEmpty(); + + //should be false if the matrix contains elements + Assert.assertFalse(nexTest); + + // there most be more than zero matrices because every treebase study has at least one matrix + Assert.assertTrue(nexMatrices.size() != 0 ); + + // now we're going to match up the NeXML matrices with their equivalent treebase ones + for ( Matrix<?> nexMatrix : nexMatrices ) { + + // the xml id is the same as the primary key of the equivalent matrix stored by treebase + String nexId = nexMatrix.getId(); + + for ( org.cipres.treebase.domain.matrix.Matrix tbMatrix : tbMatrices ) { + String tbId = "M" + tbMatrix.getId(); + // if true, the matrices are equivalent + + System.out.println(tbMatrix.getClass()); + System.out.println(nexMatrix.getClass().toString() + "hi"); + + if ( nexId.equals(tbId) ) { + Assert.assertTrue("NeXML matrix "+nexId+ " is one of the known subclasses", + nexMatrix instanceof CategoricalMatrix || nexMatrix instanceof MolecularMatrix || nexMatrix instanceof ContinuousMatrix); + + Assert.assertNotNull(nexMatrix); + Assert.assertNotNull(tbMatrix); + + + for ( MatrixRow tbRow : ((CharacterMatrix) tbMatrix).getRowsReadOnly() ) { + System.out.println (tbRow.buildElementAsString()); + } + } + //print out the rows of the nexml matrix to see if there are sequences + + } + + } + + //System.out.println(nexDoc.getXmlString()); + } + + + + + /** * Test for {@link org.cipres.treebase.domain.nexus.nexml.NexmlMatrixConverter#}. * It verifies that NexmlCharSets have the same name and coordinates as those in the * TreeBASE matrix. @@ -166,7 +269,7 @@ // iterate over all treebase matrices for the study for ( org.cipres.treebase.domain.matrix.Matrix tbMatrix : tbMatrices ) { String tbId = "M" + tbMatrix.getId(); - + // if true, the matrices are equivalent if ( nexId.equals(tbId) ) { Assert.assertTrue("NeXML matrix "+nexId+ " is one of the known subclasses", @@ -191,7 +294,7 @@ //get names of TreeBASE and NeXML character set String tbCharSetName = tbCharSet.getLabel(); String nexCharSetName = nexSubset.getLabel(); - + //verify that the names are the same Assert.assertEquals("The NeXML character set must have copied the label of the TreeBASE character set",tbCharSetName,nexCharSetName); @@ -230,6 +333,7 @@ PhyloChar tbCharacter = tbCharacterMatrix.getCharacter(i); Assert.assertNotNull("The TreeBASE PhyloChar should not be null if there as an index into it in this set", tbCharacter); Assert.assertEquals("If the TreeBASE character has a label, then the NeXML character's label should match it", tbCharacter.getLabel(), nexCharacter.getLabel()); + } } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lol...@us...> - 2011-08-11 19:44:47
|
Revision: 936 http://treebase.svn.sourceforge.net/treebase/?rev=936&view=rev Author: loloyohe Date: 2011-08-11 19:44:41 +0000 (Thu, 11 Aug 2011) Log Message: ----------- Added testNexmlEmptyMatrix() in response to bug#3303002 in which some matrices of studies were not returned in nexml. Modified Paths: -------------- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-08-01 20:18:08 UTC (rev 935) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java 2011-08-11 19:44:41 UTC (rev 936) @@ -17,6 +17,7 @@ import org.cipres.treebase.domain.matrix.ColumnRange; import org.cipres.treebase.domain.matrix.ContinuousMatrixElement; import org.cipres.treebase.domain.matrix.DiscreteChar; +import org.cipres.treebase.domain.matrix.DiscreteCharState; import org.cipres.treebase.domain.matrix.DiscreteMatrix; import org.cipres.treebase.domain.matrix.DiscreteMatrixElement; import org.cipres.treebase.domain.matrix.MatrixColumn; @@ -152,7 +153,11 @@ /** * Test for {@link org.cipres.treebase.domain.nexus.nexml.NexmlMatrixConverter#}. - * This verfies that all row-segment annotation are expressed for a particular study. + * This ensures that a matrix prints for a DiscreteMatrix matrices that + * suit the condition : if ( characterList.size() <= MAX_GRANULAR_NCHAR && xmlOTUs.getAllOTUs().size() <= MAX_GRANULAR_NTAX ) + * in populateXmlMatrix() of NexmlMatrixConverter. + * + * This is in response to bug #3303002 */ public void testNexmlEmptyMatrix() { String testName = "testNexmlEmptyMatrix()"; @@ -191,38 +196,57 @@ // there most be more than zero matrices because every treebase study has at least one matrix Assert.assertTrue(nexMatrices.size() != 0 ); + // now we're going to match up the NeXML matrices with their equivalent treebase ones for ( Matrix<?> nexMatrix : nexMatrices ) { // the xml id is the same as the primary key of the equivalent matrix stored by treebase String nexId = nexMatrix.getId(); + for ( org.cipres.treebase.domain.matrix.Matrix tbMatrix : tbMatrices ) { String tbId = "M" + tbMatrix.getId(); // if true, the matrices are equivalent + System.out.println(tbId); + int otuIndex = 0; + for ( MatrixRow tbRow : ((CharacterMatrix) tbMatrix).getRowsReadOnly() ) { + OTUs xmlOTUs = nexMatrix.getOTUs(); + + //need to make an OTU list because getOTUByID cannot be is private + List<OTU> xmlOTUList = xmlOTUs.getAllOTUs();//getOTUById(xmlOTUs, tbRow.getTaxonLabel().getId()); + OTU xmlOTU = xmlOTUList.get(otuIndex); //get xmlOTUs + List<org.nexml.model.Character> characterList = nexMatrix.getCharacters(); - System.out.println(tbMatrix.getClass()); - System.out.println(nexMatrix.getClass().toString() + "hi"); + int charIndex = 0; + if ( characterList.size() <= MAX_GRANULAR_NCHAR && xmlOTUs.getAllOTUs().size() <= MAX_GRANULAR_NTAX ) { + + //tbColumn is not used, but is in the actual NexmlMatrixConverter class. + //it is necessary so the for loop does not crash + for ( MatrixColumn tbColumn : ((CharacterMatrix)tbMatrix).getColumns() ) { + + //this builds the matrix + String string = tbRow.buildElementAsString(); + nexMatrix.setSeq(string, xmlOTU); + + //in NexmlMatrixConverter attachTreeBASEID would be called here. Not necessary for the test. + } + charIndex++; + otuIndex++; + + } if ( nexId.equals(tbId) ) { Assert.assertTrue("NeXML matrix "+nexId+ " is one of the known subclasses", nexMatrix instanceof CategoricalMatrix || nexMatrix instanceof MolecularMatrix || nexMatrix instanceof ContinuousMatrix); - Assert.assertNotNull(nexMatrix); Assert.assertNotNull(tbMatrix); - - - for ( MatrixRow tbRow : ((CharacterMatrix) tbMatrix).getRowsReadOnly() ) { - System.out.println (tbRow.buildElementAsString()); - } + } - //print out the rows of the nexml matrix to see if there are sequences + } } - } - - //System.out.println(nexDoc.getXmlString()); + System.out.println(nexDoc.getXmlString()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |