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. |