From: <yo...@us...> - 2009-11-06 16:36:20
|
Revision: 257 http://treebase.svn.sourceforge.net/treebase/?rev=257&view=rev Author: youjun Date: 2009-11-06 16:36:12 +0000 (Fri, 06 Nov 2009) Log Message: ----------- typo-proof, add a test on SubmissionDAOTest Modified Paths: -------------- trunk/treebase-core/src/main/java/org/cipres/treebase/dao/study/SubmissionDAO.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/SubmissionHome.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/SubmissionService.java trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/SubmissionServiceImpl.java trunk/treebase-core/src/test/java/org/cipres/treebase/dao/study/SubmissionDAOTest.java Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/dao/study/SubmissionDAO.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/dao/study/SubmissionDAO.java 2009-11-05 20:30:13 UTC (rev 256) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/dao/study/SubmissionDAO.java 2009-11-06 16:36:12 UTC (rev 257) @@ -184,12 +184,12 @@ return (Submission) q.uniqueResult(); } - public Collection<Submission> findByCreateDateRange(Date from, Date util) { + public Collection<Submission> findByCreateDateRange(Date from, Date until) { Query q = getSession().createQuery( - "from Submission as sub where sub.createDate between :begin and :end"); + "from Submission where createdate between :begin and :end"); q.setDate("begin", from); - q.setDate("end", util); + q.setDate("end", until); return q.list(); } Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/SubmissionHome.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/SubmissionHome.java 2009-11-05 20:30:13 UTC (rev 256) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/SubmissionHome.java 2009-11-06 16:36:12 UTC (rev 257) @@ -71,5 +71,5 @@ Collection<Submission> findByPublishedState(); Collection<Submission> findByInProgressState(); - Collection<Submission> findByCreateDateRange(Date from, Date util); + Collection<Submission> findByCreateDateRange(Date from, Date until); } Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/SubmissionService.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/SubmissionService.java 2009-11-05 20:30:13 UTC (rev 256) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/SubmissionService.java 2009-11-06 16:36:12 UTC (rev 257) @@ -41,7 +41,7 @@ Collection<Submission> findPublishedSubmissions(); - Collection<Submission> findSubmissionByCreateDateRange(Date from, Date util); + Collection<Submission> findSubmissionByCreateDateRange(Date from, Date until); /** * Create a submission, which associates with a new study. A submitter is required. * Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/SubmissionServiceImpl.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/SubmissionServiceImpl.java 2009-11-05 20:30:13 UTC (rev 256) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/SubmissionServiceImpl.java 2009-11-06 16:36:12 UTC (rev 257) @@ -929,10 +929,10 @@ } - public Collection<Submission> findSubmissionByCreateDateRange(Date from, Date util) { + public Collection<Submission> findSubmissionByCreateDateRange(Date from, Date until) { - return getSubmissionHome().findByCreateDateRange(from, util); + return getSubmissionHome().findByCreateDateRange(from, until); } Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/dao/study/SubmissionDAOTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/dao/study/SubmissionDAOTest.java 2009-11-05 20:30:13 UTC (rev 256) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/dao/study/SubmissionDAOTest.java 2009-11-06 16:36:12 UTC (rev 257) @@ -1,6 +1,8 @@ package org.cipres.treebase.dao.study; import java.util.Collection; +import java.util.Date; +import java.util.GregorianCalendar; import org.cipres.treebase.dao.AbstractDAOTest; import org.cipres.treebase.domain.matrix.Matrix; @@ -166,6 +168,23 @@ } } + public void testFindByCreateDateRange() { + String testName = "testFindByCreateDateRange"; + if (logger.isInfoEnabled()) { + logger.info("\n\t\tRunning Test: " + testName); + } + + Date from = (new GregorianCalendar(2006,1,1)).getTime(); + Date until = (new GregorianCalendar(2007,1,1)).getTime(); + + Collection<Submission> s = getFixture().findByCreateDateRange(from, until); + assertTrue(s.size() > 0); + if (logger.isInfoEnabled()) { + logger.info("\n\t\tRunning Test: found " + s.size()); + } + } + + } /* This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yo...@us...> - 2010-01-07 19:20:25
|
Revision: 408 http://treebase.svn.sourceforge.net/treebase/?rev=408&view=rev Author: youjun Date: 2010-01-07 19:20:18 +0000 (Thu, 07 Jan 2010) Log Message: ----------- change test record that no longer exist etc Modified Paths: -------------- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/tree/PhyloTree.java trunk/treebase-core/src/test/java/org/cipres/treebase/service/study/StudyServiceImplTest.java trunk/treebase-core/src/test/java/org/cipres/treebase/service/tree/PhyloTreeServiceImplTest.java Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/tree/PhyloTree.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/tree/PhyloTree.java 2010-01-06 21:28:32 UTC (rev 407) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/tree/PhyloTree.java 2010-01-07 19:20:18 UTC (rev 408) @@ -751,6 +751,7 @@ */ // added in implementation where the number of tips is calculated and // stored if the internal boxed member mNtax is null (i.e. unassigned) + @Column(name = "ntax") public Integer getnTax() { if ( mNtax == null ) { int ntax = 0; Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/service/study/StudyServiceImplTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/service/study/StudyServiceImplTest.java 2010-01-06 21:28:32 UTC (rev 407) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/service/study/StudyServiceImplTest.java 2010-01-07 19:20:18 UTC (rev 408) @@ -133,7 +133,7 @@ // Notes: this is important: why?? there are two copies of s in the same session. // how??? - //s = (Study) hibernateTemplate.merge(s); + s = (Study) hibernateTemplate.merge(s); Long studyID = s.getId(); Long citationID = c.getId(); @@ -499,7 +499,7 @@ // 1. get a valid nexus file name: String fileName = "wtset.nex"; - long studyId = 82L; + long studyId = 100L; logger.info("study id: " + studyId); assertTrue(studyId > 0); Study s = (Study) hibernateTemplate.get(Study.class, studyId); Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/service/tree/PhyloTreeServiceImplTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/service/tree/PhyloTreeServiceImplTest.java 2010-01-06 21:28:32 UTC (rev 407) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/service/tree/PhyloTreeServiceImplTest.java 2010-01-07 19:20:18 UTC (rev 408) @@ -172,7 +172,7 @@ public void testFindSomethingByRangeExpression() throws MalformedRangeExpression { Collection<PhyloTree> trees = getFixture() - .findSomethingByRangeExpression(PhyloTree.class, "nTax", "37..100"); + .findSomethingByRangeExpression(PhyloTree.class, "nTax", "37..40"); assertTrue(trees.size() > 0); for (PhyloTree tree : trees) { int n = tree.getnTax(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hs...@us...> - 2011-12-12 18:01:15
|
Revision: 1003 http://treebase.svn.sourceforge.net/treebase/?rev=1003&view=rev Author: hshyket Date: 2011-12-12 18:01:09 +0000 (Mon, 12 Dec 2011) Log Message: ----------- Fixing issue where the numbering of the translation table in the tree string was not converting properly Modified Paths: -------------- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/taxon/TaxonLabelSet.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/tree/TreeBlock.java trunk/treebase-core/src/test/java/org/cipres/treebase/domain/taxon/TaxonLabelTest.java Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/taxon/TaxonLabelSet.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/taxon/TaxonLabelSet.java 2011-12-09 16:23:11 UTC (rev 1002) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/taxon/TaxonLabelSet.java 2011-12-12 18:01:09 UTC (rev 1003) @@ -260,7 +260,7 @@ return getTitle(); } - private void sortByTaxonLabel(List<TaxonLabel> tList) + public void sortByTaxonLabel(List<TaxonLabel> tList) { java.util.Collections.sort(tList, new Comparator<TaxonLabel>() { @@ -273,4 +273,16 @@ }); } + + public void sortByTaxonLabelLength(List<TaxonLabel> tList) + { + java.util.Collections.sort(tList, new Comparator<TaxonLabel>() { + + public int compare(TaxonLabel pObject1, TaxonLabel pObject2) { + return pObject2.getTaxonLabel().length() - pObject1.getTaxonLabel().length(); + } + + }); + + } } Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/tree/TreeBlock.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/tree/TreeBlock.java 2011-12-09 16:23:11 UTC (rev 1002) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/tree/TreeBlock.java 2011-12-12 18:01:09 UTC (rev 1003) @@ -244,11 +244,18 @@ } String tmpnewick, newick = atree.getNewickString(); + List<TaxonLabel> txnlbllistclone = new ArrayList<TaxonLabel>(txnlbllist); + tlSet.sortByTaxonLabelLength(txnlbllistclone); + HashMap<String, Integer> txnOrder = new HashMap<String, Integer>(); + for (int y = 0; y < numoftxnlbls; y++) { + txnOrder.put(txnlbllist.get(y).getTaxonLabel(), y); + } for (int z = 0; z < numoftxnlbls; z++) { - String label = StringUtil.tokenize(txnlbllist.get(z).getTaxonLabel()); - tmpnewick = newick.replace(label, String.valueOf(z + 1)); + String label = StringUtil.tokenize(txnlbllistclone.get(z).getTaxonLabel()); + tmpnewick = newick.replace(label, String.valueOf(txnOrder.get(txnlbllistclone.get(z).getTaxonLabel())+1)); newick = tmpnewick; } + txnlbllistclone = null; // out.append(atree.getNewickString()); pBuilder.append(newick); pBuilder.append("\n"); Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/taxon/TaxonLabelTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/taxon/TaxonLabelTest.java 2011-12-09 16:23:11 UTC (rev 1002) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/taxon/TaxonLabelTest.java 2011-12-12 18:01:09 UTC (rev 1003) @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.List; import org.apache.log4j.Logger; import org.cipres.treebase.dao.AbstractDAOTest; @@ -112,17 +113,49 @@ } assertTrue(matricesOkay); } + + public void testTaxonLabelLengthSorting() { + int x = 0; + boolean isTaxonSorted = false; + + List<TaxonLabel> res = (List<TaxonLabel>) findHomoSapiensTL(); + LOGGER.info("Homo matrices: " + res.size() + " result(s)"); + assertNotNull(res); + TaxonLabel newTaxon = new TaxonLabel(); + newTaxon.setTaxonLabel("Homo Sapiens ABCD"); + res.add(newTaxon); + //res.get(1).setTaxonLabel("Homo Sapiens ABCD"); + TaxonLabelSet tlSet = new TaxonLabelSet(); + tlSet.sortByTaxonLabelLength(res); + + //for (TaxonLabel tLabel : res) { + for (x = 0; x < res.size(); x++) { + if (x > 0) { + if (res.get(x-1).getTaxonLabel().length() >= res.get(x).getTaxonLabel().length()) { + isTaxonSorted = true; + } + else { + LOGGER.debug("Taxon Labels are not sorted"); + isTaxonSorted = false; + break; + } + } + } + assertTrue(isTaxonSorted); + } private Collection<TaxonLabel> findHomoSapiensTL() { return getTaxonLabelHome().findByExactString("Homo sapiens"); } - + private TaxonVariant findHomoSapiensTV() { Collection<TaxonVariant> hSap = getTaxonLabelHome().findTaxonVariantByFullName("Homo sapiens"); if (hSap == null) return null; if (hSap.isEmpty()) return null; return hSap.iterator().next(); } + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2011-04-28 23:39:59
|
Revision: 815 http://treebase.svn.sourceforge.net/treebase/?rev=815&view=rev Author: rvos Date: 2011-04-28 23:39:53 +0000 (Thu, 28 Apr 2011) Log Message: ----------- Added findAll search service Modified Paths: -------------- trunk/treebase-core/src/main/java/org/cipres/treebase/service/AbstractService.java trunk/treebase-core/src/main/java/org/cipres/treebase/service/AbstractServiceImpl.java trunk/treebase-core/src/test/java/org/cipres/treebase/auxdata/AuxDataTest.java Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/service/AbstractService.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/service/AbstractService.java 2011-04-28 23:38:54 UTC (rev 814) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/service/AbstractService.java 2011-04-28 23:39:53 UTC (rev 815) @@ -100,7 +100,17 @@ String attributeName, String target); + /** + * Find all persistent objects of a certain class + * + * @param <T> + * @param T + * @return + */ + public <T extends TBPersistable> Collection<T> findAll(Class T); + + /** * Search all persistent objects of a certain class for those that contain a string in a particular attribute field. * * @param T - the class in which you want to find objects Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/service/AbstractServiceImpl.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/service/AbstractServiceImpl.java 2011-04-28 23:38:54 UTC (rev 814) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/service/AbstractServiceImpl.java 2011-04-28 23:39:53 UTC (rev 815) @@ -100,6 +100,14 @@ return findSomethingByString(T, attributeName, target, true); } + /* + * (non-Javadoc) + * @see org.cipres.treebase.service.AbstractService#findAll(java.lang.Class) + */ + public <T extends TBPersistable> Collection<T> findAll(Class T) { + return getDomainHome().findAll(T); + } + /* (non-Javadoc) * @see org.cipres.treebase.service.AbstractService#findSomethingByString(java.lang.Class, java.lang.String, java.lang.String) */ Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/auxdata/AuxDataTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/auxdata/AuxDataTest.java 2011-04-28 23:38:54 UTC (rev 814) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/auxdata/AuxDataTest.java 2011-04-28 23:39:53 UTC (rev 815) @@ -217,6 +217,11 @@ public Matrix findByTB1StudyID(String pTB1MatrixID) { // TODO Auto-generated method stub return null; + } + + public <T extends TBPersistable> Collection<T> findAll(Class T) { + // TODO Auto-generated method stub + return null; } } @@ -290,6 +295,11 @@ Boolean caseSensitive) { // TODO Auto-generated method stub return null; + } + + public <T extends TBPersistable> Collection<T> findAll(Class T) { + // TODO Auto-generated method stub + return null; } } @@ -347,6 +357,11 @@ // TODO Auto-generated method stub return null; } + + public <T extends TBPersistable> Collection<T> findAll(Class T) { + // TODO Auto-generated method stub + return null; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2011-10-13 16:26:56
|
Revision: 971 http://treebase.svn.sourceforge.net/treebase/?rev=971&view=rev Author: rvos Date: 2011-10-13 16:26:47 +0000 (Thu, 13 Oct 2011) Log Message: ----------- This refactoring splits NeXML reading and writing into separate classes and hides some more of the visibility of methods that only deal with the conversion of deeply nested objects. Modified Paths: -------------- trunk/treebase-core/src/main/java/org/cipres/treebase/dao/jdbc/ContinuousMatrixJDBC.java trunk/treebase-core/src/main/java/org/cipres/treebase/dao/jdbc/DiscreteMatrixJDBC.java trunk/treebase-core/src/main/java/org/cipres/treebase/dao/jdbc/MatrixJDBC.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlConverter.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlObjectConverter.java trunk/treebase-core/src/main/java/org/cipres/treebase/service/nexus/NexusServiceNexml.java trunk/treebase-core/src/main/java/org/cipres/treebase/service/nexus/NexusServiceRDFa.java trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlAnalysisConverterTest.java trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlMatrixConverterTest.java trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlSerializationTest.java Added Paths: ----------- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentReader.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentWriter.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixReader.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixWriter.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlOTUReader.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlOTUWriter.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockReader.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockWriter.java Removed Paths: ------------- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentConverter.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixConverter.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlOTUConverter.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockConverter.java Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/dao/jdbc/ContinuousMatrixJDBC.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/dao/jdbc/ContinuousMatrixJDBC.java 2011-10-05 17:43:48 UTC (rev 970) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/dao/jdbc/ContinuousMatrixJDBC.java 2011-10-13 16:26:47 UTC (rev 971) @@ -20,7 +20,8 @@ import org.cipres.treebase.domain.matrix.ContinuousMatrix; import org.cipres.treebase.domain.matrix.ItemDefinition; import org.cipres.treebase.domain.nexus.mesquite.MesquiteMatrixConverter; -import org.cipres.treebase.domain.nexus.nexml.NexmlMatrixConverter; +import org.cipres.treebase.domain.nexus.nexml.NexmlMatrixWriter; +import org.cipres.treebase.domain.nexus.nexml.NexmlMatrixReader; /** * Helper class for direct Matrix related SQL operations. Bypass the hibernate framework for high @@ -67,7 +68,7 @@ private org.nexml.model.ContinuousMatrix mNexmlCharacterData; - private NexmlMatrixConverter mNexmlMatrixConverter; + private NexmlMatrixWriter mNexmlMatrixConverter; // Note: currently we support only one set of item definitions for the entire matrix. // It is modeled in continuousMatrix.itemDefinitions. @@ -105,7 +106,7 @@ public ContinuousMatrixJDBC(ContinuousMatrix tbMatrix, org.nexml.model.ContinuousMatrix xmlMatrix, - NexmlMatrixConverter nexmlMatrixConverter) { + NexmlMatrixReader nexmlMatrixConverter) { this(); setCharacterMatrix(tbMatrix); setNexmlCharacterData(xmlMatrix); Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/dao/jdbc/DiscreteMatrixJDBC.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/dao/jdbc/DiscreteMatrixJDBC.java 2011-10-05 17:43:48 UTC (rev 970) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/dao/jdbc/DiscreteMatrixJDBC.java 2011-10-13 16:26:47 UTC (rev 971) @@ -23,7 +23,8 @@ import org.cipres.treebase.domain.matrix.DiscreteChar; import org.cipres.treebase.domain.matrix.DiscreteCharState; import org.cipres.treebase.domain.nexus.mesquite.MesquiteMatrixConverter; -import org.cipres.treebase.domain.nexus.nexml.NexmlMatrixConverter; +import org.cipres.treebase.domain.nexus.nexml.NexmlMatrixWriter; +import org.cipres.treebase.domain.nexus.nexml.NexmlMatrixReader; /** * Helper class for direct Matrix related SQL operations. Bypass the hibernate framework for high @@ -107,7 +108,7 @@ public DiscreteMatrixJDBC(CharacterMatrix tbMatrix, org.nexml.model.CategoricalMatrix xmlMatrix, - NexmlMatrixConverter nexmlMatrixConverter) { + NexmlMatrixReader nexmlMatrixConverter) { this(); setCharacterMatrix(tbMatrix); setNexmlCharacterData(xmlMatrix); Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/dao/jdbc/MatrixJDBC.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/dao/jdbc/MatrixJDBC.java 2011-10-05 17:43:48 UTC (rev 970) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/dao/jdbc/MatrixJDBC.java 2011-10-13 16:26:47 UTC (rev 971) @@ -19,7 +19,8 @@ import org.cipres.treebase.domain.matrix.CharacterMatrix; import org.cipres.treebase.domain.matrix.ContinuousMatrix; import org.cipres.treebase.domain.nexus.mesquite.MesquiteMatrixConverter; -import org.cipres.treebase.domain.nexus.nexml.NexmlMatrixConverter; +import org.cipres.treebase.domain.nexus.nexml.NexmlMatrixWriter; +import org.cipres.treebase.domain.nexus.nexml.NexmlMatrixReader; /** * Helper class for direct Matrix related SQL operations. Bypass the hibernate framework for high @@ -69,7 +70,7 @@ private List<MatrixColumnJDBC> mMatrixColumnJDBCs; private MesquiteMatrixConverter mMesqMatrixConverter; - private NexmlMatrixConverter mNexmlMatrixConverter; + private NexmlMatrixReader mNexmlMatrixConverter; private Matrix mNexmlCharacterData; /** @@ -295,7 +296,7 @@ } protected void setNexmlMatrixConverter( - NexmlMatrixConverter nexmlMatrixConverter) { + NexmlMatrixReader nexmlMatrixConverter) { mNexmlMatrixConverter = nexmlMatrixConverter; } Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlConverter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlConverter.java 2011-10-05 17:43:48 UTC (rev 970) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlConverter.java 2011-10-13 16:26:47 UTC (rev 971) @@ -42,13 +42,13 @@ } // Taxa - NexmlOTUConverter noc = new NexmlOTUConverter(pStudy,getTaxonLabelHome(),document); + NexmlOTUReader noc = new NexmlOTUReader(pStudy,getTaxonLabelHome(),document); for ( OTUs xmlOTUs : document.getOTUsList() ) { pDataSet.addTaxonLabelSet(xmlOTUs, noc.fromXmlToTreeBase(xmlOTUs)); } // Matrices - NexmlMatrixConverter nmc = new NexmlMatrixConverter(pStudy,getTaxonLabelHome(),document); + NexmlMatrixReader nmc = new NexmlMatrixReader(pStudy,getTaxonLabelHome(),document); for ( org.nexml.model.Matrix<?> xmlMatrix : document.getMatrices() ) { Matrix tbMatrix = nmc.fromXmlToTreeBase(xmlMatrix); tbMatrix.setNexusFileName(pFile.getName()); @@ -56,7 +56,7 @@ } // Trees - NexmlTreeBlockConverter ntbc = new NexmlTreeBlockConverter(pStudy,getTaxonLabelHome(),document); + NexmlTreeBlockReader ntbc = new NexmlTreeBlockReader(pStudy,getTaxonLabelHome(),document); for ( org.nexml.model.TreeBlock xmlTreeBlock : document.getTreeBlockList() ) { TreeBlock tbTreeBlock = ntbc.fromXmlToTreeBase(xmlTreeBlock); for ( PhyloTree phyloTree : tbTreeBlock.getTreeList() ) { Deleted: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentConverter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentConverter.java 2011-10-05 17:43:48 UTC (rev 970) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentConverter.java 2011-10-13 16:26:47 UTC (rev 971) @@ -1,123 +0,0 @@ -package org.cipres.treebase.domain.nexus.nexml; - -//import org.cipres.treebase.Constants; -//import org.cipres.treebase.domain.admin.Person; -import org.cipres.treebase.Constants; -import org.cipres.treebase.domain.matrix.CharacterMatrix; -import org.cipres.treebase.domain.nexus.NexusDataSet; -//import org.cipres.treebase.domain.study.ArticleCitation; -//import org.cipres.treebase.domain.study.Citation; -import org.cipres.treebase.domain.study.Study; -import org.cipres.treebase.domain.taxon.TaxonLabelHome; -import org.cipres.treebase.domain.taxon.TaxonLabelSet; -import org.nexml.model.Document; -import org.nexml.model.Matrix; -import org.nexml.model.OTUs; -import org.nexml.model.TreeBlock; - -public class NexmlDocumentConverter extends NexmlObjectConverter { - - /** - * - * @param study - * @param taxonLabelHome - * @param document - */ - public NexmlDocumentConverter(Study study, TaxonLabelHome taxonLabelHome, - Document document) { - super(study, taxonLabelHome, document); - } - - public NexmlDocumentConverter(Study study, TaxonLabelHome taxonLabelHome, - Document document,String baseURI) { - super(study, taxonLabelHome, document,baseURI); - } - - /** - * - * @param pDocument - * @return - */ - public NexusDataSet fromXmlToTreeBase(Document pDocument) { - NexusDataSet nexusDataSet = new NexusDataSet(); - nexusDataSet.setNexmlProject(pDocument); - - NexmlOTUConverter noc = new NexmlOTUConverter(getStudy(),getTaxonLabelHome(),pDocument); - for ( OTUs xmlOTUs : pDocument.getOTUsList() ) { - TaxonLabelSet taxonLabelSet = noc.fromXmlToTreeBase(xmlOTUs); - nexusDataSet.addTaxonLabelSet(xmlOTUs, taxonLabelSet); - } - - NexmlMatrixConverter nmc = new NexmlMatrixConverter(getStudy(),getTaxonLabelHome(),pDocument); - for ( Matrix<?> xmlMatrix : pDocument.getMatrices() ) { - org.cipres.treebase.domain.matrix.Matrix matrix = nmc.fromXmlToTreeBase(xmlMatrix); - nexusDataSet.getMatrices().add(matrix); - } - - NexmlTreeBlockConverter ntc = new NexmlTreeBlockConverter(getStudy(),getTaxonLabelHome(),pDocument); - for ( TreeBlock xmlTreeBlock : pDocument.getTreeBlockList() ) { - org.cipres.treebase.domain.tree.TreeBlock treeBlock = ntc.fromXmlToTreeBase(xmlTreeBlock); - nexusDataSet.getTreeBlocks().add(treeBlock); - } - - return nexusDataSet; - } - - /** - * - * @param pNexusDataSet - * @return - */ - public Document fromTreeBaseToXml(NexusDataSet pNexusDataSet) { - - NexmlOTUConverter noc = new NexmlOTUConverter(getStudy(),getTaxonLabelHome(),getDocument()); - for ( TaxonLabelSet taxonLabelSet : pNexusDataSet.getTaxonLabelSets() ) { - noc.fromTreeBaseToXml(taxonLabelSet); - } - - NexmlMatrixConverter nmc = new NexmlMatrixConverter(getStudy(),getTaxonLabelHome(),getDocument()); - for (org.cipres.treebase.domain.matrix.Matrix matrix : pNexusDataSet.getMatrices() ) { - if ( matrix instanceof CharacterMatrix ) { - nmc.fromTreeBaseToXml((CharacterMatrix)matrix); - } - } - - NexmlTreeBlockConverter ntc = new NexmlTreeBlockConverter(getStudy(),getTaxonLabelHome(),getDocument()); - for ( org.cipres.treebase.domain.tree.TreeBlock treeBlock : pNexusDataSet.getTreeBlocks() ) { - ntc.fromTreeBaseToXML(treeBlock); - } - - return getDocument(); - - } - - /** - * - * @param pStudy - * @return - */ - public Document fromTreeBaseToXml(Study pStudy) { - attachTreeBaseID(getDocument(), pStudy,Study.class); - getDocument().addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using NexmlDocumentConverter $Rev$"); - - NexmlOTUConverter noc = new NexmlOTUConverter(getStudy(),getTaxonLabelHome(),getDocument()); - for ( TaxonLabelSet taxonLabelSet : pStudy.getTaxonLabelSets() ) { - noc.fromTreeBaseToXml(taxonLabelSet); - } - - NexmlMatrixConverter nmc = new NexmlMatrixConverter(getStudy(),getTaxonLabelHome(),getDocument()); - for (org.cipres.treebase.domain.matrix.Matrix matrix : pStudy.getMatrices() ) { - if ( matrix instanceof CharacterMatrix ) { - nmc.fromTreeBaseToXml((CharacterMatrix)matrix); - } - } - - NexmlTreeBlockConverter ntc = new NexmlTreeBlockConverter(getStudy(),getTaxonLabelHome(),getDocument()); - for ( org.cipres.treebase.domain.tree.TreeBlock treeBlock : pStudy.getTreeBlocks() ) { - ntc.fromTreeBaseToXML(treeBlock); - } - - return getDocument(); - } - -} Added: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentReader.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentReader.java (rev 0) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentReader.java 2011-10-13 16:26:47 UTC (rev 971) @@ -0,0 +1,49 @@ +package org.cipres.treebase.domain.nexus.nexml; + +import org.cipres.treebase.domain.nexus.NexusDataSet; +import org.cipres.treebase.domain.study.Study; +import org.cipres.treebase.domain.taxon.TaxonLabelHome; +import org.cipres.treebase.domain.taxon.TaxonLabelSet; +import org.nexml.model.Document; +import org.nexml.model.Matrix; +import org.nexml.model.OTUs; +import org.nexml.model.TreeBlock; + +public class NexmlDocumentReader extends NexmlObjectConverter { + + public NexmlDocumentReader(Study study, TaxonLabelHome taxonLabelHome, + Document document) { + super(study, taxonLabelHome, document); + } + + /** + * + * @param pDocument + * @return + */ + public NexusDataSet fromXmlToTreeBase(Document pDocument) { + NexusDataSet nexusDataSet = new NexusDataSet(); + nexusDataSet.setNexmlProject(pDocument); + + NexmlOTUReader noc = new NexmlOTUReader(getStudy(),getTaxonLabelHome(),pDocument); + for ( OTUs xmlOTUs : pDocument.getOTUsList() ) { + TaxonLabelSet taxonLabelSet = noc.fromXmlToTreeBase(xmlOTUs); + nexusDataSet.addTaxonLabelSet(xmlOTUs, taxonLabelSet); + } + + NexmlMatrixReader nmc = new NexmlMatrixReader(getStudy(),getTaxonLabelHome(),pDocument); + for ( Matrix<?> xmlMatrix : pDocument.getMatrices() ) { + org.cipres.treebase.domain.matrix.Matrix matrix = nmc.fromXmlToTreeBase(xmlMatrix); + nexusDataSet.getMatrices().add(matrix); + } + + NexmlTreeBlockReader ntc = new NexmlTreeBlockReader(getStudy(),getTaxonLabelHome(),pDocument); + for ( TreeBlock xmlTreeBlock : pDocument.getTreeBlockList() ) { + org.cipres.treebase.domain.tree.TreeBlock treeBlock = ntc.fromXmlToTreeBase(xmlTreeBlock); + nexusDataSet.getTreeBlocks().add(treeBlock); + } + + return nexusDataSet; + } + +} Copied: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentWriter.java (from rev 970, trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentConverter.java) =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentWriter.java (rev 0) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentWriter.java 2011-10-13 16:26:47 UTC (rev 971) @@ -0,0 +1,86 @@ +package org.cipres.treebase.domain.nexus.nexml; + +import org.cipres.treebase.Constants; +import org.cipres.treebase.domain.matrix.CharacterMatrix; +import org.cipres.treebase.domain.nexus.NexusDataSet; +import org.cipres.treebase.domain.study.Study; +import org.cipres.treebase.domain.taxon.TaxonLabelHome; +import org.cipres.treebase.domain.taxon.TaxonLabelSet; +import org.nexml.model.Document; + +public class NexmlDocumentWriter extends NexmlObjectConverter { + + /** + * + * @param study + * @param taxonLabelHome + * @param document + */ + public NexmlDocumentWriter(Study study, TaxonLabelHome taxonLabelHome, + Document document) { + super(study, taxonLabelHome, document); + } + + public NexmlDocumentWriter(Study study, TaxonLabelHome taxonLabelHome, + Document document,String baseURI) { + super(study, taxonLabelHome, document,baseURI); + } + + /** + * + * @param pNexusDataSet + * @return + */ + public Document fromTreeBaseToXml(NexusDataSet pNexusDataSet) { + + NexmlOTUWriter noc = new NexmlOTUWriter(getStudy(),getTaxonLabelHome(),getDocument()); + for ( TaxonLabelSet taxonLabelSet : pNexusDataSet.getTaxonLabelSets() ) { + noc.fromTreeBaseToXml(taxonLabelSet); + } + + NexmlMatrixWriter nmc = new NexmlMatrixWriter(getStudy(),getTaxonLabelHome(),getDocument()); + for (org.cipres.treebase.domain.matrix.Matrix matrix : pNexusDataSet.getMatrices() ) { + if ( matrix instanceof CharacterMatrix ) { + nmc.fromTreeBaseToXml((CharacterMatrix)matrix); + } + } + + NexmlTreeBlockWriter ntc = new NexmlTreeBlockWriter(getStudy(),getTaxonLabelHome(),getDocument()); + for ( org.cipres.treebase.domain.tree.TreeBlock treeBlock : pNexusDataSet.getTreeBlocks() ) { + ntc.fromTreeBaseToXML(treeBlock); + } + + return getDocument(); + + } + + /** + * + * @param pStudy + * @return + */ + public Document fromTreeBaseToXml(Study pStudy) { + attachTreeBaseID(getDocument(), pStudy,Study.class); + getDocument().addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using NexmlDocumentConverter $Rev$"); + + NexmlOTUWriter noc = new NexmlOTUWriter(getStudy(),getTaxonLabelHome(),getDocument()); + for ( TaxonLabelSet taxonLabelSet : pStudy.getTaxonLabelSets() ) { + noc.fromTreeBaseToXml(taxonLabelSet); + } + + NexmlMatrixWriter nmc = new NexmlMatrixWriter(getStudy(),getTaxonLabelHome(),getDocument()); + for (org.cipres.treebase.domain.matrix.Matrix matrix : pStudy.getMatrices() ) { + if ( matrix instanceof CharacterMatrix ) { + nmc.fromTreeBaseToXml((CharacterMatrix)matrix); + } + } + + NexmlTreeBlockWriter ntc = new NexmlTreeBlockWriter(getStudy(),getTaxonLabelHome(),getDocument()); + for ( org.cipres.treebase.domain.tree.TreeBlock treeBlock : pStudy.getTreeBlocks() ) { + ntc.fromTreeBaseToXML(treeBlock); + } + + return getDocument(); + } + +} Deleted: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixConverter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixConverter.java 2011-10-05 17:43:48 UTC (rev 970) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixConverter.java 2011-10-13 16:26:47 UTC (rev 971) @@ -1,739 +0,0 @@ -package org.cipres.treebase.domain.nexus.nexml; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.cipres.treebase.Constants; -import org.cipres.treebase.dao.jdbc.ContinuousMatrixElementJDBC; -import org.cipres.treebase.dao.jdbc.ContinuousMatrixJDBC; -import org.cipres.treebase.dao.jdbc.DiscreteMatrixElementJDBC; -import org.cipres.treebase.dao.jdbc.DiscreteMatrixJDBC; -import org.cipres.treebase.dao.jdbc.MatrixColumnJDBC; -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.ContinuousChar; -import org.cipres.treebase.domain.matrix.ContinuousMatrix; -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.Matrix; -import org.cipres.treebase.domain.matrix.MatrixColumn; -import org.cipres.treebase.domain.matrix.MatrixDataType; -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.matrix.StandardMatrix; -import org.cipres.treebase.domain.matrix.StateSet; -import org.cipres.treebase.domain.study.Study; -import org.cipres.treebase.domain.taxon.TaxonLabelHome; -import org.cipres.treebase.domain.taxon.TaxonLabelSet; -import org.nexml.model.Annotatable; -import org.nexml.model.CategoricalMatrix; -import org.nexml.model.CharacterState; -import org.nexml.model.CharacterStateSet; -import org.nexml.model.Document; -import org.nexml.model.MatrixCell; -import org.nexml.model.MolecularMatrix; -import org.nexml.model.OTUs; -import org.nexml.model.OTU; -import org.nexml.model.Subset; - -public class NexmlMatrixConverter extends NexmlObjectConverter { - - private static final int MAX_GRANULAR_NCHAR = 1000; - private static final int MAX_GRANULAR_NTAX = 30; - - /** - * - * @param study - * @param taxonLabelHome - */ - public NexmlMatrixConverter(Study study,TaxonLabelHome taxonLabelHome,Document document) { - super(study,taxonLabelHome,document); - } - - /** - * - * @param xmlMatrix - * @return - */ - public Matrix fromXmlToTreeBase(CategoricalMatrix xmlMatrix) { - DiscreteMatrix tbMatrix = new DiscreteMatrix(); - DiscreteMatrixJDBC matrixJDBC = new DiscreteMatrixJDBC(tbMatrix, xmlMatrix, this); - List<MatrixColumnJDBC> columnJDBCs = new ArrayList<MatrixColumnJDBC>(); - long[] colIds = matrixJDBC.getColIDs(); - long[] rowIds = matrixJDBC.getRowIDs(); - List<DiscreteMatrixElementJDBC> elements = new ArrayList<DiscreteMatrixElementJDBC>(); - int colIndex = 0; - for ( org.nexml.model.Character xmlCharacter : xmlMatrix.getCharacters() ) { - String charName = xmlCharacter.getLabel(); - DiscreteChar tbChar = new DiscreteChar(); - tbChar.setDescription(charName); - MatrixColumnJDBC aColumnJDBC = new MatrixColumnJDBC(); - aColumnJDBC.setPhyloChar(tbChar); - columnJDBCs.add(aColumnJDBC); - int rowIndex = 0; - for ( OTU xmlOTU : xmlMatrix.getOTUs().getAllOTUs() ) { - @SuppressWarnings("unused") - MatrixCell<CharacterState> xmlCell = xmlMatrix.getCell(xmlOTU, xmlCharacter); - DiscreteMatrixElementJDBC element = new DiscreteMatrixElementJDBC(); - //element.setValue(xmlCell.getValue()); // XXX nested stateset lookup song & dance here - element.setElementOrder(colIndex); - element.setMatrixRowID(rowIds[rowIndex]); - element.setMatrixColID(colIds[colIndex]); - elements.add(element); - rowIndex++; - } - colIndex++; - } - DiscreteMatrixElementJDBC.batchDiscreteElements(elements, getTaxonLabelHome().getConnection()); - return tbMatrix; - } - - /** - * - * @param xmlMatrix - * @return - */ - public Matrix fromXmlToTreeBase(org.nexml.model.ContinuousMatrix xmlMatrix) { - ContinuousMatrix tbMatrix = new ContinuousMatrix(); - ContinuousMatrixJDBC matrixJDBC = new ContinuousMatrixJDBC(tbMatrix, xmlMatrix, this); - List<MatrixColumnJDBC> columnJDBCs = new ArrayList<MatrixColumnJDBC>(); - long[] colIds = matrixJDBC.getColIDs(); - long[] rowIds = matrixJDBC.getRowIDs(); - List<ContinuousMatrixElementJDBC> elements = new ArrayList<ContinuousMatrixElementJDBC>(); - - int colIndex = 0; - for ( org.nexml.model.Character xmlCharacter : xmlMatrix.getCharacters() ) { - String charName = xmlCharacter.getLabel(); - ContinuousChar tbChar = new ContinuousChar(); - tbChar.setDescription(charName); - MatrixColumnJDBC aColumnJDBC = new MatrixColumnJDBC(); - aColumnJDBC.setPhyloChar(tbChar); - columnJDBCs.add(aColumnJDBC); - int rowIndex = 0; - for ( OTU xmlOTU : xmlMatrix.getOTUs().getAllOTUs() ) { - MatrixCell<Double> xmlCell = xmlMatrix.getCell(xmlOTU, xmlCharacter); - ContinuousMatrixElementJDBC element = new ContinuousMatrixElementJDBC(); - element.setValue(xmlCell.getValue()); - element.setElementOrder(colIndex); - element.setMatrixRowID(rowIds[rowIndex]); - element.setMatrixColID(colIds[colIndex]); - elements.add(element); - rowIndex++; - } - colIndex++; - } - ContinuousMatrixElementJDBC.batchContinuousElements(elements, getTaxonLabelHome().getConnection()); - return tbMatrix; - } - - /** - * - * @param xmlMatrix - * @return - */ - public Matrix fromXmlToTreeBase(org.nexml.model.Matrix<?> xmlMatrix) { - OTUs xmlOTUs = xmlMatrix.getOTUs(); - Matrix tbMatrix = null; - TaxonLabelSet tbTaxa = null; - Long tbTaxonLabelSetID = readTreeBaseID((Annotatable) xmlOTUs); - if ( null != tbTaxonLabelSetID ) { - tbTaxa = getTaxonLabelHome() - .findPersistedObjectByID(TaxonLabelSet.class, tbTaxonLabelSetID); - } - if ( xmlMatrix instanceof CategoricalMatrix ) { - tbMatrix = fromXmlToTreeBase((CategoricalMatrix) xmlMatrix); - } - else if ( xmlMatrix instanceof org.nexml.model.ContinuousMatrix ) { - tbMatrix = fromXmlToTreeBase((org.nexml.model.ContinuousMatrix) xmlMatrix); - } - if ( null != tbMatrix ) { - attachTreeBaseID((Annotatable) xmlMatrix, tbMatrix,Matrix.class); - if ( null != tbTaxa ) { - tbMatrix.setTaxa(tbTaxa); - } - tbMatrix.setStudy(getStudy()); - tbMatrix.setTitle(xmlMatrix.getLabel()); - tbMatrix.setPublished(false); - } - return tbMatrix; - } - - /** - * Creates and populates characters (i.e. columns) with their annotations, - * and state sets, with their annotations - * - * @param tbMatrix - * @return an xml matrix with empty rows - */ - public CategoricalMatrix fromTreeBaseToXml(StandardMatrix tbMatrix) { - OTUs xmlOTUs = getOTUsById(tbMatrix.getTaxa().getId()); - CategoricalMatrix xmlMatrix = getDocument().createCategoricalMatrix(xmlOTUs); - - // attach base uri and history note - xmlMatrix.addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using NexmlMatrixConverter $Rev$"); - xmlMatrix.setBaseURI(mMatrixBaseURI); - - List<List<DiscreteCharState>> tbStateLabels = tbMatrix.getStateLabels(); - List<MatrixColumn> tbColumns = tbMatrix.getColumnsReadOnly(); - for ( int i = 0; i < tbColumns.size(); i++ ) { - CharacterStateSet xmlStateSet = xmlMatrix.createCharacterStateSet(); - for ( DiscreteCharState tbState : tbStateLabels.get(i) ) { - CharacterState xmlState = xmlStateSet.createCharacterState(tbState.getSymbol().toString()); - if ( null != tbState.getDescription() ) { - xmlState.setLabel(tbState.getDescription()); - } - attachTreeBaseID((Annotatable)xmlState,tbState,DiscreteCharState.class); - } - org.nexml.model.Character xmlCharacter = xmlMatrix.createCharacter(xmlStateSet); - PhyloChar tbCharacter = tbColumns.get(i).getCharacter(); - if ( null != tbCharacter.getDescription() ) { - xmlCharacter.setLabel(tbCharacter.getDescription()); - } - attachTreeBaseID((Annotatable)xmlCharacter,tbColumns.get(i),MatrixColumn.class); - } - return xmlMatrix; - } - - /** - * Creates and populates characters (i.e. columns) with their annotations, - * and state sets, with their annotations - * - * @param tbMatrix - * @return an xml matrix with empty rows - */ - public MolecularMatrix fromTreeBaseToXml(DiscreteMatrix tbMatrix) { - OTUs xmlOTUs = getOTUsById(tbMatrix.getTaxa().getId()); - String tbDataType = tbMatrix.getDataType().getDescription(); - MolecularMatrix xmlMatrix = null; - CharacterStateSet xmlStateSet = null; - - // create the matrix and constant state set - if ( tbDataType.equals(MatrixDataType.MATRIX_DATATYPE_DNA) ) { - xmlMatrix = getDocument().createMolecularMatrix(xmlOTUs, MolecularMatrix.DNA); - xmlStateSet = ((MolecularMatrix)xmlMatrix).getDNACharacterStateSet(); - } - else if ( tbDataType.equals(MatrixDataType.MATRIX_DATATYPE_RNA) ) { - xmlMatrix = getDocument().createMolecularMatrix(xmlOTUs, MolecularMatrix.RNA); - xmlStateSet = ((MolecularMatrix)xmlMatrix).getRNACharacterStateSet(); - } - else if ( tbDataType.equals(MatrixDataType.MATRIX_DATATYPE_PROTEIN) ) { - xmlMatrix = getDocument().createMolecularMatrix(xmlOTUs, MolecularMatrix.Protein); - xmlStateSet = ((MolecularMatrix)xmlMatrix).getProteinCharacterStateSet(); - } - - // attach base uri and history note - xmlMatrix.setBaseURI(mMatrixBaseURI); - xmlMatrix.addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using NexmlMatrixConverter $Rev$"); - - // lookup the equivalent state in tb and attach identifiers - for(StateSet tbStateSet : tbMatrix.getStateSets() ) { - for (DiscreteCharState tbState : tbStateSet.getStates() ) { - String tbSymbol = tbState.getSymbol().toString().toUpperCase(); - CharacterState xmlState = xmlStateSet.lookupCharacterStateBySymbol(tbSymbol); - if ( null == xmlState ) { - xmlState = xmlStateSet.createCharacterState(tbSymbol); - } - attachTreeBaseID((Annotatable)xmlState,tbState,DiscreteCharState.class); - } - } - - // create columns and attach identifiers - for ( MatrixColumn tbColumn : tbMatrix.getColumnsReadOnly() ) { - org.nexml.model.Character xmlCharacter = xmlMatrix.createCharacter(xmlStateSet); - attachTreeBaseID((Annotatable)xmlCharacter,tbColumn,MatrixColumn.class); - } - return xmlMatrix; - } - - /** - * Creates and populates characters (i.e. columns) with their annotations, - * and state sets, with their annotations - * - * @param tbMatrix - * @return an xml matrix with empty rows - */ - public org.nexml.model.ContinuousMatrix fromTreeBaseToXml(ContinuousMatrix tbMatrix) { - OTUs xmlOTUs = getOTUsById(tbMatrix.getTaxa().getId()); - org.nexml.model.ContinuousMatrix xmlMatrix = getDocument().createContinuousMatrix(xmlOTUs); - - // attach base uri and history note - xmlMatrix.setBaseURI(mMatrixBaseURI); - xmlMatrix.addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using NexmlMatrixConverter $Rev$"); - - for ( MatrixColumn tbColumn : tbMatrix.getColumnsReadOnly() ) { - org.nexml.model.Character xmlCharacter = xmlMatrix.createCharacter(); - PhyloChar tbCharacter = tbColumn.getCharacter(); - if ( null != tbCharacter.getDescription() ) { - xmlCharacter.setLabel(tbCharacter.getDescription()); - ((Annotatable)xmlCharacter).addAnnotationValue("dcterms:description", Constants.DCTermsURI, tbCharacter.getDescription()); - } - attachTreeBaseID((Annotatable)xmlCharacter,tbColumn,MatrixColumn.class); - - //coerce the tbMatrix into a character matrix to get its character sets - CharacterMatrix tbCharacterMatrix = (CharacterMatrix)tbMatrix; - Set<CharSet> tbCharSets = tbCharacterMatrix.getCharSets(); - for ( CharSet tbCharSet : tbCharSets ) { - 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(); - - // increment from beginning to end. This number is probably either null, for a - // contiguous range, or perhaps 3 for codon positions - int tbInc = 1; - // create the equivalent nexml character set - Subset nexSubset = xmlMatrix.createSubset(tbCharSet.getLabel()); - - // assign character objects to the subset. Here we get the full list - List<org.nexml.model.Character> nexCharacters = xmlMatrix.getCharacters(); - - // now we iterate over the coordinates and assign the nexml characters to the set - for ( int i = tbStart; i <= tbStop; i += tbInc ) { - nexSubset.addThing(nexCharacters.get(i)); - } - } - } - - } - - return xmlMatrix; - } - - -// XXX doesn't handle the following data types: -// public static final String MATRIX_DATATYPE_NUCLEOTIDE = "Nucleotide"; -// public static final String MATRIX_DATATYPE_DISTANCE = "Distance"; -// public static final String MATRIX_DATATYPE_MIXED = "Mixed"; - @SuppressWarnings("unchecked") - public org.nexml.model.Matrix<?> fromTreeBaseToXml(CharacterMatrix tbMatrix) { - org.nexml.model.Matrix<?> xmlMatrix = null; - if ( tbMatrix instanceof DiscreteMatrix ) { - if ( tbMatrix.getDataType().getDescription().equals(MatrixDataType.MATRIX_DATATYPE_STANDARD) ) { - xmlMatrix = fromTreeBaseToXml((StandardMatrix) tbMatrix); - } - else { - xmlMatrix = fromTreeBaseToXml((DiscreteMatrix) tbMatrix); - } - populateXmlMatrix((org.nexml.model.Matrix<CharacterState>)xmlMatrix,(DiscreteMatrix)tbMatrix); - } - else if ( tbMatrix instanceof ContinuousMatrix ) { - xmlMatrix = fromTreeBaseToXml((ContinuousMatrix) tbMatrix); - populateXmlMatrix((org.nexml.model.ContinuousMatrix)xmlMatrix,(ContinuousMatrix)tbMatrix); - } - xmlMatrix.setLabel(tbMatrix.getTitle()); - attachTreeBaseID((Annotatable)xmlMatrix, tbMatrix,Matrix.class); - String tb1MatrixID = tbMatrix.getTB1MatrixID(); - if ( null != tb1MatrixID ) { - ((Annotatable)xmlMatrix).addAnnotationValue("tb:identifier.matrix.tb1", Constants.TBTermsURI, tb1MatrixID); - } - Set<CharSet> tbCharSets = tbMatrix.getCharSets(); - for ( CharSet tbCharSet : tbCharSets ) { - Collection<ColumnRange> tbColumnRanges = tbCharSet.getColumns(tbMatrix); - - for ( ColumnRange tbColumnRange : tbColumnRanges ) { - - // these are the beginning and end of the range - int tbStart = tbColumnRange.getStartColIndex(); - int tbStop = tbColumnRange.getEndColIndex(); - - // increment from beginning to end. This number is probably either null, for a - // contiguous range, or perhaps 3 for codon positions - int tbInc = 1; - // create the equivalent nexml character set - Subset nexSubset = xmlMatrix.createSubset(tbCharSet.getLabel()); - - // assign character objects to the subset. Here we get the full list - List<org.nexml.model.Character> nexCharacters = xmlMatrix.getCharacters(); - - // now we iterate over the coordinates and assign the nexml characters to the set - for ( int i = tbStart; i <= tbStop; i += tbInc ) { - nexSubset.addThing(nexCharacters.get(i)); - } - } - } - - return xmlMatrix; - } - - /** - * - * @param xmlMatrix - * @param tbMatrix - * @param xmlOTUs - * @param stateSet - */ - private void populateXmlMatrix( - org.nexml.model.Matrix<CharacterState> xmlMatrix, - DiscreteMatrix tbMatrix) { - OTUs xmlOTUs = xmlMatrix.getOTUs(); - List<org.nexml.model.Character> characterList = xmlMatrix.getCharacters(); - for ( MatrixRow tbRow : tbMatrix.getRowsReadOnly() ) { - Set<RowSegment> tbSegments = tbRow.getSegmentsReadOnly(); - OTU xmlOTU = getOTUById(xmlOTUs, tbRow.getTaxonLabel().getId()); - int charIndex = 0; - if ( characterList.size() <= MAX_GRANULAR_NCHAR && xmlOTUs.getAllOTUs().size() <= MAX_GRANULAR_NTAX ) { - for ( MatrixColumn tbColumn : ((CharacterMatrix)tbMatrix).getColumns() ) { - String seq = tbRow.buildElementAsString(); - xmlMatrix.setSeq(seq, xmlOTU); - org.nexml.model.Character xmlCharacter = characterList.get(charIndex); - MatrixCell<CharacterState> xmlCell = xmlMatrix.getCell(xmlOTU, xmlCharacter); - - attachTreeBaseID ((Annotatable) xmlCell, tbColumn , DiscreteMatrixElement.class); - - //The following is commented out as tbRow.getElements() does not work directly and crashes the loop. - //The above for loop fixes this issue. - /* - for ( MatrixElement tbCell : tbRow.getElements() ) { - org.nexml.model.Character xmlCharacter = characterList.get(charIndex); - MatrixCell<CharacterState> xmlCell = xmlMatrix.getCell(xmlOTU, xmlCharacter); - DiscreteCharState tbState = ((DiscreteMatrixElement)tbCell).getCharState(); - String tbSymbolString = ( null == tbState ) ? "?" : tbState.getSymbol().toString(); - CharacterState xmlState = xmlCharacter.getCharacterStateSet().lookupCharacterStateBySymbol(tbSymbolString); - xmlCell.setValue(xmlState); - attachTreeBaseID((Annotatable)xmlCell,tbCell,DiscreteMatrixElement.class); - */ - - for ( RowSegment tbSegment : tbSegments ) { - if ( tbSegment.getStartIndex() <= charIndex && charIndex <= tbSegment.getEndIndex() ) { - //declare variables for row-segment annotations - String title = tbSegment.getTitle(); - String institutionCode = tbSegment.getSpecimenLabel().getInstAcronym(); - String collectionCode = tbSegment.getSpecimenLabel().getCollectionCode(); - String catalogNumber = tbSegment.getSpecimenLabel().getCatalogNumber(); - String accessionNumber = tbSegment.getSpecimenLabel().getGenBankAccession(); - String otherAccessionNumber = tbSegment.getSpecimenLabel().getOtherAccession(); - String dateSampled = tbSegment.getSpecimenLabel().getSampleDateString(); - String scientificName = tbSegment.getSpecimenTaxonLabelAsString(); - String collector = tbSegment.getSpecimenLabel().getCollector(); - Double latitude = tbSegment.getSpecimenLabel().getLatitude(); - Double longitude = tbSegment.getSpecimenLabel().getLongitude(); - Double elevation = tbSegment.getSpecimenLabel().getElevation(); - String country = tbSegment.getSpecimenLabel().getCountry(); - String state = tbSegment.getSpecimenLabel().getState(); - String locality = tbSegment.getSpecimenLabel().getLocality(); - String notes = tbSegment.getSpecimenLabel().getNotes(); - - //if the value is not null, output the xmlOTU annotation. - //DwC refers to the Darwin Core term vocabulary for the associated annotation - if (null != title){ - //output name identifying the data set from which the record was derived - ((Annotatable)xmlCell).addAnnotationValue("DwC:datasetName", Constants.DwCURI, title); - } - if ( null != institutionCode ) { - //output name or acronym of institution that has custody of information referred to in record - ((Annotatable)xmlCell).addAnnotationValue("DwC:institutionCode", Constants.DwCURI, institutionCode); - } - if ( null != collectionCode ) { - //output name or code that identifies collection or data set from which record was derived - ((Annotatable)xmlCell).addAnnotationValue ("DwC:collectionCode", Constants.DwCURI, collectionCode); - } - if ( null != catalogNumber ){ - //output unique (usually) identifier for the record within data set or collection - ((Annotatable)xmlCell).addAnnotationValue("DwC:catalogNumber", Constants.DwCURI, catalogNumber); - } - if ( null != accessionNumber) { - //output a list of genetic sequence information associated with occurrence - ((Annotatable)xmlCell).addAnnotationValue("DwC:associatedSequences", Constants.DwCURI, accessionNumber); - } - if ( null != otherAccessionNumber ) { - //list of previous or alternate fully catalog numbers (i.e. Genbank) or human-used identifiers - ((Annotatable)xmlCell).addAnnotationValue("DwC:otherCatalogNumbers", Constants.DwCURI, otherAccessionNumber); - } - if ( null != dateSampled ) { - //output date sampled in ISO 8601 format - ((Annotatable)xmlCell).addAnnotationValue("DwC:eventDate", Constants.DwCURI, dateSampled); - } - if ( null != scientificName ) { - //output full scientific name - ((Annotatable)xmlCell).addAnnotationValue("DwC:scientificName", Constants.DwCURI, scientificName); - } - if ( null != collector ) { - //output names of people associated with recording of original occurrence - ((Annotatable)xmlCell).addAnnotationValue("DwC:recordedBy", Constants.DwCURI, collector); - } - if ( null != latitude ) { - //output geographic latitude in decimal degrees using geodeticDatum spatial reference system - ((Annotatable)xmlCell).addAnnotationValue("DwC:decimalLatitude", Constants.DwCURI, latitude); - } - if ( null != longitude ) { - //output geographic longitude in decimal degrees using geodeticDatum spatial reference system - ((Annotatable)xmlCell).addAnnotationValue("DwC:decimalLongitude", Constants.DwCURI, longitude); - } - if ( null != elevation ) { - //there are two different Darwin Core terms for elevation depending on elevation value - //outputs geographic elevation of sample - if ( elevation >= 0) { - //above local surface in meters - ((Annotatable)xmlCell).addAnnotationValue("DwC:verbatimElevation", Constants.DwCURI, elevation); - } - else { - //below local surface in meters - ((Annotatable)xmlCell).addAnnotationValue("DwC:verbatimDepth", Constants.DwCURI, elevation); - } - } - if ( null != country ) { - //output country in which location occurs - ((Annotatable)xmlCell).addAnnotationValue("DwC:country", Constants.DwCURI, country); - } - if ( null != state ) { - //output name of next smaller administrative region than country (i.e. state, province, region) - ((Annotatable)xmlCell).addAnnotationValue ("DwC:stateProvince", Constants.DwCURI, state); - } - if ( null != locality) { - //output brief description of sample location - ((Annotatable)xmlCell).addAnnotationValue("DwC:locality", Constants.DwCURI, locality); - } - if ( null != notes ) { - //output any additional information about specimen - ((Annotatable)xmlCell).addAnnotationValue("DwC:occurenceRemarks", Constants.DwCURI, notes); - } - } - } - charIndex++; - } - } - else { - String seq = tbRow.buildElementAsString(); - if ( tbMatrix.getDataType().getDescription().equals(MatrixDataType.MATRIX_DATATYPE_STANDARD) ) { - StringBuilder sb = new StringBuilder(); - for ( int i = 0; i < seq.length(); i++ ) { - sb.append(seq.charAt(i)); - if ( i < seq.length() - 1 ) { - sb.append(' '); - } - } - } - xmlMatrix.setSeq(seq,xmlOTU); - } - for ( RowSegment tbSegment : tbSegments ) { - //declare variables for row-segment annotations - String title = tbSegment.getTitle(); - String institutionCode = tbSegment.getSpecimenLabel().getInstAcronym(); - String collectionCode = tbSegment.getSpecimenLabel().getCollectionCode(); - String catalogNumber = tbSegment.getSpecimenLabel().getCatalogNumber(); - String accessionNumber = tbSegment.getSpecimenLabel().getGenBankAccession(); - String otherAccessionNumber = tbSegment.getSpecimenLabel().getOtherAccession(); - String dateSampled = tbSegment.getSpecimenLabel().getSampleDateString(); - String scientificName = tbSegment.getSpecimenTaxonLabelAsString(); - String collector = tbSegment.getSpecimenLabel().getCollector(); - Double latitude = tbSegment.getSpecimenLabel().getLatitude(); - Double longitude = tbSegment.getSpecimenLabel().getLongitude(); - Double elevation = tbSegment.getSpecimenLabel().getElevation(); - String country = tbSegment.getSpecimenLabel().getCountry(); - String state = tbSegment.getSpecimenLabel().getState(); - String locality = tbSegment.getSpecimenLabel().getLocality(); - String notes = tbSegment.getSpecimenLabel().getNotes(); - - //if the value is not null, output the xmlOTU annotation. - //DwC refers to the Darwin Core term vocabulary for the associated annotation - if (null != title){ - //output name identifying the data set from which the record was derived - xmlOTU.addAnnotationValue("DwC:datasetName", Constants.DwCURI, title); - } - if ( null != institutionCode ) { - //output name or acronym of institution that has custody of information referred to in record - xmlOTU.addAnnotationValue("DwC:institutionCode", Constants.DwCURI, institutionCode); - } - if ( null != collectionCode ) { - //output name or code that identifies collection or data set from which record was derived - xmlOTU.addAnnotationValue ("DwC:collectionCode", Constants.DwCURI, collectionCode); - } - if ( null != catalogNumber ){ - //output unique (usually) identifier for the record within data set or collection - xmlOTU.addAnnotationValue("DwC:catalogNumber", Constants.DwCURI, catalogNumber); - } - if ( null != accessionNumber) { - //output a list of genetic sequence information associated with occurrence - xmlOTU.addAnnotationValue("DwC:associatedSequences", Constants.DwCURI, accessionNumber); - } - if ( null != otherAccessionNumber ) { - //list of previous or alternate fully catalog numbers (i.e. Genbank) or human-used identifiers - xmlOTU.addAnnotationValue("DwC:otherCatalogNumbers", Constants.DwCURI, otherAccessionNumber); - } - if ( null != dateSampled ) { - //output date sampled in ISO 8601 format - xmlOTU.addAnnotationValue("DwC:eventDate", Constants.DwCURI, dateSampled); - } - if ( null != scientificName ) { - //output full scientific name - xmlOTU.addAnnotationValue("DwC:scientificName", Constants.DwCURI, scientificName); - } - if ( null != collector ) { - //output names of people associated with recording of original occurrence - xmlOTU.addAnnotationValue("DwC:recordedBy", Constants.DwCURI, collector); - } - if ( null != latitude ) { - //output geographic latitude in decimal degrees using geodeticDatum spatial reference system - xmlOTU.addAnnotationValue("DwC:decimalLatitude", Constants.DwCURI, latitude); - } - if ( null != longitude ) { - //output geographic longitude in decimal degrees using geodeticDatum spatial reference system - xmlOTU.addAnnotationValue("DwC:decimalLongitude", Constants.DwCURI, longitude); - } - if ( null != elevation ) { - //there are two different Darwin Core terms for elevation depending on elevation value - //outputs geographic elevation of sample - if ( elevation >= 0) { - //above local surface in meters - xmlOTU.addAnnotationValue("DwC:verbatimElevation", Constants.DwCURI, elevation); - } - else { - //below local surface in meters - xmlOTU.addAnnotationValue("DwC:verbatimDepth", Constants.DwCURI, elevation); - } - } - if ( null != country ) { - //output country in which location occurs - xmlOTU.addAnnotationValue("DwC:country", Constants.DwCURI, country); - } - if ( null != state ) { - //output name of next smaller administrative region than country (i.e. state, province, region) - xmlOTU.addAnnotationValue ("DwC:stateProvince", Constants.DwCURI, state); - } - if ( null != locality) { - //output brief description of sample location - xmlOTU.addAnnotationValue("DwC:locality", Constants.DwCURI, locality); - } - if ( null != notes ) { - //output any additional information about specimen - xmlOTU.addAnnotationValue("DwC:occurenceRemarks", Constants.DwCURI, notes); - } - } - } - } - - /** - * - * @param xmlMatrix - * @param tbMatrix - */ - private void populateXmlMatrix(org.nexml.model.ContinuousMatrix xmlMatrix, - ContinuousMatrix tbMatrix) { - List<org.nexml.model.Character> characterList = xmlMatrix.getCharacters(); - OTUs xmlOTUs = xmlMatrix.getOTUs(); - for ( MatrixRow tbRow : tbMatrix.getRowsReadOnly() ) { - List<MatrixElement> elements = tbRow.getElements(); - OTU xmlOTU = getOTUById(xmlOTUs, tbRow.getTaxonLabel().getId()); - if ( characterList.size() <= MAX_GRANULAR_NCHAR && xmlOTUs.getAllOTUs().size() <= MAX_GRANULAR_NTAX ) { - for ( int elementIndex = 0; elementIndex < tbMatrix.getnChar(); elementIndex++ ) { - ContinuousMatrixElement tbCell = (ContinuousMatrixElement)elements.get(elementIndex); - MatrixCell<Double> xmlCell = xmlMatrix.getCell(xmlOTU, characterList.get(elementIndex)); - xmlCell.setValue(tbCell.getValue()); - attachTreeBaseID((Annotatable)xmlCell,tbCell,DiscreteMatrixElement.class); - } - } - else { - String seq = tbRow.buildElementAsString(); - xmlMatrix.setSeq(seq,xmlOTU); - } - Set<RowSegment> tbSegments = tbRow.getSegmentsReadOnly(); - for ( RowSegment tbSegment : tbSegments ) { - //declare variables for row-segment annotations - String title = tbSegment.getTitle(); - String institutionCode = tbSegment.getSpecimenLabel().getInstAcronym(); - String collectionCode = tbSegment.getSpecimenLabel().getCollectionCode(); - String catalogNumber = tbSegment.getSpecimenLabel().getCatalogNumber(); - String accessionNumber = tbSegment.getSpecimenLabel().getGenBankAccession(); - String otherAccessionNumber = tbSegment.getSpecimenLabel().getOtherAccession(); - String dateSampled = tbSegment.getSpecimenLabel().getSampleDateString(); - String scientificName = tbSegment.getSpecimenTaxonLabelAsString(); - String collector = tbSegment.getSpecimenLabel().getCollector(); - Double latitude = tbSegment.getSpecimenLabel().getLatitude(); - Double longitude = tbSegment.getSpecimenLabel().getLongitude(); - Double elevation = tbSegment.getSpecimenLabel().getElevation(); - String country = tbSegment.getSpecimenLabel().getCountry(); - String state = tbSegment.getSpecimenLabel().getState(); - String locality = tbSegment.getSpecimenLabel().getLocality(); - String notes = tbSegment.getSpecimenLabel().getNotes(); - - //if the value is not null, output the xmlOTU annotation. - //DwC refers to the Darwin Core term vocabulary for the associated annotation - if (null != title){ - //output name identifying the data set from which the record was derived - xmlOTU.addAnnotationValue("DwC:datasetName", Constants.DwCURI, title); - } - if ( null != institutionCode ) { - //output name or acronym of institution that has custody of information referred to in record - xmlOTU.addAnnotationValue("DwC:institutionCode", Constants.DwCURI, institutionCode); - } - if ( null != collectionCode ) { - //output name or code that identifies collection or data set from which record was derived - xmlOTU.addAnnotationValue ("DwC:collectionCode", Constants.DwCURI, collectionCode); - } - if ( null != catalogNumber ){ - //output unique (usually) identifier for the record within data set or collection - xmlOTU.addAnnotationValue("DwC:catalogNumber", Constants.DwCURI, catalogNumber); - } - if ( null != accessionNumber) { - //output a list of genetic sequence information associated with occurrence - xmlOTU.addAnnotationValue("DwC:associatedSequences", Constants.DwCURI, accessionNumber); - } - if ( null != otherAccessionNumber ) { - //list of previous or alternate fully catalog numbers (i.e. Genbank) or human-used identifiers - xmlOTU.addAnnotationValue("DwC:otherCatalogNumbers", Constants.DwCURI, otherAccessionNumber); - } - if ( null != dateSampled ) { - //output date sampled in ISO 8601 format - xmlOTU.addAnnotationValue("DwC:eventDate", Constants.DwCURI, dateSampled); - } - if ( null != scientificName ) { - //output full scientific name - xmlOTU.addAnnotationValue("DwC:scientificName", Constants.DwCURI, scientificName); - } - if ( null != collector ) { - //output names of people associated with recording of original occurrence - xmlOTU.addAnnotationValue("DwC:recordedBy", Constants.DwCURI, collector); - } - if ( null != latitude ) { - //output geographic latitude in decimal degrees using geodeticDatum spatial reference system - xmlOTU.addAnnotationValue("DwC:decimalLatitude", Constants.DwCURI, latitude); - } - if ( null != longitude ) { - //output geographic longitude in decimal degrees using geodeticDatum spatial reference system - xmlOTU.addAnnotationValue("DwC:decimalLongitude", Constants.DwCURI, longitude); - } - if ( null != elevation ) { - //there are two different Darwin Core terms for elevation depending on elevation value - //outputs geographic elevation of sample - if ( elevation >= 0) { - //above local surface in meters - xmlOTU.addAnnotationValue("DwC:verbatimElevation", Constants.DwCURI, elevation); - } - else { - //below local surface in meters - xmlOTU.addAnnotationValue("DwC:verbatimDepth", Constants.DwCURI, elevation); - } - } - if ( null != country ) { - //output country in which location occurs - xmlOTU.addAnnotationValue("DwC:country", Constants.DwCURI, country); - } - if ( null != state ) { - //output name of next smaller administrative region than country (i.e. state, province, region) - xmlOTU.addAnnotationValue ("DwC:stateProvince", Constants.DwCURI, state); - } - if ( null != locality) { - //output brief description of sample location - xmlOTU.addAnnotationValue("DwC:locality", Constants.DwCURI, locality); - } - if ( null != notes ) { - //output any additional information about specimen - xmlOTU.addAnnotationValue("DwC:occurenceRemarks", Constants.DwCURI, notes); - } - } - } - } - -} Added: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixReader.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixReader.java (rev 0) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixReader.java 2011-10-13 16:26:47 UTC (rev 971) @@ -0,0 +1,142 @@ +package org.cipres.treebase.domain.nexus.nexml; + +import java.util.ArrayList; +import java.util.List; + +import org.cipres.treebase.dao.jdbc.ContinuousMatrixElementJDBC; +import org.cipres.treebase.dao.jdbc.ContinuousMatrixJDBC; +import org.cipres.treebase.dao.jdbc.DiscreteMatrixElementJDBC; +import org.cipres.treebase.dao.jdbc.DiscreteMatrixJDBC; +import org.cipres.treebase.dao.jdbc.MatrixColumnJDBC; +import org.cipres.treebase.domain.matrix.ContinuousChar; +import org.cipres.treebase.domain.matrix.ContinuousMatrix; +import org.cipres.treebase.domain.matrix.DiscreteChar; +import org.cipres.treebase.domain.matrix.DiscreteMatrix; +import org.cipres.treebase.domain.matrix.Matrix; +import org.cipres.treebase.domain.study.Study; +import org.cipres.treebase.domain.taxon.TaxonLabelHome; +import org.cipres.treebase.domain.taxon.TaxonLabelSet; +import org.nexml.model.Annotatable; +import org.nexml.model.CategoricalMatrix; +import org.nexml.model.CharacterState; +import org.nexml.model.Document; +import org.nexml.model.MatrixCell; +import org.nexml.model.OTU; +import org.nexml.model.OTUs; + +public class NexmlMatrixReader extends NexmlObjectConverter { + + public NexmlMatrixReader(Study study, TaxonLabelHome taxonLabelHome, + Document document) { + super(study, taxonLabelHome, document); + } + + /** + * + * @param xmlMatrix + * @return + */ + private Matrix fromXmlToTreeBase(CategoricalMatrix xmlMatrix) { + DiscreteMatrix tbMatrix = new DiscreteMatrix(); + DiscreteMatrixJDBC matrixJDBC = new DiscreteMatrixJDBC(tbMatrix, xmlMatrix, this); + List<MatrixColumnJDBC> columnJDBCs = new ArrayList<MatrixColumnJDBC>(); + long[] colIds = matrixJDBC.getColIDs(); + long[] rowIds = matrixJDBC.getRowIDs(); + List<DiscreteMatrixElementJDBC> elements = new ArrayList<DiscreteMatrixElementJDBC>(); + int colIndex = 0; + for ( org.nexml.model.Character xmlCharacter : xmlMatrix.getCharacters() ) { + String charName = xmlCharacter.getLabel(); + DiscreteChar tbChar = new DiscreteChar(); + tbChar.setDescription(charName); + MatrixColumnJDBC aColumnJDBC = new MatrixColumnJDBC(); + aColumnJDBC.setPhyloChar(tbChar); + columnJDBCs.add(aColumnJDBC); + int rowIndex = 0; + for ( OTU xmlOTU : xmlMatrix.getOTUs().getAllOTUs() ) { + @SuppressWarnings("unused") + MatrixCell<CharacterState> xmlCell = xmlMatrix.getCell(xmlOTU, xmlCharacter); + DiscreteMatrixElementJDBC element = new DiscreteMatrixElementJDBC(); + //element.setValue(xmlCell.getValue()); // XXX nested stateset lookup song & dance here + element.setElementOrder(colIndex); + element.setMatrixRowID(rowIds[rowIndex]); + element.setMatrixColID(colIds[colIndex]); + elements.add(element); + rowIndex++; + } + colIndex++; + } + DiscreteMatrixElementJDBC.batchDiscreteElements(elements, getTaxonLabelHome().getConnection()); + return tbMatrix; + } + + /** + * + * @param xmlMatrix + * @return + */ + private Matrix fromXmlToTreeBase(org.nexml.model.ContinuousMatrix xmlMatrix) { + ContinuousMatrix tbMatrix = new ContinuousMatrix(); + ContinuousMatrixJDBC matrixJDBC = new ContinuousMatrixJDBC(tbMatrix, xmlMatrix, this); + List<MatrixColumnJDBC> columnJDBCs = new ArrayList<MatrixColumnJDBC>(); + long[] colIds = matrixJDBC.getColIDs(); + long[] rowIds = matrixJDBC.getRowIDs(); + List<ContinuousMatrixElementJDBC> elements = new ArrayList<ContinuousMatrixElementJDBC>(); + + int colIndex = 0; + for ( org.nexml.model.Character xmlCharacter : xmlMatrix.getCharacters() ) { + String charName = xmlCharacter.getLabel(); + ContinuousChar tbChar = new ContinuousChar(); + tbChar.setDescription(charName); + MatrixColumnJDBC aColumnJDBC = new MatrixColumnJDBC(); + aColumnJDBC.setPhyloChar(tbChar); + columnJDBCs.add(aColumnJDBC); + int rowIndex = 0; + for ( OTU xmlOTU : xmlMatrix.getOTUs().getAllOTUs() ) { + MatrixCell<Double> xmlCell = xmlMatrix.getCell(xmlOTU, xmlCharacter); + ContinuousMatrixElementJDBC element = new ContinuousMatrixElementJDBC(); + element.setValue(xmlCell.getValue()); + element.setElementOrder(colIndex); + element.setMatrixRowID(rowIds[rowIndex]); + element.setMatrixColID(colIds[colIndex]); + elements.add(element); + rowIndex++; + } + colIndex++; + } + ContinuousMatrixElementJDBC.batchContinuousElements(elements, getTaxonLabelHome().getConnection()); + return tbMatrix; + } + + /** + * + * @param xmlMatrix + * @return + */ + public Matrix fromXmlToTreeBase(org.nexml.model.Matrix<?> xmlMatrix) { + OTUs xmlOTUs = xmlMatrix.getOTUs(); + Matrix tbMatrix = null; + TaxonLabelSet tbTaxa = null; + Long tbTaxonLabelSetID = readTreeBaseID((Annotatable) xmlOTUs); + if ( null != tbTaxonLabelSetID ) { + tbTaxa = getTaxonLabelHome() + .findPersistedObjectByID(TaxonLabelSet.class, tbTaxonLabelSetID); + } + if ( xmlMatrix instanceof CategoricalMatrix ) { + tbMatrix = fromXmlToTreeBase((CategoricalMatrix) xmlMatrix); + } + else if ( xmlMatrix instanceof org.nexml.model.ContinuousMatrix ) { + tbMatrix = fromXmlToTreeBase((org.nexml.model.ContinuousMatrix) xmlMatrix); + } + if ( null != tbMatrix ) { + attachTreeBaseID((Annotatable) xmlMatrix, tbMatrix,Matrix.class); + if ( null != tbTaxa ) { + tbMatrix.setTaxa(tbTaxa); + } + tbMatrix.setStudy(getStudy()); + tbMatrix.setTitle(xmlMatrix.getLabel()); + tbMatrix.setPublished(false); + } + return tbMatrix; + } + +} Copied: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixWriter.java (from rev 970, trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixConverter.java) =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixWriter.java (rev 0) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixWriter.java 2011-10-13 16:26:47 UTC (rev 971) @@ -0,0 +1,622 @@ +package org.cipres.treebase.domain.nexus.nexml; + +import java.util.Collection; +import java.util.List; +import java.util.Set; + +import org.cipres.treebase.Constants; +import org.cipres.treebase.domain.matrix.CharSet; +import org.cipres.treebase.domain.matrix.CharacterMatrix; +import org.cipres.treebase.domain.matrix.ColumnRange; +impo... [truncated message content] |
From: <rv...@us...> - 2011-10-27 16:58:23
|
Revision: 974 http://treebase.svn.sourceforge.net/treebase/?rev=974&view=rev Author: rvos Date: 2011-10-27 16:58:16 +0000 (Thu, 27 Oct 2011) Log Message: ----------- So far, the NeXML converters were working on the assumption that a single study/nexusdataset would be converted to NeXML. It turns out there are use cases where a search result set needs to be converted. This means that we also want to be able to generate NeXML documents that don't have all the annotations that go with serializing a single study (e.g. its ID, authors, title, etc.), but rather a place holder document into which search results (e.g. entire studies, sets of taxa, matrices, trees) can be added and jointly serialized. This commit includes some refactorings in the Nexml*Writer classes and a JUnit test class that demonstrates this new behavior. Modified Paths: -------------- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentWriter.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixWriter.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlOTUWriter.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlObjectConverter.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockWriter.java Added Paths: ----------- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlSearchResultConverterTest.java Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentWriter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentWriter.java 2011-10-13 18:50:53 UTC (rev 973) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentWriter.java 2011-10-27 16:58:16 UTC (rev 974) @@ -1,12 +1,28 @@ package org.cipres.treebase.domain.nexus.nexml; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import org.cipres.treebase.Constants; import org.cipres.treebase.domain.matrix.CharacterMatrix; +import org.cipres.treebase.domain.matrix.Matrix; import org.cipres.treebase.domain.nexus.NexusDataSet; +import org.cipres.treebase.domain.search.MatrixSearchResults; +import org.cipres.treebase.domain.search.SearchResults; +import org.cipres.treebase.domain.search.SearchResultsType; +import org.cipres.treebase.domain.search.StudySearchResults; +import org.cipres.treebase.domain.search.TaxonSearchResults; +import org.cipres.treebase.domain.search.TreeSearchResults; import org.cipres.treebase.domain.study.Study; +import org.cipres.treebase.domain.taxon.Taxon; +import org.cipres.treebase.domain.taxon.TaxonLabel; import org.cipres.treebase.domain.taxon.TaxonLabelHome; import org.cipres.treebase.domain.taxon.TaxonLabelSet; +import org.cipres.treebase.domain.tree.PhyloTree; import org.nexml.model.Document; +import org.nexml.model.OTUs; +import org.nexml.model.TreeBlock; public class NexmlDocumentWriter extends NexmlObjectConverter { @@ -41,7 +57,7 @@ NexmlMatrixWriter nmc = new NexmlMatrixWriter(getStudy(),getTaxonLabelHome(),getDocument()); for (org.cipres.treebase.domain.matrix.Matrix matrix : pNexusDataSet.getMatrices() ) { if ( matrix instanceof CharacterMatrix ) { - nmc.fromTreeBaseToXml((CharacterMatrix)matrix); + nmc.fromTreeBaseToXml((CharacterMatrix)matrix,null); } } @@ -71,7 +87,7 @@ NexmlMatrixWriter nmc = new NexmlMatrixWriter(getStudy(),getTaxonLabelHome(),getDocument()); for (org.cipres.treebase.domain.matrix.Matrix matrix : pStudy.getMatrices() ) { if ( matrix instanceof CharacterMatrix ) { - nmc.fromTreeBaseToXml((CharacterMatrix)matrix); + nmc.fromTreeBaseToXml((CharacterMatrix)matrix,null); } } @@ -82,5 +98,91 @@ return getDocument(); } + + public Document fromTreeBaseToXml(SearchResults<?> searchResults) { + getDocument().addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using "+this.toString()+" $Rev$"); + SearchResultsType srt = searchResults.resultType(); + switch(srt) { + case STUDY : return fromTreeBaseToXml((StudySearchResults) searchResults); + case MATRIX : return fromTreeBaseToXml((MatrixSearchResults) searchResults); + case TREE : return fromTreeBaseToXml((TreeSearchResults) searchResults); + case TAXON : return fromTreeBaseToXml((TaxonSearchResults) searchResults); + case NONE : ; break; + } + return null; + } + + public Document fromTreeBaseToXml(StudySearchResults searchResults) { + NexmlOTUWriter noc = new NexmlOTUWriter(null,getTaxonLabelHome(),getDocument()); + NexmlMatrixWriter nmc = new NexmlMatrixWriter(null,getTaxonLabelHome(),getDocument()); + NexmlTreeBlockWriter ntc = new NexmlTreeBlockWriter(null,getTaxonLabelHome(),getDocument()); + for ( Study pStudy : searchResults.getResults() ) { + for ( TaxonLabelSet taxonLabelSet : pStudy.getTaxonLabelSets() ) { + noc.fromTreeBaseToXml(taxonLabelSet); + } + for (org.cipres.treebase.domain.matrix.Matrix matrix : pStudy.getMatrices() ) { + if ( matrix instanceof CharacterMatrix ) { + nmc.fromTreeBaseToXml((CharacterMatrix)matrix,null); + } + } + for ( org.cipres.treebase.domain.tree.TreeBlock treeBlock : pStudy.getTreeBlocks() ) { + ntc.fromTreeBaseToXML(treeBlock); + } + } + return getDocument(); + } + + public Document fromTreeBaseToXml(MatrixSearchResults searchResults) { + + // create a merged set of all taxon labels in all matrices + Set<TaxonLabel> mergedLabels = new HashSet<TaxonLabel>(); + for (Matrix m : searchResults.getResults()) { + List<TaxonLabel> labelsInTree = m.getAllTaxonLabels(); + mergedLabels.addAll(labelsInTree); + } + + // convert merged set of taxon labels to XML OTUs + NexmlOTUWriter noc = new NexmlOTUWriter(null,getTaxonLabelHome(),getDocument()); + OTUs xmlOTUs = noc.fromTreeBaseToXml(mergedLabels); + + // convert matrices to XML trees + NexmlMatrixWriter nmc = new NexmlMatrixWriter(null,getTaxonLabelHome(),getDocument()); + for (Matrix m : searchResults.getResults()) { + nmc.fromTreeBaseToXml((CharacterMatrix)m,xmlOTUs); + } + + return getDocument(); + } + public Document fromTreeBaseToXml(TreeSearchResults searchResults) { + + // create a merged set of all taxon labels in all trees + Set<TaxonLabel> mergedLabels = new HashSet<TaxonLabel>(); + for (PhyloTree t : searchResults.getResults()) { + Set<TaxonLabel> labelsInTree = t.getAllTaxonLabels(); + mergedLabels.addAll(labelsInTree); + } + + // convert merged set of taxon labels to XML OTUs + NexmlOTUWriter noc = new NexmlOTUWriter(null,getTaxonLabelHome(),getDocument()); + OTUs xmlOTUs = noc.fromTreeBaseToXml(mergedLabels); + + // convert phylotrees to XML trees + NexmlTreeBlockWriter ntc = new NexmlTreeBlockWriter(null,getTaxonLabelHome(),getDocument()); + TreeBlock xmlTreeBlock = getDocument().createTreeBlock(xmlOTUs); + for (PhyloTree t : searchResults.getResults()) { + ntc.fromTreeBaseToXml(t, xmlTreeBlock); + } + return getDocument(); + } + + public Document fromTreeBaseToXml(TaxonSearchResults searchResults) { + NexmlOTUWriter noc = new NexmlOTUWriter(null,getTaxonLabelHome(),getDocument()); + OTUs xmlOTUs = getDocument().createOTUs(); + for (Taxon t : searchResults.getResults()) { + noc.fromTreeBaseToXml(t, xmlOTUs); + } + return getDocument(); + } + } Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixWriter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixWriter.java 2011-10-13 18:50:53 UTC (rev 973) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixWriter.java 2011-10-27 16:58:16 UTC (rev 974) @@ -57,8 +57,10 @@ * @param tbMatrix * @return an xml matrix with empty rows */ - private CategoricalMatrix fromTreeBaseToXml(StandardMatrix tbMatrix) { - OTUs xmlOTUs = getOTUsById(tbMatrix.getTaxa().getId()); + private CategoricalMatrix fromTreeBaseToXml(StandardMatrix tbMatrix,OTUs xmlOTUs) { + if ( null == xmlOTUs ) { + xmlOTUs = getOTUsById(tbMatrix.getTaxa().getId()); + } CategoricalMatrix xmlMatrix = getDocument().createCategoricalMatrix(xmlOTUs); setMatrixAttributes(xmlMatrix,tbMatrix); @@ -108,8 +110,10 @@ * @param tbMatrix * @return an xml matrix with empty rows */ - private MolecularMatrix fromTreeBaseToXml(DiscreteMatrix tbMatrix) { - OTUs xmlOTUs = getOTUsById(tbMatrix.getTaxa().getId()); + private MolecularMatrix fromTreeBaseToXml(DiscreteMatrix tbMatrix,OTUs xmlOTUs) { + if ( null == xmlOTUs ) { + xmlOTUs = getOTUsById(tbMatrix.getTaxa().getId()); + } String tbDataType = tbMatrix.getDataType().getDescription(); MolecularMatrix xmlMatrix = null; CharacterStateSet xmlStateSet = null; @@ -156,8 +160,10 @@ * @param tbMatrix * @return an xml matrix with empty rows */ - private org.nexml.model.ContinuousMatrix fromTreeBaseToXml(ContinuousMatrix tbMatrix) { - OTUs xmlOTUs = getOTUsById(tbMatrix.getTaxa().getId()); + private org.nexml.model.ContinuousMatrix fromTreeBaseToXml(ContinuousMatrix tbMatrix,OTUs xmlOTUs) { + if ( null == xmlOTUs ) { + xmlOTUs = getOTUsById(tbMatrix.getTaxa().getId()); + } org.nexml.model.ContinuousMatrix xmlMatrix = getDocument().createContinuousMatrix(xmlOTUs); setMatrixAttributes(xmlMatrix,tbMatrix); @@ -204,19 +210,19 @@ // public static final String MATRIX_DATATYPE_DISTANCE = "Distance"; // public static final String MATRIX_DATATYPE_MIXED = "Mixed"; @SuppressWarnings("unchecked") - public org.nexml.model.Matrix<?> fromTreeBaseToXml(CharacterMatrix tbMatrix) { + public org.nexml.model.Matrix<?> fromTreeBaseToXml(CharacterMatrix tbMatrix,OTUs xmlOTUs) { org.nexml.model.Matrix<?> xmlMatrix = null; if ( tbMatrix instanceof DiscreteMatrix ) { if ( tbMatrix.getDataType().getDescription().equals(MatrixDataType.MATRIX_DATATYPE_STANDARD) ) { - xmlMatrix = fromTreeBaseToXml((StandardMatrix) tbMatrix); + xmlMatrix = fromTreeBaseToXml((StandardMatrix) tbMatrix,xmlOTUs); } else { - xmlMatrix = fromTreeBaseToXml((DiscreteMatrix) tbMatrix); + xmlMatrix = fromTreeBaseToXml((DiscreteMatrix) tbMatrix,xmlOTUs); } populateXmlMatrix((org.nexml.model.Matrix<CharacterState>)xmlMatrix,(DiscreteMatrix)tbMatrix); } else if ( tbMatrix instanceof ContinuousMatrix ) { - xmlMatrix = fromTreeBaseToXml((ContinuousMatrix) tbMatrix); + xmlMatrix = fromTreeBaseToXml((ContinuousMatrix) tbMatrix,xmlOTUs); populateXmlMatrix((org.nexml.model.ContinuousMatrix)xmlMatrix,(ContinuousMatrix)tbMatrix); } Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlOTUWriter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlOTUWriter.java 2011-10-13 18:50:53 UTC (rev 973) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlOTUWriter.java 2011-10-27 16:58:16 UTC (rev 974) @@ -1,7 +1,10 @@ package org.cipres.treebase.domain.nexus.nexml; +import java.util.Set; + import org.cipres.treebase.Constants; import org.cipres.treebase.domain.study.Study; +import org.cipres.treebase.domain.taxon.Taxon; import org.cipres.treebase.domain.taxon.TaxonLabel; import org.cipres.treebase.domain.taxon.TaxonLabelHome; import org.cipres.treebase.domain.taxon.TaxonLabelSet; @@ -42,11 +45,30 @@ /** * + * @param taxonLabelSet + * @return + */ + protected OTUs fromTreeBaseToXml(Set<TaxonLabel> taxonLabelSet) { + OTUs xmlOTUs = getDocument().createOTUs(); + + // attach base uri and skos:historyNote + xmlOTUs.setBaseURI(mTaxonBaseURI); + xmlOTUs.addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using "+this.toString()+" $Rev$"); + + for ( TaxonLabel taxonLabel : taxonLabelSet ) { + fromTreeBaseToXml(taxonLabel,xmlOTUs); + } + return xmlOTUs; + + } + + /** + * * @param taxonLabel * @param xmlOTUs * @return */ - private OTU fromTreeBaseToXml(TaxonLabel taxonLabel,OTUs xmlOTUs) { + protected OTU fromTreeBaseToXml(TaxonLabel taxonLabel,OTUs xmlOTUs) { OTU xmlOTU = xmlOTUs.createOTU(); if ( null != taxonLabel.getTaxonLabel() ) { xmlOTU.setLabel(taxonLabel.getTaxonLabel()); @@ -54,5 +76,20 @@ attachTreeBaseID(xmlOTU,taxonLabel,TaxonLabel.class); return xmlOTU; } + + /** + * + * @param taxon + * @param xmlOTUs + * @return + */ + protected OTU fromTreeBaseToXml(Taxon taxon,OTUs xmlOTUs) { + OTU xmlOTU = xmlOTUs.createOTU(); + if ( null != taxon.getLabel() ) { + xmlOTU.setLabel(taxon.getLabel()); + } + attachTreeBaseID(xmlOTU,taxon,Taxon.class); + return xmlOTU; + } } Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlObjectConverter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlObjectConverter.java 2011-10-13 18:50:53 UTC (rev 973) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlObjectConverter.java 2011-10-27 16:58:16 UTC (rev 974) @@ -36,7 +36,9 @@ if ( null != baseURI ) { document.setBaseURI(URI.create(baseURI)); } - document.setId(study.getTreebaseIDString().toString()); + if ( null != study ) { + document.setId(study.getTreebaseIDString().toString()); + } setTaxonLabelHome(taxonLabelHome); setStudy(study); setDocument(document); Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockWriter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockWriter.java 2011-10-13 18:50:53 UTC (rev 973) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockWriter.java 2011-10-27 16:58:16 UTC (rev 974) @@ -33,7 +33,7 @@ * @param phyloTree * @return */ - private Tree<?> fromTreeBaseToXml(PhyloTree phyloTree,org.nexml.model.TreeBlock xmlTreeBlock) { + protected Tree<?> fromTreeBaseToXml(PhyloTree phyloTree,org.nexml.model.TreeBlock xmlTreeBlock) { Tree<FloatEdge> xmlTree = xmlTreeBlock.createFloatTree(); if ( null != phyloTree.getLabel() ) { xmlTree.setLabel(phyloTree.getLabel()); Added: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlSearchResultConverterTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlSearchResultConverterTest.java (rev 0) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/nexus/NexmlSearchResultConverterTest.java 2011-10-27 16:58:16 UTC (rev 974) @@ -0,0 +1,133 @@ +package org.cipres.treebase.domain.nexus; + +import java.util.Collection; +import java.util.HashSet; + +import org.cipres.treebase.dao.AbstractDAOTest; +import org.cipres.treebase.domain.matrix.Matrix; +import org.cipres.treebase.domain.search.MatrixSearchResults; +import org.cipres.treebase.domain.search.StudySearchResults; +import org.cipres.treebase.domain.search.TaxonSearchResults; +import org.cipres.treebase.domain.search.TreeSearchResults; +import org.cipres.treebase.domain.study.Study; +import org.cipres.treebase.domain.study.StudyHome; +import org.cipres.treebase.domain.taxon.TaxonLabel; +import org.cipres.treebase.domain.taxon.TaxonLabelHome; +import org.cipres.treebase.domain.tree.PhyloTree; +import org.cipres.treebase.domain.nexus.nexml.NexmlDocumentWriter; +import org.nexml.model.Document; +import org.nexml.model.DocumentFactory; + +public class NexmlSearchResultConverterTest extends AbstractDAOTest { + + private TaxonLabelHome mTaxonLabelHome; + private StudyHome mStudyHome; + + private StudySearchResults ssr = null; + + private Collection<Study> studies = null; + private Collection<Matrix> matrices = null; + private Collection<PhyloTree> trees = null; + private Collection<TaxonLabel> taxa = null; + + @Override + protected void onSetUp() throws Exception { + super.onSetUp(); + + studies = getTestData(); + ssr = new StudySearchResults(studies); + + // populate set of matrices from test data + matrices = new HashSet<Matrix> (); + for (Study s : studies) { + matrices.addAll(s.getMatrices()); + } + + // populate set of trees from test data + trees = new HashSet<PhyloTree> (); + for (Study s : studies) { + trees.addAll(s.getTrees()); + } + + // populate set of taxa from test data + taxa = new HashSet<TaxonLabel>(); + for ( Study s : studies) { + taxa.addAll(s.getTaxonLabels()); + } + } + + public NexmlSearchResultConverterTest() { + super(); + } + + public void testTrivial() { + assertNotNull(getTaxonLabelHome()); + assertNotNull(getStudyHome()); + } + + public void testQuickCheck() { + assertFalse(studies.size() == 0); + assertFalse(matrices.size() == 0); + assertFalse(trees.size() == 0); + assertFalse(taxa.size() == 0); + } + + private Collection<Study> getTestData(String accessionNumber) { + Collection<Study> studies = new HashSet<Study>(); + studies.add(getStudyHome().findByAccessionNumber(accessionNumber)); + assertFalse(studies.size() == 0); + return studies; + } + + private Collection<Study> getTestData() { + return getTestData("S1787"); + } + + public void testStudySearchSerialization() { + Document doc = DocumentFactory.safeCreateDocument(); + NexmlDocumentWriter ndw = new NexmlDocumentWriter(null, mTaxonLabelHome, doc); + ndw.fromTreeBaseToXml(ssr); + assertNotNull(doc.getXmlString()); + } + + public void testTaxonSearchSerialization() { + Document doc = DocumentFactory.safeCreateDocument(); + NexmlDocumentWriter ndw = new NexmlDocumentWriter(null, mTaxonLabelHome, doc); + TaxonSearchResults tasr = ssr.convertToTaxa(); + ndw.fromTreeBaseToXml(tasr); + assertNotNull(doc.getXmlString()); + } + + public void testMatrixSearchSerialization() { + Document doc = DocumentFactory.safeCreateDocument(); + NexmlDocumentWriter ndw = new NexmlDocumentWriter(null, mTaxonLabelHome, doc); + MatrixSearchResults msr = ssr.convertToMatrices(); + ndw.fromTreeBaseToXml(msr); + assertNotNull(doc.getXmlString()); + } + + public void testTreeSearchSerialization() { + Document doc = DocumentFactory.safeCreateDocument(); + NexmlDocumentWriter ndw = new NexmlDocumentWriter(null, mTaxonLabelHome, doc); + TreeSearchResults tsr = ssr.convertToTrees(); + ndw.fromTreeBaseToXml(tsr); + assertNotNull(doc.getXmlString()); + } + + public TaxonLabelHome getTaxonLabelHome() { + return mTaxonLabelHome; + } + + public void setTaxonLabelHome(TaxonLabelHome pNewTaxonLabelHome) { + mTaxonLabelHome = pNewTaxonLabelHome; + } + + public StudyHome getStudyHome() { + return mStudyHome; + } + + public void setStudyHome(StudyHome studyHome) { + mStudyHome = studyHome; + } + +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2012-02-01 21:00:38
|
Revision: 1029 http://treebase.svn.sourceforge.net/treebase/?rev=1029&view=rev Author: rvos Date: 2012-02-01 21:00:31 +0000 (Wed, 01 Feb 2012) Log Message: ----------- Adding state set mappers, which help translate character state sequences from ones that contain mini-syntax for indicating ambiguity as {ACGT} to IUPAC single character ambiguity codes such as N. Added Paths: ----------- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapper.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapperDna.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapperProtein.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapperRna.java trunk/treebase-core/src/test/java/org/cipres/treebase/domain/matrix/StateSetMapperTest.java Added: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapper.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapper.java (rev 0) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapper.java 2012-02-01 21:00:31 UTC (rev 1029) @@ -0,0 +1,93 @@ +package org.cipres.treebase.domain.matrix; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + +/** + * This class (and its subclasses) help with mapping between sets + * of fundamental states (such as {ACGT}) and IUPAC single character + * ambiguity symbols. This is especially important for valid NeXML + * generation, which requires that molecular <seq> elements only + * contain single character symbols, not sets. + * @author rvosa + * + */ +public abstract class StateSetMapper { + private Map<Character,HashSet<Character>> symbolToAmbig; + private Map<HashSet<Character>,Character> ambigToSymbol; + + /** + * Returns a map keyed on IUPAC single character ambiguity symbols + * http://droog.gs.washington.edu/parc/images/iupac.html with values + * containing a set (possibly of 1) with fundamental states. + * @return + */ + protected abstract Map<Character,HashSet<Character>> makeSymbolToAmbigMap(); + + + public StateSetMapper () { + symbolToAmbig = makeSymbolToAmbigMap(); + ambigToSymbol = new HashMap<HashSet<Character>,Character>(); + for ( Character key : symbolToAmbig.keySet() ) { + HashSet<Character> value = symbolToAmbig.get(key); + ambigToSymbol.put(value, key); + } + } + + /** + * Instantiates appropriate subclass given datatype + * @param datatype - one of the types in MatrixDataType + * @return + */ + public static StateSetMapper createMapperForDataType(String datatype) { + if ( MatrixDataType.MATRIX_DATATYPE_DNA.equals(datatype) ) { + return new StateSetMapperDna(); + } + else if ( MatrixDataType.MATRIX_DATATYPE_RNA.equals(datatype) ) { + return new StateSetMapperRna(); + } + else if ( MatrixDataType.MATRIX_DATATYPE_PROTEIN.equals(datatype) ) { + return new StateSetMapperProtein(); + } + else { + return null; + } + } + + /** + * Looks up the IUPAC single character symbol for a set of fundamental states + * @return + */ + public Character getSymbolForAmbiguousSet(HashSet<Character> ambiguousSet) { + return ambigToSymbol.get(ambiguousSet); + } + + /** + * Looks up the set of fundamental states for an IUPAC single character symbol + * @return + */ + public HashSet<Character> getAmbiguousSetForSymbol(Character symbol) { + return symbolToAmbig.get(symbol); + } + + /** + * Returns a data type from MatrixDataType.MATRIX_DATATYPE_.* + * @return + */ + public abstract String getDataType(); + + /** + * Helper method for populating the underlying Map object + * @param symbol + * @param symbolArray + * @param result + */ + protected void addMapping(Character symbol,Character[] symbolArray,Map<Character, HashSet<Character>> result) { + HashSet<Character> symbolSet = new HashSet<Character>(symbolArray.length); + for ( int i = 0; i < symbolArray.length; i++ ) { + symbolSet.add(symbolArray[i]); + } + result.put(symbol, symbolSet); + } +} Added: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapperDna.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapperDna.java (rev 0) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapperDna.java 2012-02-01 21:00:31 UTC (rev 1029) @@ -0,0 +1,65 @@ +package org.cipres.treebase.domain.matrix; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import org.cipres.treebase.domain.matrix.MatrixDataType; + +public class StateSetMapperDna extends StateSetMapper { + + /* + * (non-Javadoc) + * @see org.cipres.treebase.domain.matrix.StateSetMapper#makeSymbolToAmbigMap() + */ + @Override + protected Map<Character, HashSet<Character>> makeSymbolToAmbigMap() { + return this.makeSymbolToAmbigMapWithSymbols('A', 'C', 'G', 'T'); + } + + /** + * + * @param A + * @param C + * @param G + * @param T + * @return + */ + protected Map<Character, HashSet<Character>> makeSymbolToAmbigMapWithSymbols(char A, char C, char G, char T) { + Map<Character, HashSet<Character>> result = new HashMap<Character, HashSet<Character>>(); + + addMapping(A,new Character[]{A}, result); // A + addMapping(C,new Character[]{C}, result); // C + addMapping(G,new Character[]{G}, result); // G + addMapping(T,new Character[]{T}, result); // T + + addMapping('M',new Character[]{A,C}, result); // M => (A,C) + addMapping('R',new Character[]{A,G}, result); // R => (A,G) + addMapping('W',new Character[]{A,T}, result); // W => (A,T) + addMapping('S',new Character[]{C,G}, result); // S => (C,G) + addMapping('Y',new Character[]{C,T}, result); // Y => (C,T) XXX + addMapping('K',new Character[]{G,T}, result); // K => (G,T) + + addMapping('V',new Character[]{A,C,G}, result); // V => (A,C,G) + addMapping('H',new Character[]{A,C,T}, result); // H => (A,C,T) + addMapping('D',new Character[]{A,G,T}, result); // D => (A,G,T) + addMapping('B',new Character[]{C,G,T}, result); // B => (C,G,T) + + addMapping('N',new Character[]{A,C,G,T}, result); // N => (A,C,G,T) + addMapping('?',new Character[]{A,C,G,T,'-'}, result); // ? => (A,C,G,T,-) + addMapping('-',new Character[]{'-'}, result); // - => () + + return result; + } + + /** + * Returns MatrixDataType.MATRIX_DATATYPE_DNA + */ + @Override + public String getDataType() { + return MatrixDataType.MATRIX_DATATYPE_DNA; + } + + + + +} Added: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapperProtein.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapperProtein.java (rev 0) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapperProtein.java 2012-02-01 21:00:31 UTC (rev 1029) @@ -0,0 +1,56 @@ +package org.cipres.treebase.domain.matrix; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import org.cipres.treebase.domain.matrix.MatrixDataType; + +public class StateSetMapperProtein extends StateSetMapper { + + /* + * (non-Javadoc) + * @see org.cipres.treebase.domain.matrix.StateSetMapper#makeSymbolToAmbigMap() + */ + @Override + protected Map<Character, HashSet<Character>> makeSymbolToAmbigMap() { + Map<Character, HashSet<Character>> result = new HashMap<Character, HashSet<Character>>(); + + addMapping('A',new Character[]{'A'}, result); // Alanine + addMapping('B',new Character[]{'B'}, result); // Aspartic acid or asparagine + addMapping('C',new Character[]{'C'}, result); // Cysteine + addMapping('D',new Character[]{'D'}, result); // Aspartic acid + addMapping('E',new Character[]{'E'}, result); // Glutamic acid + addMapping('F',new Character[]{'F'}, result); // Phenylanine + addMapping('G',new Character[]{'G'}, result); // Glycine + addMapping('H',new Character[]{'H'}, result); // Histidine + addMapping('I',new Character[]{'I'}, result); // Isoleucine + addMapping('K',new Character[]{'K'}, result); // Lysine + addMapping('L',new Character[]{'L'}, result); // Leucine + addMapping('M',new Character[]{'M'}, result); // Methionine + addMapping('N',new Character[]{'N'}, result); // Asparagine + addMapping('P',new Character[]{'P'}, result); // Proline + addMapping('Q',new Character[]{'Q'}, result); // Glutamine + addMapping('R',new Character[]{'R'}, result); // Arginine + addMapping('S',new Character[]{'S'}, result); // Serine + addMapping('T',new Character[]{'T'}, result); // Threonine + addMapping('U',new Character[]{'U'}, result); // Selenocysteine + addMapping('V',new Character[]{'V'}, result); // Valine + addMapping('W',new Character[]{'W'}, result); // Tryptophan + addMapping('Y',new Character[]{'Y'}, result); // Tyrosine + addMapping('Z',new Character[]{'Z'}, result); // Glutamic acid or glutamine + addMapping('X',new Character[]{'A','B','C','D','E','F','G','H','I','K','L','M','N','P','Q','R','S','T','U','V','W','Y','Z'}, result); + addMapping('?',new Character[]{'A','B','C','D','E','F','G','H','I','K','L','M','N','P','Q','R','S','T','U','V','W','Y','Z','-'}, result); + addMapping('-',new Character[]{'-'}, result); + + return result; + } + + /** + * Returns MatrixDataType.MATRIX_DATATYPE_PROTEIN + */ + @Override + public String getDataType() { + return MatrixDataType.MATRIX_DATATYPE_PROTEIN; + } + +} Added: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapperRna.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapperRna.java (rev 0) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/matrix/StateSetMapperRna.java 2012-02-01 21:00:31 UTC (rev 1029) @@ -0,0 +1,25 @@ +package org.cipres.treebase.domain.matrix; + +import java.util.HashSet; +import java.util.Map; +import org.cipres.treebase.domain.matrix.MatrixDataType; + +public class StateSetMapperRna extends StateSetMapperDna { + + /* + * (non-Javadoc) + * @see org.cipres.treebase.domain.matrix.StateSetMapperDna#makeSymbolToAmbigMap() + */ + @Override + protected Map<Character, HashSet<Character>> makeSymbolToAmbigMap() { + return makeSymbolToAmbigMapWithSymbols('A', 'C', 'G', 'U'); + } + + /** + * Returns MatrixDataType.MATRIX_DATATYPE_RNA + */ + @Override + public String getDataType() { + return MatrixDataType.MATRIX_DATATYPE_RNA; + } +} Added: trunk/treebase-core/src/test/java/org/cipres/treebase/domain/matrix/StateSetMapperTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/domain/matrix/StateSetMapperTest.java (rev 0) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/domain/matrix/StateSetMapperTest.java 2012-02-01 21:00:31 UTC (rev 1029) @@ -0,0 +1,54 @@ +package org.cipres.treebase.domain.matrix; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.cipres.treebase.domain.matrix.MatrixDataType; +import org.cipres.treebase.domain.matrix.MatrixRow; +import org.cipres.treebase.domain.matrix.StateSetMapper; + +public class StateSetMapperTest extends TestCase { + /** + * The inputSeq contains all possible permutations of the fundamental + * states, which are to be mapped onto the IUPAC single character symbols + */ + public void testDnaMapper() { + String inputSeq = "ACGTK{GT}M{AC}R{AG}S{CG}W{AT}B{CGT}D{AGT}H{ACT}V{ACG}N{ACGT}-?{ACGT-}"; + String outputSeq = "ACGTKKMMRRSSWWBBDDHHVVNN-??"; + String result = MatrixRow.buildNormalizedSymbolString(StateSetMapper.createMapperForDataType(MatrixDataType.MATRIX_DATATYPE_DNA), inputSeq); + Assert.assertEquals(outputSeq, result); + } + + /** + * The inputSeq contains all possible permutations of the fundamental + * states, which are to be mapped onto the IUPAC single character symbols + */ + public void testRnaMapper() { + String inputSeq = "ACGUK{GU}M{AC}R{AG}S{CG}W{AU}B{CGU}D{AGU}H{ACU}V{ACG}N{ACGU}-?{ACGU-}"; + String outputSeq = "ACGUKKMMRRSSWWBBDDHHVVNN-??"; + String result = MatrixRow.buildNormalizedSymbolString(StateSetMapper.createMapperForDataType(MatrixDataType.MATRIX_DATATYPE_RNA), inputSeq); + Assert.assertEquals(outputSeq, result); + } + + /** + * The inputSeq contains all possible permutations of the fundamental + * states, which are to be mapped onto the IUPAC single character symbols + */ + public void testProteinMapper() { + String inputSeq = "ABCDEFGHIKLMNPQRSTUVWYZ{ABCDEFGHIKLMNPQRSTUVWYZ}{ABCDEFGHIKLMNPQRSTUVWYZ-}-"; + String outputSeq = "ABCDEFGHIKLMNPQRSTUVWYZX?-"; + String result = MatrixRow.buildNormalizedSymbolString(StateSetMapper.createMapperForDataType(MatrixDataType.MATRIX_DATATYPE_PROTEIN), inputSeq); + Assert.assertEquals(outputSeq, result); + } + + /** + * For STANDARD data there is no implied mapping. For now we will simply + * pass these through, though that's technically not valid. + */ + public void testStandardMapper() { + String inputSeq = "012{1}"; + String outputSeq = "012{1}"; + String result = MatrixRow.buildNormalizedSymbolString(StateSetMapper.createMapperForDataType(MatrixDataType.MATRIX_DATATYPE_STANDARD), inputSeq); + Assert.assertEquals(outputSeq, result); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2012-02-17 18:17:23
|
Revision: 1072 http://treebase.svn.sourceforge.net/treebase/?rev=1072&view=rev Author: rvos Date: 2012-02-17 18:17:16 +0000 (Fri, 17 Feb 2012) Log Message: ----------- We want to be able to find studies by their DOIs. To make this possible, the interfaces for CitationService and StudyService have been expanded with a findByDoi(String doi) method, the idea being that the StudyService will delegate the query to the CitationService, then get the associated study from the returned citation. This is how it has been implemented in the *Impl classes, and the AuxDataTest needed to be expanded with another method stub to satisfy the interface for the inner class that is used there. Modified Paths: -------------- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/CitationService.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/StudyService.java trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/CitationServiceImpl.java trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/StudyServiceImpl.java trunk/treebase-core/src/test/java/org/cipres/treebase/auxdata/AuxDataTest.java Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/CitationService.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/CitationService.java 2012-02-17 18:13:28 UTC (rev 1071) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/CitationService.java 2012-02-17 18:17:16 UTC (rev 1072) @@ -44,5 +44,12 @@ * @param pCitation */ void replaceCitation(Study pStudy, Citation pCitation); + + /** + * Find the citation with the provided doi + * @param doi + * @return + */ + Citation findByDOI(String doi); } Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/StudyService.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/StudyService.java 2012-02-17 18:13:28 UTC (rev 1071) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/study/StudyService.java 2012-02-17 18:17:16 UTC (rev 1072) @@ -204,4 +204,11 @@ * @author mjd 20080813 */ Collection<Study> findByTaxonLabelName(String taxonLabel); + + /** + * Return the study for publication with provided DOI + * @param doi + * @return + */ + Study findByDOI(String doi); } Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/CitationServiceImpl.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/CitationServiceImpl.java 2012-02-17 18:13:28 UTC (rev 1071) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/CitationServiceImpl.java 2012-02-17 18:17:16 UTC (rev 1072) @@ -2,6 +2,7 @@ package org.cipres.treebase.service.study; import java.util.Calendar; +import java.util.Collection; import org.cipres.treebase.domain.DomainHome; import org.cipres.treebase.domain.study.Citation; @@ -161,4 +162,18 @@ return Citation.class; } + /* + * (non-Javadoc) + * @see org.cipres.treebase.domain.study.CitationService#findByDOI(java.lang.String) + */ + public Citation findByDOI(String doi) { + Collection<Citation> results = findSomethingByString(Citation.class, "doi", doi); + if ( null != results && ! results.isEmpty() ) { + return results.iterator().next(); + } + else { + return null; + } + } + } Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/StudyServiceImpl.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/StudyServiceImpl.java 2012-02-17 18:13:28 UTC (rev 1071) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/service/study/StudyServiceImpl.java 2012-02-17 18:17:16 UTC (rev 1072) @@ -19,6 +19,7 @@ import org.cipres.treebase.domain.matrix.Matrix; import org.cipres.treebase.domain.matrix.MatrixHome; import org.cipres.treebase.domain.study.AnalysisService; +import org.cipres.treebase.domain.study.Citation; import org.cipres.treebase.domain.study.CitationService; import org.cipres.treebase.domain.study.Study; import org.cipres.treebase.domain.study.StudyCriteria; @@ -533,4 +534,14 @@ public Collection<Study> findByPublicationDateRange(Date from, Date until) { return getStudyHome().findByPublicationDateRange(from, until); } + + public Study findByDOI(String doi) { + Citation citation = getCitationService().findByDOI(doi); + if ( null != citation ) { + return citation.getStudy(); + } + else { + return null; + } + } } Modified: trunk/treebase-core/src/test/java/org/cipres/treebase/auxdata/AuxDataTest.java =================================================================== --- trunk/treebase-core/src/test/java/org/cipres/treebase/auxdata/AuxDataTest.java 2012-02-17 18:13:28 UTC (rev 1071) +++ trunk/treebase-core/src/test/java/org/cipres/treebase/auxdata/AuxDataTest.java 2012-02-17 18:17:16 UTC (rev 1072) @@ -368,6 +368,11 @@ // TODO Auto-generated method stub return null; } + + public Study findByDOI(String doi) { + // TODO Auto-generated method stub + return null; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |