From: <rv...@us...> - 2009-06-23 10:52:29
|
Revision: 73 http://treebase.svn.sourceforge.net/treebase/?rev=73&view=rev Author: rvos Date: 2009-06-23 10:52:08 +0000 (Tue, 23 Jun 2009) Log Message: ----------- Now emit valid nexml. Modified 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/NexmlObjectConverter.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/domain/nexus/nexml/NexmlDocumentConverter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentConverter.java 2009-06-23 10:50:48 UTC (rev 72) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentConverter.java 2009-06-23 10:52:08 UTC (rev 73) @@ -1,6 +1,7 @@ package org.cipres.treebase.domain.nexus.nexml; import org.cipres.treebase.domain.admin.Person; +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; @@ -69,7 +70,9 @@ NexmlMatrixConverter nmc = new NexmlMatrixConverter(getStudy(),getTaxonLabelHome(),getDocument()); for (org.cipres.treebase.domain.matrix.Matrix matrix : pNexusDataSet.getMatrices() ) { - nmc.fromTreeBaseToXml(matrix); + if ( matrix instanceof CharacterMatrix ) { + nmc.fromTreeBaseToXml((CharacterMatrix)matrix); + } } NexmlTreeBlockConverter ntc = new NexmlTreeBlockConverter(getStudy(),getTaxonLabelHome(),getDocument()); @@ -87,22 +90,40 @@ * @param document */ private void copyCitationMetadata(Citation citation,Document document) { - attachAnnotation("prism:publicationDate",citation.getPublishYear().toString(),mPrismURI,document); - attachAnnotation("prism:doi",citation.getDoi(),mPrismURI,document); - String[] pages = citation.getPages().split("-"); - if ( pages.length > 2 ) { - attachAnnotation("prism:startingPage",pages[0],mPrismURI,document); - attachAnnotation("prism:endingPage",pages[1],mPrismURI,document); - attachAnnotation("prism:pageRange",citation.getPages(),mPrismURI,document); + if ( null != citation.getTitle() ) { + attachAnnotation("dc:title",citation.getTitle(),mPrismURI,document); } - String[] keywords = citation.getKeywords().split(", "); - for ( int i = 0; i < keywords.length; i++ ) { - attachAnnotation("prism:keyword",keywords[i],mPrismURI,document); - } + if ( null != citation.getPublishYear() ) { + attachAnnotation("prism:publicationDate",citation.getPublishYear().toString(),mPrismURI,document); + } + if ( null != citation.getDoi() ) { + attachAnnotation("prism:doi",citation.getDoi(),mPrismURI,document); + } + if ( null != citation.getPages() ) { + String[] pages = citation.getPages().split("\\-"); + if ( pages.length == 2 ) { + attachAnnotation("prism:startingPage",pages[0],mPrismURI,document); + attachAnnotation("prism:endingPage",pages[1],mPrismURI,document); + attachAnnotation("prism:pageRange",citation.getPages(),mPrismURI,document); + } + } + if ( null != citation.getKeywords() ) { + String[] keywords = citation.getKeywords().split(", "); + for ( int i = 0; i < keywords.length; i++ ) { + attachAnnotation("prism:keyword",keywords[i],mPrismURI,document); + } + } if ( citation instanceof ArticleCitation ) { - attachAnnotation("prism:publicationName",((ArticleCitation)citation).getJournal(),mPrismURI,document); - attachAnnotation("prism:volume",((ArticleCitation)citation).getVolume(),mPrismURI,document); - attachAnnotation("prism:number",((ArticleCitation)citation).getIssue(),mPrismURI,document); + ArticleCitation ac = (ArticleCitation)citation; + if ( null != ac.getJournal() ) { + attachAnnotation("prism:publicationName",ac.getJournal(),mPrismURI,document); + } + if ( null != ac.getVolume() ) { + attachAnnotation("prism:volume",ac.getVolume(),mPrismURI,document); + } + if ( null != ac.getIssue() ) { + attachAnnotation("prism:number",ac.getIssue(),mPrismURI,document); + } } } @@ -112,22 +133,7 @@ * @return */ public Document fromTreeBaseToXml(Study pStudy) { - attachTreeBaseID(getDocument(), pStudy); - attachAnnotation("dc:title", pStudy.getName(), mDCURI, getDocument()); - attachAnnotation("dc:abstract",pStudy.getCitation().getAbstract(), mDCURI,getDocument()); - attachAnnotation( - "dc:creator", - pStudy.getSubmission().getSubmitter().getPerson().getFullNameCitationStyle(), - mDCURI, - getDocument() - ); - for ( Person person : pStudy.getAuthors() ) { - String personName = person.getFullNameCitationStyle(); - attachAnnotation("dc:contributor",personName,mDCURI,getDocument()); - } - attachAnnotation("prism:creationDate",pStudy.getSubmission().getCreateDate().toString(),mPrismURI,getDocument()); - attachAnnotation("prism:embargoDate",pStudy.getReleaseDate().toString(),mPrismURI,getDocument()); - copyCitationMetadata(pStudy.getCitation(),getDocument()); + copyMetadata(pStudy); NexmlOTUConverter noc = new NexmlOTUConverter(getStudy(),getTaxonLabelHome(),getDocument()); for ( TaxonLabelSet taxonLabelSet : pStudy.getTaxonLabelSets() ) { @@ -136,14 +142,48 @@ NexmlMatrixConverter nmc = new NexmlMatrixConverter(getStudy(),getTaxonLabelHome(),getDocument()); for (org.cipres.treebase.domain.matrix.Matrix matrix : pStudy.getMatrices() ) { - nmc.fromTreeBaseToXml(matrix); + 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(); } + private void copyMetadata(Study pStudy) { + attachTreeBaseID(getDocument(), pStudy,Study.class); + if ( null != pStudy.getName() ) { + attachAnnotation("dc:title", pStudy.getName(), mDCURI, getDocument()); + } + for ( Person person : pStudy.getAuthors() ) { + String personName = person.getFullNameCitationStyle(); + attachAnnotation("dc:contributor",personName,mDCURI,getDocument()); + } + if ( null != pStudy.getReleaseDate() ) { + attachAnnotation("prism:embargoDate",pStudy.getReleaseDate().toString(),mPrismURI,getDocument()); + } + if ( null != pStudy.getSubmission() ) { + if ( null != pStudy.getSubmission().getSubmitter() ) { + attachAnnotation( + "dc:creator", + pStudy.getSubmission().getSubmitter().getPerson().getFullNameCitationStyle(), + mDCURI, + getDocument() + ); + } + if ( null != pStudy.getSubmission().getCreateDate() ) { + attachAnnotation("prism:creationDate",pStudy.getSubmission().getCreateDate().toString(),mPrismURI,getDocument()); + } + } + if ( null != pStudy.getCitation() ) { + //attachAnnotation("dc:abstract",forXML(pStudy.getCitation().getAbstract()), mDCURI,getDocument()); + copyCitationMetadata(pStudy.getCitation(),getDocument()); + } + } + } Modified: 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 2009-06-23 10:50:48 UTC (rev 72) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixConverter.java 2009-06-23 10:52:08 UTC (rev 73) @@ -2,29 +2,45 @@ 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.CharacterMatrix; 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.StandardMatrix; 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.ContinuousMatrix; +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; public class NexmlMatrixConverter extends NexmlObjectConverter { + private static final int MAX_GRANULAR_NCHAR = 1000; + private static final int MAX_GRANULAR_NTAX = 30; + /** * * @param study @@ -56,6 +72,7 @@ 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 @@ -76,9 +93,8 @@ * @param xmlMatrix * @return */ - public Matrix fromXmlToTreeBase(ContinuousMatrix xmlMatrix) { - org.cipres.treebase.domain.matrix.ContinuousMatrix tbMatrix = - new org.cipres.treebase.domain.matrix.ContinuousMatrix(); + 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(); @@ -119,7 +135,7 @@ OTUs xmlOTUs = xmlMatrix.getOTUs(); Matrix tbMatrix = null; TaxonLabelSet tbTaxa = null; - Long tbTaxonLabelSetID = readTreeBaseID((Annotatable) xmlOTUs,TaxonLabelSet.class); + Long tbTaxonLabelSetID = readTreeBaseID((Annotatable) xmlOTUs); if ( null != tbTaxonLabelSetID ) { tbTaxa = getTaxonLabelHome() .findPersistedObjectByID(TaxonLabelSet.class, tbTaxonLabelSetID); @@ -127,11 +143,11 @@ if ( xmlMatrix instanceof CategoricalMatrix ) { tbMatrix = fromXmlToTreeBase((CategoricalMatrix) xmlMatrix); } - else if ( xmlMatrix instanceof ContinuousMatrix ) { - tbMatrix = fromXmlToTreeBase((ContinuousMatrix) xmlMatrix); + else if ( xmlMatrix instanceof org.nexml.model.ContinuousMatrix ) { + tbMatrix = fromXmlToTreeBase((org.nexml.model.ContinuousMatrix) xmlMatrix); } if ( null != tbMatrix ) { - attachTreeBaseID((Annotatable) xmlMatrix, tbMatrix); + attachTreeBaseID((Annotatable) xmlMatrix, tbMatrix,Matrix.class); if ( null != tbTaxa ) { tbMatrix.setTaxa(tbTaxa); } @@ -142,21 +158,192 @@ return tbMatrix; } - public org.nexml.model.Matrix<?> fromTreeBaseToXml(Matrix tbMatrix) { - TaxonLabelSet taxonLabelSet = tbMatrix.getTaxa(); - Long taxonLabelSetId = taxonLabelSet.getId(); - OTUs xmlOTUs = null; - for ( OTUs otus : getDocument().getOTUsList() ) { - Long annotatedID = readTreeBaseID(otus, TaxonLabelSet.class); - if ( taxonLabelSetId == annotatedID ) { - xmlOTUs = otus; - break; + /** + * 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); + 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()); + } + if ( null != tbState.getNotes() ) { + ((Annotatable)xmlState).addAnnotationValue("dc:description", mDCURI, tbState.getNotes()); + } + 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,tbCharacter,PhyloChar.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; + 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(); + } + for ( MatrixColumn tbColumn : tbMatrix.getColumnsReadOnly() ) { + org.nexml.model.Character xmlCharacter = xmlMatrix.createCharacter(xmlStateSet); + PhyloChar tbCharacter = tbColumn.getCharacter(); + if ( null != tbCharacter.getDescription() && ! tbCharacter.getDescription().equals(tbDataType) ) { + ((Annotatable)xmlCharacter).addAnnotationValue("dc:description", mDCURI, tbCharacter.getDescription()); + } + if ( null != tbCharacter.getId() && tbCharacter.getId() != 2 ) { // XXX is PhyloChar.id 2 some sort of magic number? + attachTreeBaseID((Annotatable)xmlCharacter,tbCharacter,PhyloChar.class); } } - org.nexml.model.Matrix<?> xmlMatrix = getDocument().createCategoricalMatrix(xmlOTUs); + 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); + for ( MatrixColumn tbColumn : tbMatrix.getColumnsReadOnly() ) { + org.nexml.model.Character xmlCharacter = xmlMatrix.createCharacter(); + PhyloChar tbCharacter = tbColumn.getCharacter(); + if ( null != tbCharacter.getDescription() ) { + ((Annotatable)xmlCharacter).addAnnotationValue("dc:description", mDCURI, tbCharacter.getDescription()); + } + attachTreeBaseID((Annotatable)xmlCharacter,tbCharacter,PhyloChar.class); + } + 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); + attachTreeBaseID((Annotatable)xmlMatrix, tbMatrix,Matrix.class); 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 row : tbMatrix.getRowsReadOnly() ) { + OTU xmlOTU = getOTUById(xmlOTUs, row.getTaxonLabel().getId()); + int charIndex = 0; + if ( characterList.size() <= MAX_GRANULAR_NCHAR && xmlOTUs.getAllOTUs().size() <= MAX_GRANULAR_NTAX ) { + for ( MatrixElement tbCell : row.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); + charIndex++; + } + } + else { + String seq = row.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); + } + } + } + + /** + * + * @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 row : tbMatrix.getRowsReadOnly() ) { + List<MatrixElement> elements = row.getElements(); + OTU xmlOTU = getOTUById(xmlOTUs, row.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 = row.buildElementAsString(); + xmlMatrix.setSeq(seq,xmlOTU); + } + } + } + } Modified: 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/NexmlOTUConverter.java 2009-06-23 10:50:48 UTC (rev 72) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlOTUConverter.java 2009-06-23 10:52:08 UTC (rev 73) @@ -27,9 +27,11 @@ */ public TaxonLabelSet fromXmlToTreeBase (OTUs xmlOTUs) { TaxonLabelSet labelSet = new TaxonLabelSet(); - attachTreeBaseID(xmlOTUs,labelSet); + attachTreeBaseID(xmlOTUs,labelSet,TaxonLabelSet.class); labelSet.setStudy(getStudy()); - labelSet.setTitle(xmlOTUs.getLabel()); + if ( null != xmlOTUs.getLabel() ) { + labelSet.setTitle(xmlOTUs.getLabel()); + } labelSet.setTaxa(true); for ( OTU xmlOTU : xmlOTUs.getAllOTUs() ) { TaxonLabel taxonLabel = fromXmlToTreeBase(xmlOTU); @@ -46,7 +48,7 @@ public OTUs fromTreeBaseToXml(TaxonLabelSet taxonLabelSet) { OTUs xmlOTUs = getDocument().createOTUs(); xmlOTUs.setLabel(taxonLabelSet.getTitle()); - attachTreeBaseID(xmlOTUs,taxonLabelSet); + attachTreeBaseID(xmlOTUs,taxonLabelSet,TaxonLabelSet.class); for ( TaxonLabel taxonLabel : taxonLabelSet.getTaxonLabelsReadOnly() ) { fromTreeBaseToXml(taxonLabel,xmlOTUs); } @@ -61,7 +63,7 @@ public TaxonLabel fromXmlToTreeBase(OTU xmlOTU) { TaxonLabel taxonLabel = getTaxonLabelHome().getByDescriptionAndStudy(xmlOTU.getLabel(), getStudy()); taxonLabel.setStudy(getStudy()); - attachTreeBaseID(xmlOTU,taxonLabel); + attachTreeBaseID(xmlOTU,taxonLabel,TaxonLabel.class); return taxonLabel; } @@ -73,8 +75,10 @@ */ public OTU fromTreeBaseToXml(TaxonLabel taxonLabel,OTUs xmlOTUs) { OTU xmlOTU = xmlOTUs.createOTU(); - xmlOTU.setLabel(taxonLabel.getTaxonLabel()); - attachTreeBaseID(xmlOTU,taxonLabel); + if ( null != taxonLabel.getTaxonLabel() ) { + xmlOTU.setLabel(taxonLabel.getTaxonLabel()); + } + attachTreeBaseID(xmlOTU,taxonLabel,TaxonLabel.class); if ( null != taxonLabel.getNcbiTaxID() ) { attachAnnotation("dc:identifier", "NCBI:" + taxonLabel.getNcbiTaxID(), mDCURI, 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 2009-06-23 10:50:48 UTC (rev 72) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlObjectConverter.java 2009-06-23 10:52:08 UTC (rev 73) @@ -2,16 +2,22 @@ import java.net.URI; import java.net.URISyntaxException; +import java.text.CharacterIterator; +import java.text.StringCharacterIterator; import java.util.Iterator; import java.util.Set; import org.cipres.treebase.TreebaseIDString; +import org.cipres.treebase.NamespacedGUID; +import org.cipres.treebase.TreebaseIDString.MalformedTreebaseIDString; import org.cipres.treebase.domain.TBPersistable; import org.cipres.treebase.domain.nexus.AbstractNexusConverter; import org.cipres.treebase.domain.study.Study; import org.cipres.treebase.domain.taxon.TaxonLabelHome; import org.nexml.model.Annotatable; import org.nexml.model.Document; +import org.nexml.model.OTU; +import org.nexml.model.OTUs; public class NexmlObjectConverter extends AbstractNexusConverter { protected static URI mDCURI; @@ -44,14 +50,9 @@ * @param tbPersistable * @return */ - public String makeNamespacedID (TBPersistable tbPersistable) { - StringBuilder sb = new StringBuilder(); - sb - .append(TreeBASE2Prefix) - .append(':') - .append(TreebaseIDString.getPrefixForClass(tbPersistable.getClass())) - .append(tbPersistable.getId()); - return sb.toString(); + private String makeNamespacedID (TBPersistable tbPersistable,Class<?> persistableClass) { + TreebaseIDString tbIDString = new TreebaseIDString(persistableClass,tbPersistable.getId()); + return tbIDString.getNamespacedGUID().toString(); } /** @@ -59,8 +60,10 @@ * @param annotatable * @param tbPersistable */ - protected void attachTreeBaseID(Annotatable annotatable,TBPersistable tbPersistable) { - attachAnnotation(mDCIdentifier,makeNamespacedID(tbPersistable),mDCURI,annotatable); + protected void attachTreeBaseID(Annotatable annotatable,TBPersistable tbPersistable,Class<?> persistableClass) { + if ( null != tbPersistable.getId() ) { + attachAnnotation(mDCIdentifier,makeNamespacedID(tbPersistable,persistableClass),mDCURI,annotatable); + } } /** @@ -71,7 +74,7 @@ * @param annotatable */ protected void attachAnnotation(String key,String value,URI namespace,Annotatable annotatable) { - annotatable.addAnnotationValue(key, namespace, value); + annotatable.addAnnotationValue(key, namespace, value); // FIXME! Attaches meta element as last child } /** @@ -80,22 +83,49 @@ * @param persistableClass * @return */ - protected Long readTreeBaseID(Annotatable annotatable, Class<? extends TBPersistable> persistableClass) { - Set<Object> values = annotatable.getAnnotationValues(mDCIdentifier); - Iterator<Object> objectIterator = values.iterator(); + protected Long readTreeBaseID(Annotatable annotatable) { + + // this will return the value object associated with a + // dc:identifier predicate in a nexml meta annotation, + // e.g. <meta property="dc:identifier" content="TB2:Tr231"/> + // this will return something that stringifies to TB2:Tr231 + Set<Object> dublinCoreIdentifierObjects = annotatable.getAnnotationValues(mDCIdentifier); + Iterator<Object> objectIterator = dublinCoreIdentifierObjects.iterator(); while ( objectIterator.hasNext() ) { - String namespacedId = objectIterator.next().toString(); - StringBuffer prefix = new StringBuffer(); - prefix - .append(TreeBASE2Prefix) - .append(':') - .append(TreebaseIDString.getPrefixForClass(persistableClass)); - if ( namespacedId.startsWith(prefix.toString()) ) { - return Long.parseLong(namespacedId.substring(prefix.length())); + TreebaseIDString treebaseIDString = null; + NamespacedGUID namespacedGUID = null; + try { + namespacedGUID = new NamespacedGUID(objectIterator.next().toString()); + treebaseIDString = namespacedGUID.getTreebaseIDString(); + return treebaseIDString.getId(); + } catch ( MalformedTreebaseIDString e ) { + // XXX do nothing, it's OK, it means we're + // parsing an id from a different naming + // authority, e.g. uBio or NCBI } } return null; } + + protected OTUs getOTUsById(Long taxonLabelSetId) { + for ( OTUs otus : getDocument().getOTUsList() ) { + Long annotatedID = readTreeBaseID(otus); + if ( taxonLabelSetId.equals(annotatedID) ) { + return otus; + } + } + return null; + } + + protected OTU getOTUById(OTUs otus,Long taxonLabelId) { + for ( OTU otu : otus.getAllOTUs() ) { + Long annotatedID = readTreeBaseID(otu); + if ( taxonLabelId.equals(annotatedID) ) { + return otu; + } + } + return null; + } public Document getDocument() { return mDocument; @@ -104,4 +134,29 @@ public void setDocument(Document document) { mDocument = document; } + + public static String forXML(String aText){ + final StringBuilder result = new StringBuilder(); + final StringCharacterIterator iterator = new StringCharacterIterator(aText); + char character = iterator.current(); + while (character != CharacterIterator.DONE) { + if (character == '<') { + result.append("<"); + } else if (character == '>') { + result.append(">"); + } else if (character == '\"') { + result.append("""); + } else if (character == '\'') { + result.append("'"); + } else if (character == '&') { + result.append("&"); + } else { + //the char is not a special one + //add it to the result as is + result.append(character); + } + character = iterator.next(); + } + return result.toString(); + } } Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockConverter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockConverter.java 2009-06-23 10:50:48 UTC (rev 72) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockConverter.java 2009-06-23 10:52:08 UTC (rev 73) @@ -17,6 +17,7 @@ import org.nexml.model.IntEdge; import org.nexml.model.Network; import org.nexml.model.Node; +import org.nexml.model.OTU; import org.nexml.model.OTUs; import org.nexml.model.Tree; @@ -38,7 +39,7 @@ */ public TreeBlock fromXmlToTreeBase(org.nexml.model.TreeBlock xmlTreeBlock) { OTUs xmlOTUs = xmlTreeBlock.getOTUs(); - Long tbTaxonLabelSetId = readTreeBaseID(xmlOTUs,TaxonLabelSet.class); + Long tbTaxonLabelSetId = readTreeBaseID(xmlOTUs); TreeBlock tbTreeBlock = new TreeBlock(); tbTreeBlock.setTitle(xmlTreeBlock.getLabel()); if ( null != tbTaxonLabelSetId ) { @@ -80,8 +81,10 @@ */ public Tree<?> fromTreeBaseToXml(PhyloTree phyloTree,org.nexml.model.TreeBlock xmlTreeBlock) { Tree<FloatEdge> xmlTree = xmlTreeBlock.createFloatTree(); - xmlTree.setLabel(phyloTree.getLabel()); - attachTreeBaseID(xmlTree, phyloTree); + if ( null != phyloTree.getLabel() ) { + xmlTree.setLabel(phyloTree.getLabel()); + } + attachTreeBaseID(xmlTree, phyloTree,PhyloTree.class); copyTreeBaseTree(phyloTree, xmlTree); return xmlTree; } @@ -93,18 +96,12 @@ */ public org.nexml.model.TreeBlock fromTreeBaseToXML(TreeBlock treeBlock) { TaxonLabelSet taxonLabelSet = treeBlock.getTaxonLabelSet(); - OTUs xmlOTUs = null; - Long taxonLabelSetId = taxonLabelSet.getId(); - for ( OTUs otus : getDocument().getOTUsList() ) { - Long otusId = readTreeBaseID(otus, TaxonLabelSet.class); - if ( taxonLabelSetId == otusId ) { - xmlOTUs = otus; - break; - } - } + OTUs xmlOTUs = getOTUsById(taxonLabelSet.getId()); org.nexml.model.TreeBlock xmlTreeBlock = getDocument().createTreeBlock(xmlOTUs); - xmlTreeBlock.setLabel(treeBlock.getTitle()); - attachTreeBaseID((Annotatable)xmlTreeBlock,treeBlock); + if ( null != treeBlock.getTitle() ) { + xmlTreeBlock.setLabel(treeBlock.getTitle()); + } + attachTreeBaseID((Annotatable)xmlTreeBlock,treeBlock,TreeBlock.class); for ( PhyloTree phyloTree : treeBlock.getTreeList() ) { fromTreeBaseToXml(phyloTree,xmlTreeBlock); } @@ -128,25 +125,27 @@ * @param xmlTree */ private void traverseTreeBaseTree(PhyloTree tbTree,PhyloTreeNode tbNode,Node xmlNode,Tree<FloatEdge> xmlTree) { - xmlNode.setLabel(tbNode.getName()); - attachTreeBaseID(xmlNode, tbNode); + if ( null != tbNode.getName() ) { + xmlNode.setLabel(tbNode.getName()); + } + attachTreeBaseID(xmlNode, tbNode,PhyloTreeNode.class); TaxonLabel taxonLabel = tbNode.getTaxonLabel(); if ( null != taxonLabel ) { Long taxonId = taxonLabel.getId(); for ( OTUs xmlOTUs : getDocument().getOTUsList() ) { - for ( org.nexml.model.OTU xmlOTU : xmlOTUs.getAllOTUs() ) { - Long currentTaxonId = readTreeBaseID(xmlOTU, TaxonLabel.class); - if ( taxonId == currentTaxonId ) { - xmlNode.setOTU(xmlOTU); - break; - } + OTU xmlOTU = getOTUById(xmlOTUs, taxonId); + if ( null != xmlOTU ) { + xmlNode.setOTU(xmlOTU); + break; } } } for ( PhyloTreeNode tbChildNode : tbNode.getChildNodes() ) { Node xmlChildNode = xmlTree.createNode(); FloatEdge xmlEdge = xmlTree.createEdge(xmlNode, xmlChildNode); - xmlEdge.setLength(tbChildNode.getBranchLength()); + if ( null != tbChildNode.getBranchLength() ) { + xmlEdge.setLength(tbChildNode.getBranchLength()); + } traverseTreeBaseTree(tbTree, tbChildNode, xmlChildNode, xmlTree); } } @@ -176,7 +175,7 @@ private void traverseXmlTree(Tree<?> xmlTree, StringBuilder sb, Node xmlNode, PhyloTreeNode tbNode, PhyloTree tbTree) { tbTree.addTreeNode(tbNode); if ( null != xmlNode.getOTU() ) { - Long tbTaxonLabelId = readTreeBaseID(xmlNode.getOTU(),TaxonLabel.class); + Long tbTaxonLabelId = readTreeBaseID(xmlNode.getOTU()); if ( null != tbTaxonLabelId ) { TaxonLabel tbTaxonLabel = getTaxonLabelHome() .findPersistedObjectByID(TaxonLabel.class, tbTaxonLabelId); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2009-07-02 21:02:24
|
Revision: 162 http://treebase.svn.sourceforge.net/treebase/?rev=162&view=rev Author: rvos Date: 2009-07-02 21:02:07 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Added treebase term annotations Modified 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/NexmlObjectConverter.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/domain/nexus/nexml/NexmlDocumentConverter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentConverter.java 2009-07-02 10:48:31 UTC (rev 161) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentConverter.java 2009-07-02 21:02:07 UTC (rev 162) @@ -95,8 +95,9 @@ * @param document */ private void copyCitationMetadata(Citation citation,Document document) { + attachAnnotation("dcterms.bibliographicCitation",citation.getAuthorsCitationStyleWithoutHtml(),mDCURI,document); if ( null != citation.getTitle() ) { - attachAnnotation("dc:title",citation.getTitle(),mPrismURI,document); + attachAnnotation("tb:title.study",citation.getTitle(),mTBTermsURI,document); } if ( null != citation.getPublishYear() ) { attachAnnotation("prism:publicationDate",citation.getPublishYear().toString(),mPrismURI,document); @@ -115,7 +116,7 @@ if ( null != citation.getKeywords() ) { String[] keywords = citation.getKeywords().split(", "); for ( int i = 0; i < keywords.length; i++ ) { - attachAnnotation("prism:keyword",keywords[i],mPrismURI,document); + attachAnnotation("dcterms:subject",keywords[i],mDCURI,document); } } if ( citation instanceof ArticleCitation ) { @@ -162,12 +163,14 @@ private void copyMetadata(Study pStudy) { attachTreeBaseID(getDocument(), pStudy,Study.class); + attachAnnotation("tb:identifier.study",pStudy.getId().toString(), mTBTermsURI, getDocument()); + attachAnnotation("tb:identifier.study.tb1",pStudy.getTB1StudyID(), mTBTermsURI, getDocument()); if ( null != pStudy.getName() ) { - attachAnnotation("dc:title", pStudy.getName(), mDCURI, getDocument()); + attachAnnotation("tb:title.study", pStudy.getName(), mTBTermsURI, getDocument()); } for ( Person person : pStudy.getAuthors() ) { String personName = person.getFullNameCitationStyle(); - attachAnnotation("dc:contributor",personName,mDCURI,getDocument()); + attachAnnotation("dcterms:contributor",personName,mDCURI,getDocument()); } if ( null != pStudy.getReleaseDate() ) { attachAnnotation("prism:embargoDate",pStudy.getReleaseDate().toString(),mPrismURI,getDocument()); @@ -175,7 +178,7 @@ if ( null != pStudy.getSubmission() ) { if ( null != pStudy.getSubmission().getSubmitter() ) { attachAnnotation( - "dc:creator", + "dcterms:creator", pStudy.getSubmission().getSubmitter().getPerson().getFullNameCitationStyle(), mDCURI, getDocument() Modified: 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 2009-07-02 10:48:31 UTC (rev 161) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlMatrixConverter.java 2009-07-02 21:02:07 UTC (rev 162) @@ -178,7 +178,7 @@ xmlState.setLabel(tbState.getDescription()); } if ( null != tbState.getNotes() ) { - ((Annotatable)xmlState).addAnnotationValue("dc:description", mDCURI, tbState.getNotes()); + ((Annotatable)xmlState).addAnnotationValue("dcterms:description", mDCURI, tbState.getNotes()); } attachTreeBaseID((Annotatable)xmlState,tbState,DiscreteCharState.class); } @@ -220,7 +220,7 @@ org.nexml.model.Character xmlCharacter = xmlMatrix.createCharacter(xmlStateSet); PhyloChar tbCharacter = tbColumn.getCharacter(); if ( null != tbCharacter.getDescription() && ! tbCharacter.getDescription().equals(tbDataType) ) { - ((Annotatable)xmlCharacter).addAnnotationValue("dc:description", mDCURI, tbCharacter.getDescription()); + ((Annotatable)xmlCharacter).addAnnotationValue("dcterms:description", mDCURI, tbCharacter.getDescription()); } if ( null != tbCharacter.getId() && tbCharacter.getId() != 2 ) { // XXX is PhyloChar.id 2 some sort of magic number? attachTreeBaseID((Annotatable)xmlCharacter,tbCharacter,PhyloChar.class); @@ -243,7 +243,7 @@ org.nexml.model.Character xmlCharacter = xmlMatrix.createCharacter(); PhyloChar tbCharacter = tbColumn.getCharacter(); if ( null != tbCharacter.getDescription() ) { - ((Annotatable)xmlCharacter).addAnnotationValue("dc:description", mDCURI, tbCharacter.getDescription()); + ((Annotatable)xmlCharacter).addAnnotationValue("dcterms:description", mDCURI, tbCharacter.getDescription()); } attachTreeBaseID((Annotatable)xmlCharacter,tbCharacter,PhyloChar.class); } @@ -273,6 +273,10 @@ } xmlMatrix.setLabel(tbMatrix.getTitle()); attachTreeBaseID((Annotatable)xmlMatrix, tbMatrix,Matrix.class); + ((Annotatable)xmlMatrix).addAnnotationValue("tb:type.matrix", mTBTermsURI, tbMatrix.getDataType().getDescription()); + ((Annotatable)xmlMatrix).addAnnotationValue("tb:ntax.matrix", mTBTermsURI, tbMatrix.getnTax()); + ((Annotatable)xmlMatrix).addAnnotationValue("tb:nchar.matrix", mTBTermsURI, tbMatrix.getnChar()); + ((Annotatable)xmlMatrix).addAnnotationValue("tb:identifier.matrix", mTBTermsURI, tbMatrix.getId()); return xmlMatrix; } Modified: 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/NexmlOTUConverter.java 2009-07-02 10:48:31 UTC (rev 161) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlOTUConverter.java 2009-07-02 21:02:07 UTC (rev 162) @@ -85,6 +85,10 @@ StringBuilder urlString = new StringBuilder(getDocument().getBaseURI().toString()); taxonLabel.getPhyloWSPath().getPath(urlString).append("NCBI:").append(taxonLabel.getNcbiTaxID()); xmlOTU.addAnnotationValue("dc:relation", mDCURI, URI.create(urlString.toString())); + xmlOTU.addAnnotationValue("tb:identifier.ncbi", mTBTermsURI, "NCBI:" + taxonLabel.getNcbiTaxID()); + xmlOTU.addAnnotationValue("tb:identifier.taxon", mTBTermsURI, taxonLabel.getTaxonVariant().getTaxon().getId()); + xmlOTU.addAnnotationValue("tb:identifier.taxonLabel", mTBTermsURI, taxonLabel.getId()); + xmlOTU.addAnnotationValue("tb:title.taxon", mTBTermsURI, taxonLabel.getTaxonVariant().getTaxon().getName()); } TaxonVariant tv = taxonLabel.getTaxonVariant(); if ( null != tv ) { @@ -92,6 +96,9 @@ StringBuilder urlString = new StringBuilder(getDocument().getBaseURI().toString()); taxonLabel.getPhyloWSPath().getPath(urlString).append("uBio:").append(tv.getNamebankID()); xmlOTU.addAnnotationValue("dc:relation", mDCURI, URI.create(urlString.toString())); + xmlOTU.addAnnotationValue("tb:identifier.ubio", mTBTermsURI, "uBio:" + tv.getNamebankID()); + xmlOTU.addAnnotationValue("tb:identifier.taxonVariant", mTBTermsURI, tv.getId()); + xmlOTU.addAnnotationValue("tb:title.taxonVariant", mTBTermsURI, tv.getFullName()); } } 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 2009-07-02 10:48:31 UTC (rev 161) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlObjectConverter.java 2009-07-02 21:02:07 UTC (rev 162) @@ -23,11 +23,13 @@ public class NexmlObjectConverter extends AbstractNexusConverter { protected static URI mDCURI; protected static URI mPrismURI; + protected static URI mTBTermsURI; protected URI mBaseURI; - private static String mDCURIString = "http://purl.org/dc/elements/1.1/"; + private static String mTBTermsString = "http://treebase.org/terms#"; + private static String mDCURIString = "http://purl.org/dc/terms/"; private static String mPrismURIString = "http://prismstandard.org/namespaces/1.2/basic/"; private static String mBaseURIString = "http://purl.org/PHYLO/TREEBASE/PHYLOWS/"; - private static String mDCIdentifier = "dc:identifier"; + private static String mDCIdentifier = "dcterms:identifier"; public static String TreeBASE2Prefix = "TreeBASE2"; private Document mDocument; @@ -40,6 +42,7 @@ try { mDCURI = new URI(mDCURIString); mPrismURI = new URI(mPrismURIString); + mTBTermsURI = new URI(mTBTermsString); if ( null != baseURI ) { mBaseURI = new URI(baseURI); } @@ -81,7 +84,7 @@ if ( null != tbPersistable.getId() ) { //attachAnnotation(mDCIdentifier,makeNamespacedID(tbPersistable,persistableClass),mDCURI,annotatable); String uriString = getDocument().getBaseURI().toString() + tbPersistable.getPhyloWSPath().toString(); - annotatable.addAnnotationValue("dc:relation",mDCURI, URI.create(uriString)); + annotatable.addAnnotationValue("dcterms:relation",mDCURI, URI.create(uriString)); } } @@ -108,7 +111,7 @@ // dc:identifier predicate in a nexml meta annotation, // e.g. <meta property="dc:identifier" content="TB2:Tr231"/> // this will return something that stringifies to TB2:Tr231 - Set<Object> dublinCoreRelationObjects = annotatable.getRelValues("dc:relation"); + Set<Object> dublinCoreRelationObjects = annotatable.getRelValues("dcterms:relation"); Iterator<Object> objectIterator = dublinCoreRelationObjects.iterator(); while ( objectIterator.hasNext() ) { URI relationURI = (URI)objectIterator.next(); Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockConverter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockConverter.java 2009-07-02 10:48:31 UTC (rev 161) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockConverter.java 2009-07-02 21:02:07 UTC (rev 162) @@ -84,6 +84,11 @@ if ( null != phyloTree.getLabel() ) { xmlTree.setLabel(phyloTree.getLabel()); } + xmlTree.addAnnotationValue("tb:identifier.tree", mTBTermsURI, phyloTree.getId()); + xmlTree.addAnnotationValue("tb:kind.tree", mTBTermsURI, phyloTree.getKindDescription()); + xmlTree.addAnnotationValue("tb:type.tree", mTBTermsURI, phyloTree.getTypeDescription()); + xmlTree.addAnnotationValue("tb:quality.tree", mTBTermsURI, phyloTree.getQualityDescription()); + xmlTree.addAnnotationValue("tb:ntax.tree", mTBTermsURI, phyloTree.getnTax()); attachTreeBaseID(xmlTree, phyloTree,PhyloTree.class); copyTreeBaseTree(phyloTree, xmlTree); return xmlTree; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2010-03-15 01:08:12
|
Revision: 574 http://treebase.svn.sourceforge.net/treebase/?rev=574&view=rev Author: rvos Date: 2010-03-15 01:08:05 +0000 (Mon, 15 Mar 2010) Log Message: ----------- Now calls getAnnotations() to let the object decide what metadata to add as opposed to fiddling with the object here. Modified Paths: -------------- 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/domain/nexus/nexml/NexmlOTUConverter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlOTUConverter.java 2010-03-15 01:07:17 UTC (rev 573) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlOTUConverter.java 2010-03-15 01:08:05 UTC (rev 574) @@ -1,12 +1,9 @@ package org.cipres.treebase.domain.nexus.nexml; -import java.net.URI; - import org.cipres.treebase.domain.study.Study; 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.taxon.TaxonVariant; import org.nexml.model.Document; import org.nexml.model.OTU; import org.nexml.model.OTUs; @@ -81,26 +78,6 @@ xmlOTU.setLabel(taxonLabel.getTaxonLabel()); } attachTreeBaseID(xmlOTU,taxonLabel,TaxonLabel.class); - if ( null != taxonLabel.getNcbiTaxID() ) { - StringBuilder urlString = new StringBuilder(getDocument().getBaseURI().toString()); - taxonLabel.getPhyloWSPath().getPath(urlString).append("NCBI:").append(taxonLabel.getNcbiTaxID()); - xmlOTU.addAnnotationValue("dc:relation", mDCURI, URI.create(urlString.toString())); - xmlOTU.addAnnotationValue("tb:identifier.ncbi", mTBTermsURI, "NCBI:" + taxonLabel.getNcbiTaxID()); - xmlOTU.addAnnotationValue("tb:identifier.taxon", mTBTermsURI, taxonLabel.getTaxonVariant().getTaxon().getId()); - xmlOTU.addAnnotationValue("tb:identifier.taxonLabel", mTBTermsURI, taxonLabel.getId()); - xmlOTU.addAnnotationValue("tb:title.taxon", mTBTermsURI, taxonLabel.getTaxonVariant().getTaxon().getName()); - } - TaxonVariant tv = taxonLabel.getTaxonVariant(); - if ( null != tv ) { - if ( null != tv.getNamebankID() ) { - StringBuilder urlString = new StringBuilder(getDocument().getBaseURI().toString()); - taxonLabel.getPhyloWSPath().getPath(urlString).append("uBio:").append(tv.getNamebankID()); - xmlOTU.addAnnotationValue("dc:relation", mDCURI, URI.create(urlString.toString())); - xmlOTU.addAnnotationValue("tb:identifier.ubio", mTBTermsURI, "uBio:" + tv.getNamebankID()); - xmlOTU.addAnnotationValue("tb:identifier.taxonVariant", mTBTermsURI, tv.getId()); - xmlOTU.addAnnotationValue("tb:title.taxonVariant", mTBTermsURI, tv.getFullName()); - } - } return xmlOTU; } Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockConverter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockConverter.java 2010-03-15 01:07:17 UTC (rev 573) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockConverter.java 2010-03-15 01:08:05 UTC (rev 574) @@ -3,6 +3,7 @@ import java.util.Iterator; import java.util.Set; +import org.cipres.treebase.Constants; import org.cipres.treebase.domain.study.Study; import org.cipres.treebase.domain.taxon.TaxonLabel; import org.cipres.treebase.domain.taxon.TaxonLabelHome; @@ -84,21 +85,6 @@ if ( null != phyloTree.getLabel() ) { xmlTree.setLabel(phyloTree.getLabel()); } - if ( null != phyloTree.getId() ) { - xmlTree.addAnnotationValue("tb:identifier.tree", mTBTermsURI, phyloTree.getId()); - } - if ( null != phyloTree.getKindDescription() ) { - xmlTree.addAnnotationValue("tb:kind.tree", mTBTermsURI, phyloTree.getKindDescription()); - } - if ( null != phyloTree.getTypeDescription() ) { - xmlTree.addAnnotationValue("tb:type.tree", mTBTermsURI, phyloTree.getTypeDescription()); - } - if ( null != phyloTree.getQualityDescription() ) { - xmlTree.addAnnotationValue("tb:quality.tree", mTBTermsURI, phyloTree.getQualityDescription()); - } - if ( null != phyloTree.getnTax() ) { - xmlTree.addAnnotationValue("tb:ntax.tree", mTBTermsURI, phyloTree.getnTax()); - } attachTreeBaseID(xmlTree, phyloTree,PhyloTree.class); copyTreeBaseTree(phyloTree, xmlTree); return xmlTree; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2011-10-13 18:50:59
|
Revision: 973 http://treebase.svn.sourceforge.net/treebase/?rev=973&view=rev Author: rvos Date: 2011-10-13 18:50:53 +0000 (Thu, 13 Oct 2011) Log Message: ----------- Changed skos:historyNote message serialization 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/NexmlOTUWriter.java trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockWriter.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:40:28 UTC (rev 972) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlDocumentWriter.java 2011-10-13 18:50:53 UTC (rev 973) @@ -61,7 +61,7 @@ */ public Document fromTreeBaseToXml(Study pStudy) { attachTreeBaseID(getDocument(), pStudy,Study.class); - getDocument().addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using NexmlDocumentConverter $Rev$"); + getDocument().addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using "+this.toString()+" $Rev$"); NexmlOTUWriter noc = new NexmlOTUWriter(getStudy(),getTaxonLabelHome(),getDocument()); for ( TaxonLabelSet taxonLabelSet : pStudy.getTaxonLabelSets() ) { 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:40:28 UTC (rev 972) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlOTUWriter.java 2011-10-13 18:50:53 UTC (rev 973) @@ -30,7 +30,7 @@ // attach base uri and skos:historyNote xmlOTUs.setBaseURI(mTaxonBaseURI); - xmlOTUs.addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using NexmlOTUConverter $Rev$"); + xmlOTUs.addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using "+this.toString()+" $Rev$"); xmlOTUs.setLabel(taxonLabelSet.getTitle()); attachTreeBaseID(xmlOTUs,taxonLabelSet,TaxonLabelSet.class); 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:40:28 UTC (rev 972) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockWriter.java 2011-10-13 18:50:53 UTC (rev 973) @@ -54,7 +54,7 @@ org.nexml.model.TreeBlock xmlTreeBlock = getDocument().createTreeBlock(xmlOTUs); // attach base uri and skos:historyNote - xmlTreeBlock.addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using NexmlTreeBlockConverter $Rev$"); + xmlTreeBlock.addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using "+this.toString()+" $Rev$"); xmlTreeBlock.setBaseURI(mTreeBaseURI); if ( null != treeBlock.getTitle() ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rv...@us...> - 2012-02-01 23:16:05
|
Revision: 1040 http://treebase.svn.sourceforge.net/treebase/?rev=1040&view=rev Author: rvos Date: 2012-02-01 23:15:59 +0000 (Wed, 01 Feb 2012) Log Message: ----------- This revision places attachTreeBaseID() earlier in the NeXML object creation, before any annotations are attached. This so that the about attribute is set correctly, by computing it from the TreeBASE ID instead of the internal object ID from the NeXML API. Modified Paths: -------------- 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/NexmlTreeBlockWriter.java 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 2012-02-01 21:52:11 UTC (rev 1039) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlOTUWriter.java 2012-02-01 23:15:59 UTC (rev 1040) @@ -30,13 +30,12 @@ */ public OTUs fromTreeBaseToXml(TaxonLabelSet taxonLabelSet) { OTUs xmlOTUs = getDocument().createOTUs(); + attachTreeBaseID(xmlOTUs,taxonLabelSet,TaxonLabelSet.class); - // attach base uri and skos:historyNote xmlOTUs.setBaseURI(mTaxonBaseURI); - xmlOTUs.addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using "+this.toString()+" $Rev$"); - + xmlOTUs.addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using "+this.toString()+" $Rev$"); xmlOTUs.setLabel(taxonLabelSet.getTitle()); - attachTreeBaseID(xmlOTUs,taxonLabelSet,TaxonLabelSet.class); + for ( TaxonLabel taxonLabel : taxonLabelSet.getTaxonLabelsReadOnly() ) { fromTreeBaseToXml(taxonLabel,xmlOTUs); } 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 2012-02-01 21:52:11 UTC (rev 1039) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlTreeBlockWriter.java 2012-02-01 23:15:59 UTC (rev 1040) @@ -52,15 +52,17 @@ TaxonLabelSet taxonLabelSet = treeBlock.getTaxonLabelSet(); OTUs xmlOTUs = getOTUsById(taxonLabelSet.getId()); org.nexml.model.TreeBlock xmlTreeBlock = getDocument().createTreeBlock(xmlOTUs); + attachTreeBaseID((Annotatable)xmlTreeBlock,treeBlock,TreeBlock.class); // attach base uri and skos:historyNote xmlTreeBlock.addAnnotationValue("skos:historyNote", Constants.SKOSURI, "Mapped from TreeBASE schema using "+this.toString()+" $Rev$"); xmlTreeBlock.setBaseURI(mTreeBaseURI); + xmlTreeBlock.setLabel(treeBlock.getLabel()); if ( null != treeBlock.getTitle() ) { xmlTreeBlock.setLabel(treeBlock.getTitle()); } - attachTreeBaseID((Annotatable)xmlTreeBlock,treeBlock,TreeBlock.class); + for ( PhyloTree phyloTree : treeBlock.getTreeList() ) { fromTreeBaseToXml(phyloTree,xmlTreeBlock); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |