Commit f7578409 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

common interface for drugs and chemicals extracted

parent d3f682bc
......@@ -2,6 +2,7 @@ package lcsb.mapviewer.annotation.data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
......@@ -19,7 +20,7 @@ import lcsb.mapviewer.model.map.MiriamData;
*
*/
@XmlRootElement
public class Chemical implements Serializable {
public class Chemical implements Serializable, TargettingStructure {
/**
*
......@@ -290,4 +291,17 @@ public class Chemical implements Serializable {
}
@Override
public Collection<MiriamData> getSources() {
List<MiriamData> sources = new ArrayList<>();
sources.add(getCasID());
sources.add(getChemicalId());
return sources;
}
@Override
public Collection<Target> getTargets() {
return getInferenceNetwork();
}
}
......@@ -18,7 +18,7 @@ import lcsb.mapviewer.model.map.MiriamData;
*
*/
@XmlRootElement
public class Drug implements Serializable {
public class Drug implements Serializable, TargettingStructure {
/**
*
......
package lcsb.mapviewer.annotation.data;
import java.util.Collection;
import lcsb.mapviewer.model.map.MiriamData;
public interface TargettingStructure {
Collection<MiriamData> getSources();
Collection<Target> getTargets();
}
......@@ -18,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.annotation.data.Chemical;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.annotation.data.TargettingStructure;
import lcsb.mapviewer.annotation.services.ChemicalParser;
import lcsb.mapviewer.annotation.services.ChemicalSearchException;
import lcsb.mapviewer.annotation.services.PubmedParser;
......@@ -304,19 +305,13 @@ public class ChemicalService implements IChemicalService {
}
}
double counter = 0.0;
Set<MiriamData> annotations = new HashSet<>();
for (MiriamData md : targetMiriams) {
try {
List<Chemical> chemicalList = chemicalParser.getChemicalListByTarget(md, disease);
for (Chemical chemical : chemicalList) {
annotations.addAll(getAllMiriamDataForChemical(chemical));
cacheMiriamData(chemical);
}
for (MiriamData miriamData : annotations) {
if (miriamData.getDataType().equals(MiriamType.PUBMED)) {
pubmedParser.getPubmedArticleById(Integer.valueOf(miriamData.getResource()));
}
}
} catch (ChemicalSearchException | NumberFormatException | PubmedSearchException e) {
} catch (ChemicalSearchException | AnnotatorException e) {
logger.error("Problem with accessing info about chemical for target: " + md, e);
}
counter += 1;
......@@ -328,16 +323,25 @@ public class ChemicalService implements IChemicalService {
}
}
private Set<MiriamData> getAllMiriamDataForChemical(Chemical chemical) {
private void cacheMiriamData(TargettingStructure targettingStructure) throws AnnotatorException {
Set<MiriamData> result = new HashSet<>();
result.add(chemical.getCasID());
result.add(chemical.getChemicalId());
for (Target target : chemical.getInferenceNetwork()) {
result.addAll(targettingStructure.getSources());
for (Target target : targettingStructure.getTargets()) {
result.addAll(target.getGenes());
result.addAll(target.getReferences());
}
return result;
for (MiriamData miriamData : result) {
if (miriamData.getDataType().equals(MiriamType.PUBMED)) {
try {
pubmedParser.getPubmedArticleById(Integer.valueOf(miriamData.getResource()));
} catch (NumberFormatException | PubmedSearchException e) {
throw new AnnotatorException(e);
}
}
}
}
}
......@@ -190,9 +190,6 @@ public abstract class WebTestFunctions {
@Autowired
protected ModelViewFactory modelViewFactory;
@Autowired
protected DrugViewFactory drugViewFactory;
@Autowired
protected IReferenceGenomeService referenceGenomeService;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment