Skip to content

Commit

Permalink
Fixes #9.
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorRodchenkov committed Sep 13, 2018
1 parent 7cf7ca2 commit c5a7251
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 79 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The BioPAX Validator
(code and docs permanently moved from Sourceforge, hg.code.sf.net/p/biopax/validator, to here on GitHub)
(code and docs permanently moved from Sourceforge, hg.code.sf.net/p/biopax/validator, to GitHub)

BioPAX.org [online BioPAX Validator](http://www.biopax.org/validator/)

Expand Down
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;
}

}
4 changes: 2 additions & 2 deletions biopax-validator/src/main/resources/codes.properties
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ direction.conflict.default=An illegal value or a conflict between related "direc
direction.conflict={0}
direction.conflict.category=recommendation

multi.organism.pathway.default=Components have different values for the 'organism' property. Check that this is a valid multi-organism interaction
multi.organism.pathway=pathway has: {0}, components have: {1}
multi.organism.pathway.default=Different organism references are found in a pathway and/or its members (excl. evidence). Is this indeed a multi-organism pathway?
multi.organism.pathway=BioSources (unification xref IDs): {0} (names: {1})
multi.organism.pathway.category=recommendation

complex.incomplete.default=Complex has no components, or the one without properly defined stoichiometry
Expand Down
21 changes: 1 addition & 20 deletions distr/src/main/etc/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,13 @@ http://www.biopax.org/validator
http://sourceforge.net/projects/biopax/


##
# Copyright (C) 2008 - 2013 University of Toronto (baderlab.org) and Memorial Sloan-Kettering Cancer Center (cbio.mskcc.org)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Lesser Public License for more details.
#
# You should have received a copy of the GNU General Lesser Public
# License along with this program. If not, see
# <http://www.gnu.org/licenses/lgpl-3.0.html>.
##


******************************************************************************
INSTALLATION
******************************************************************************

Download the latest ZIP distribution from

http://sourceforge.net/projects/biopax/files/validator/
http://www.biopax.org/downloads/validator/

Unpack and use (it also includes the WAR file).

Expand Down

0 comments on commit c5a7251

Please sign in to comment.