-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cf7ca2
commit c5a7251
Showing
4 changed files
with
37 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 33 additions & 56 deletions
89
biopax-validator/src/main/java/org/biopax/validator/rules/PathwayMultiOrganismRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,54 @@ | ||
package org.biopax.validator.rules; | ||
|
||
/* | ||
* | ||
*/ | ||
|
||
import java.util.Collection; | ||
import java.util.HashSet; | ||
|
||
import org.biopax.paxtools.controller.AbstractTraverser; | ||
import org.biopax.paxtools.controller.Fetcher; | ||
import org.biopax.paxtools.controller.PathAccessor; | ||
import org.biopax.paxtools.controller.PropertyEditor; | ||
import org.biopax.paxtools.util.Filter; | ||
import org.biopax.paxtools.model.BioPAXElement; | ||
import org.biopax.paxtools.model.Model; | ||
import org.biopax.paxtools.controller.SimpleEditorMap; | ||
import org.biopax.paxtools.model.level3.BioSource; | ||
import org.biopax.paxtools.model.level3.Pathway; | ||
import org.biopax.paxtools.util.Filter; | ||
import org.biopax.validator.api.AbstractRule; | ||
import org.biopax.validator.api.beans.Validation; | ||
import org.biopax.paxtools.controller.SimpleEditorMap; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Warn if a pathway and its component have different (not null) 'organism' values. | ||
* What to do? (ignore, delete this value, or override nested organism properties with pathway's value) | ||
* | ||
* | ||
* @author rodche | ||
*/ | ||
@Component | ||
public class PathwayMultiOrganismRule extends AbstractRule<Pathway> | ||
{ | ||
private final static Filter<PropertyEditor> filter = new Filter<PropertyEditor>() { | ||
public class PathwayMultiOrganismRule extends AbstractRule<Pathway> { | ||
private final static Filter<PropertyEditor> filter = new Filter<PropertyEditor>() { | ||
|
||
public boolean filter(PropertyEditor editor) { | ||
return !"nextStep".equals(editor.getProperty()); | ||
} | ||
}; | ||
|
||
public void check(final Validation validation, final Pathway pathway) { | ||
final Collection<BioPAXElement> organisms = new HashSet<BioPAXElement>(); | ||
final BioSource organism = pathway.getOrganism(); // not null - due to the canCheck method! | ||
//but.. | ||
if(organism==null) return; // we do not care | ||
|
||
AbstractTraverser runner = new AbstractTraverser( | ||
SimpleEditorMap.L3, filter) | ||
{ | ||
@Override | ||
protected void visit(Object value, BioPAXElement parent, | ||
Model model, PropertyEditor editor) | ||
{ | ||
if(value instanceof BioSource) { | ||
if(!((BioPAXElement) value).isEquivalent(organism)) { | ||
organisms.add((BioPAXElement) value); | ||
} | ||
} | ||
else if (value instanceof BioPAXElement) { | ||
logger.trace("Traverse into " + value + " " | ||
+ value.getClass().getSimpleName()); | ||
traverse((BioPAXElement) value, model); | ||
} | ||
} | ||
}; | ||
|
||
runner.traverse(pathway, null); | ||
|
||
if(organisms.size()>0) { | ||
error(validation, pathway, "multi.organism.pathway", | ||
false, organism, organisms); | ||
} | ||
public boolean filter(PropertyEditor editor) { | ||
//skip for: nextStep (those can be reached via pathwayOrder or pathwayComponent) and evidence (multi-org. is normal there) | ||
return !("nextStep".equals(editor.getProperty()) || "evidence".equals(editor.getProperty())); | ||
} | ||
}; | ||
|
||
public void check(final Validation validation, final Pathway pathway) { | ||
Fetcher fetcher = new Fetcher(SimpleEditorMap.L3, Fetcher.evidenceFilter, Fetcher.nextStepFilter); | ||
fetcher.setSkipSubPathways(true); | ||
final Set<BioSource> organisms = fetcher.fetch(pathway, BioSource.class); | ||
//collect taxonomy IDs (from the BioSource objects that have valid xrefs) | ||
PathAccessor accessor = new PathAccessor("BioSource/xref:UnificationXref/id"); | ||
Set<String> taxIds = accessor.getValueFromBeans(organisms); | ||
if (taxIds.size() > 1) { | ||
accessor = new PathAccessor("BioSource/name"); | ||
Set<String> names = new HashSet<String>(); | ||
for(Object name : accessor.getValueFromBeans(organisms)) | ||
names.add(String.valueOf(name).toLowerCase()); | ||
|
||
public boolean canCheck(Object thing) { | ||
return thing instanceof Pathway | ||
&& ((Pathway)thing).getOrganism() != null; | ||
error(validation, pathway, "multi.organism.pathway", false, taxIds, names); | ||
} | ||
} | ||
|
||
public boolean canCheck(Object thing) { | ||
return thing instanceof Pathway; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters