Skip to content

Commit

Permalink
Now it can set organism property for some entity references.
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorRodchenkov committed Mar 10, 2024
1 parent 26de2a6 commit a1b44d2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
46 changes: 30 additions & 16 deletions src/main/java/org/ctdbase/converter/CTDInteractionConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private Interaction createBindingReaction(IxnType ixn, String processId) {
StringBuilder nameBuilder = new StringBuilder();
for(ActorType actor : actors) {
if(CtdUtil.extractActor(actor) != Actor.IXN) {
PhysicalEntity pe = createSPEFromActor(actor, null);
PhysicalEntity pe = createSPEFromActor(actor, null, ixn.getTaxon());
complex.addComponent(pe);
complexAssembly.addLeft(pe);
nameBuilder.append(pe.getDisplayName()).append("/");
Expand All @@ -275,9 +275,9 @@ private Interaction createBindingReaction(IxnType ixn, String processId) {
IxnType subIxn = CtdUtil.convertActorToIxn(actor, ixn);
AxnCode subAxn = CtdUtil.axnCode(subIxn);
if(subAxn == AxnCode.W) {
//unsure what eactly does axn code 'w' mean inside an ixn actor of a 'b' parent ..
//unsure what eactly does axn code 'w' mean inside an ixn actor of a 'b' parent
for (ActorType actorType : subIxn.getActor()) {
PhysicalEntity pe = createSPEFromActor(actorType, null);
PhysicalEntity pe = createSPEFromActor(actorType, null, ixn.getTaxon());
complex.addComponent(pe);
complexAssembly.addLeft(pe);
nameBuilder.append(pe.getDisplayName()).append("/");
Expand Down Expand Up @@ -361,7 +361,7 @@ private Interaction createDegradation(IxnType ixn, String processId)
if (degradation == null) {
degradation = create(Degradation.class, processId);
setNameFromIxnType(ixn, degradation, false);
SimplePhysicalEntity par = createSPEFromActor(actor, null);
SimplePhysicalEntity par = createSPEFromActor(actor, null, ixn.getTaxon());
degradation.addLeft(par);
degradation.setConversionDirection(ConversionDirectionType.LEFT_TO_RIGHT);
model.add(degradation);
Expand All @@ -375,8 +375,8 @@ private Interaction createTransport(IxnType ixn, String processId, String leftLo
Transport transport = (Transport) model.getByID(absoluteUri(processId));
if (transport == null) {
transport = create(Transport.class, processId);
SimplePhysicalEntity leftPar = createSPEFromActor(actor, leftLoc);
SimplePhysicalEntity rightPar = createSPEFromActor(actor, rightLoc);
SimplePhysicalEntity leftPar = createSPEFromActor(actor, leftLoc, ixn.getTaxon());
SimplePhysicalEntity rightPar = createSPEFromActor(actor, rightLoc, ixn.getTaxon());
transport.addLeft(leftPar);
transport.addRight(rightPar);
transport.setConversionDirection(ConversionDirectionType.LEFT_TO_RIGHT);
Expand Down Expand Up @@ -436,11 +436,11 @@ private Interaction createConversion(IxnType ixn, String processId, boolean useL
biochemicalReaction = create(BiochemicalReaction.class, processId);
setNameFromIxnType(ixn, biochemicalReaction, false);
if(useLeft) {
SimplePhysicalEntity leftPar = createSPEFromActor(actor, null);
SimplePhysicalEntity leftPar = createSPEFromActor(actor, null, ixn.getTaxon());
biochemicalReaction.addLeft(leftPar);
}
if(useRight) {
SimplePhysicalEntity rightPar = createSPEFromActor(actor, term);
SimplePhysicalEntity rightPar = createSPEFromActor(actor, term, ixn.getTaxon());
biochemicalReaction.addRight(rightPar);
if (term != null) {
if (CtdUtil.extractActor(actor).equals(Actor.CHEMICAL)) {
Expand All @@ -461,7 +461,8 @@ private ModificationFeature createModFeature(String id, String term)
{
if(term!=null) id += "_" + term;
ModificationFeature feature = create(ModificationFeature.class, id);
SequenceModificationVocabulary modificationVocabulary = create(SequenceModificationVocabulary.class, "seqmod_" + id);
SequenceModificationVocabulary modificationVocabulary = create(
SequenceModificationVocabulary.class, "seqmod_" + id);
modificationVocabulary.addTerm(term);
feature.setModificationType(modificationVocabulary);
model.add(feature);
Expand All @@ -476,7 +477,7 @@ private Interaction createTemplateReaction(IxnType ixn, String processId) {
templateReaction = create(TemplateReaction.class, processId);
setNameFromIxnType(ixn, templateReaction, false);
templateReaction.setTemplateDirection(TemplateDirectionType.FORWARD);
SimplePhysicalEntity actorEntity = createSPEFromActor(actor, null);
SimplePhysicalEntity actorEntity = createSPEFromActor(actor, null, ixn.getTaxon());
templateReaction.addProduct(actorEntity);
model.add(templateReaction);
}
Expand Down Expand Up @@ -525,7 +526,7 @@ else if(controlled instanceof Catalysis && controllers.size()==1
// controlled process - when this actor is ixn and is inside an outer ixn/actor with e.g., 'csy' type
// (controls synthesis, conversion), then the second parameter can be used to set left participant of that proc.
private Collection<Controller> createControllersFromActor(ActorType actor, Interaction controlled, IxnType ixn) {
HashSet<Controller> controllers = new HashSet<Controller>();
HashSet<Controller> controllers = new HashSet<>();
switch (CtdUtil.extractActor(actor)) {
case IXN:
IxnType subIxn = CtdUtil.convertActorToIxn(actor, ixn);
Expand Down Expand Up @@ -561,14 +562,14 @@ private Collection<Controller> createControllersFromActor(ActorType actor, Inter

break;
default: // If not an IXN, then it is a physical entity
controllers.add(createSPEFromActor(actor, null));
controllers.add(createSPEFromActor(actor, null, ixn.getTaxon()));
break;
}

return controllers;
}

private SimplePhysicalEntity createSPEFromActor(ActorType actor, String state) {
private SimplePhysicalEntity createSPEFromActor(ActorType actor, String state, List<TaxonType> taxonTypes) {
SimplePhysicalEntity spe;
Actor aType = CtdUtil.extractActor(actor);
switch (aType) {
Expand All @@ -584,6 +585,11 @@ private SimplePhysicalEntity createSPEFromActor(ActorType actor, String state) {
Class<? extends SimplePhysicalEntity> eClass = geneForm.getEntityClass();
Class<? extends EntityReference> refClass = geneForm.getReferenceClass();
spe = createEntityFromActor(actor, eClass, refClass, state);
//add organism if it makes sense
if(spe.getEntityReference() instanceof SequenceEntityReference) {
BioSource organism = bioSource(taxonTypes);
((SequenceEntityReference) spe.getEntityReference()).setOrganism(organism);
}
break;
case IXN:
default:
Expand Down Expand Up @@ -626,11 +632,10 @@ private SimplePhysicalEntity createEntityFromActor(ActorType actorType,
entityReference = create(referenceClass, refId);
setNameFromActor(actorType, entityReference);
model.add(entityReference);
//TODO: set organism property from ixn taxon
if(actorTypeId.contains(":")) {
String[] t = actorTypeId.split(":");
RelationshipXref rx = (RelationshipXref) createXref(model, RelationshipXref.class,
("gene".equalsIgnoreCase(t[0])) ? "NCBI Gene" : t[0], t[1]);
("gene".equalsIgnoreCase(t[0])) ? "ncbigene" : t[0], t[1]);
entityReference.addXref(rx);
} else {
log.warn("Cannot make RX for ER " + refId + " due to no ':' in actor.id=" + actorTypeId);
Expand Down Expand Up @@ -670,7 +675,7 @@ private String setNameFromIxnType(IxnType ixn, Named named, boolean isTopControl
}

private static Set<PhysicalEntity> getProducts(Process process) {
Set<PhysicalEntity> products = new HashSet<PhysicalEntity>();
Set<PhysicalEntity> products = new HashSet<>();
if(process instanceof Control) {
for (Process controlled : ((Control) process).getControlled()) {
products.addAll(getProducts(controlled));
Expand All @@ -690,4 +695,13 @@ else if (process instanceof TemplateReaction) {
return products;
}

private BioSource bioSource(List<TaxonType> taxonTypes) {
if(taxonTypes == null || taxonTypes.isEmpty()) {
return null;
}
TaxonType org = taxonTypes.stream().filter(t -> StringUtils.equals(t.getId(),taxId))
.findFirst().orElse(taxonTypes.get(0));
return createBioSource(model, org.getId(), org.getValue());
}

}
15 changes: 15 additions & 0 deletions src/main/java/org/ctdbase/converter/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.biopax.paxtools.model.BioPAXElement;
import org.biopax.paxtools.model.BioPAXLevel;
import org.biopax.paxtools.model.Model;
import org.biopax.paxtools.model.level3.BioSource;
import org.biopax.paxtools.model.level3.UnificationXref;
import org.biopax.paxtools.model.level3.Xref;
import org.ctdbase.util.CtdUtil;

Expand Down Expand Up @@ -56,4 +58,17 @@ protected <T extends Xref> Xref createXref(Model model, Class<T> xrefClass, Str
}
return xref;
}

//
protected BioSource createBioSource(Model model, String taxonomyId, String name) {
String uri = "bioregistry.io/ncbitaxon:" + taxonomyId;
BioSource bioSource = (BioSource) model.getByID(uri);
if(bioSource == null) {
UnificationXref x = model.addNew(UnificationXref.class, "ncbitaxon:" + taxonomyId);
bioSource = model.addNew(BioSource.class, uri);
bioSource.setDisplayName(name);
bioSource.addXref(x);
}
return bioSource;
}
}
8 changes: 6 additions & 2 deletions src/test/java/org/ctdbase/converter/CTDConvertersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public void convertTaxon() {
converter = new CTDInteractionConverter("9606");
m = converter.convert(getClass().getResourceAsStream("/chem_gene_ixns_struct.xml"));
assertEquals(35, m.getObjects(Control.class).size());
ProteinReference pr = (ProteinReference) m.getByID("ctdbase:ref_protein_gene_83756");
assertNotNull(pr);
assertNotNull(pr.getOrganism());
assertEquals("Homo sapiens", pr.getOrganism().getDisplayName());
// (new SimpleIOHandler()).convertToOWL(m, System.out);
}

Expand All @@ -139,8 +143,8 @@ public void convertGenes() throws IOException {
assertEquals(2, m.getObjects(RelationshipXref.class).size());
assertEquals(0, m.getObjects(UnificationXref.class).size());
assertEquals(17, m.getObjects().size());
RnaReference rr1 = (RnaReference) m.getByID("ctdbase:ref_chemical_mesh_c106820");
//assertNotNull(rr1);
ProteinReference rr1 = (ProteinReference) m.getByID("ctdbase:ref_modified_form_gene_611");
assertNotNull(rr1);
// (new SimpleIOHandler()).convertToOWL(m, System.out);
}

Expand Down

0 comments on commit a1b44d2

Please sign in to comment.