Commit 067562b9 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

cache list of drugs/mirna/chemicals

parent b92228ca
Pipeline #27475 passed with stage
in 12 minutes and 7 seconds
......@@ -52,6 +52,8 @@ minerva (15.0.0~beta.4) unstable; urgency=medium
(#1257)
* Bug fix: caching file with protin name containing new line character
crashed
* Bug fix: when caching the data on project upload list hint list for mirna,
drugs, chemicals were not cached (#1163)
-- Piotr Gawron <piotr.gawron@uni.lu> Tue, 12 May 2020 15:00:00 +0200
......
......@@ -13,7 +13,6 @@ import lcsb.mapviewer.annotation.data.MeSH;
import lcsb.mapviewer.annotation.services.MeSHParser;
import lcsb.mapviewer.annotation.services.TaxonomyBackend;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.dapi.ChemicalParser;
import lcsb.mapviewer.annotation.services.dapi.ChemicalSearchException;
import lcsb.mapviewer.api.*;
import lcsb.mapviewer.model.Project;
......@@ -34,14 +33,11 @@ public class ChemicalRestImpl extends BaseRestImpl {
private IChemicalService chemicalService;
private ChemicalParser chemicalParser;
private MeSHParser meSHParser;
@Autowired
public ChemicalRestImpl(IChemicalService chemicalService, ChemicalParser chemicalParser, MeSHParser meSHParser) {
public ChemicalRestImpl(IChemicalService chemicalService, MeSHParser meSHParser) {
this.chemicalService = chemicalService;
this.chemicalParser = chemicalParser;
this.meSHParser = meSHParser;
}
......@@ -208,6 +204,6 @@ public class ChemicalRestImpl extends BaseRestImpl {
if (project == null) {
throw new ObjectNotFoundException("Project with given id doesn't exist: " + projectId);
}
return chemicalParser.getSuggestedQueryList(project, project.getDisease());
return chemicalService.getSuggestedQueryList(project, project.getDisease());
}
}
......@@ -30,12 +30,9 @@ public class MiRnaRestImpl extends BaseRestImpl {
private IMiRNAService miRnaService;
private MiRNAParser miRNAParser;
@Autowired
public MiRnaRestImpl(IMiRNAService miRnaService, MiRNAParser miRNAParser) {
this.miRnaService = miRnaService;
this.miRNAParser = miRNAParser;
}
public List<Map<String, Object>> getMiRnasByQuery(String projectId, String columns, String query)
......@@ -149,7 +146,7 @@ public class MiRnaRestImpl extends BaseRestImpl {
if (project == null) {
throw new ObjectNotFoundException("Project with given id doesn't exist");
}
return miRNAParser.getSuggestedQueryList(project);
return miRnaService.getSuggestedQueryList(project);
}
}
package lcsb.mapviewer.services.search;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
......@@ -10,12 +11,18 @@ import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.annotation.data.TargettingStructure;
import lcsb.mapviewer.annotation.services.*;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.model.Model;
@Transactional
public abstract class DbSearchService {
private static Logger logger = LogManager.getLogger();
@Autowired
private HgncAnnotator hgncAnnotator;
@Autowired
private PubmedParser pubmedParser;
......@@ -42,4 +49,42 @@ public abstract class DbSearchService {
}
}
protected Set<MiriamData> getHgncIdentifiers(List<Model> models) {
Set<BioEntity> targetElements = new HashSet<>();
for (Model model : models) {
targetElements.addAll(model.getBioEntities());
}
return getHgncIdentifiers(targetElements);
}
protected Set<MiriamData> getHgncIdentifiers(Collection<? extends BioEntity> bioEntities) {
Set<MiriamData> result = new HashSet<>();
for (BioEntity element : bioEntities) {
for (MiriamData md : element.getMiriamData()) {
if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) {
result.add(md);
}
}
boolean validClass = false;
for (Class<?> clazz : MiriamType.HGNC_SYMBOL.getValidClass()) {
if (clazz.isAssignableFrom(element.getClass())) {
validClass = true;
}
}
if (validClass) {
MiriamData md = new MiriamData(MiriamType.HGNC_SYMBOL, element.getName());
try {
if (hgncAnnotator.isValidHgncMiriam(md)) {
result.add(md);
}
} catch (AnnotatorException e) {
logger.error("Problem with accessing HGNC database", e);
}
}
}
return result;
}
}
......@@ -15,7 +15,9 @@ import lcsb.mapviewer.annotation.services.dapi.ChemicalParser;
import lcsb.mapviewer.annotation.services.dapi.ChemicalSearchException;
import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.species.*;
import lcsb.mapviewer.services.search.DbSearchCriteria;
......@@ -122,19 +124,11 @@ public class ChemicalService extends DbSearchService implements IChemicalService
MiriamData disease = originalModel.getProject().getDisease();
if (disease != null) {
logger.debug("Caching chemical queries...");
Set<MiriamData> targetMiriams = new HashSet<>();
List<Model> models = new ArrayList<>();
models.add(originalModel);
models.addAll(originalModel.getSubmodels());
for (Model model : models) {
for (BioEntity element : model.getBioEntities()) {
for (MiriamData md : element.getMiriamData()) {
if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) {
targetMiriams.add(md);
}
}
}
}
Set<MiriamData> targetMiriams = getHgncIdentifiers(models);
double counter = 0.0;
for (MiriamData md : targetMiriams) {
try {
......@@ -149,8 +143,19 @@ public class ChemicalService extends DbSearchService implements IChemicalService
progress = counter / (double) targetMiriams.size();
iProgressUpdater.setProgress(progress * IProgressUpdater.MAX_PROGRESS);
}
try {
getSuggestedQueryList(originalModel.getProject(), originalModel.getProject().getOrganism());
} catch (ChemicalSearchException e) {
logger.error("Problem with accessing chemical info", e);
}
} else {
logger.debug("Caching chemical queries not possible...");
}
}
@Override
public List<String> getSuggestedQueryList(Project project, MiriamData disease) throws ChemicalSearchException {
return chemicalParser.getSuggestedQueryList(project, disease);
}
}
package lcsb.mapviewer.services.search.chemical;
import java.util.List;
import lcsb.mapviewer.annotation.data.Chemical;
import lcsb.mapviewer.annotation.services.dapi.ChemicalSearchException;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.services.search.IDbSearchService;
/**
......@@ -11,4 +16,6 @@ import lcsb.mapviewer.services.search.IDbSearchService;
*/
public interface IChemicalService extends IDbSearchService<Chemical> {
List<String> getSuggestedQueryList(Project project, MiriamData disease) throws ChemicalSearchException;
}
......@@ -12,13 +12,12 @@ import lcsb.mapviewer.annotation.data.Drug;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.annotation.services.*;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator;
import lcsb.mapviewer.annotation.services.dapi.DrugBankParser;
import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.species.*;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.statistics.SearchType;
import lcsb.mapviewer.services.interfaces.ISearchHistoryService;
import lcsb.mapviewer.services.search.DbSearchCriteria;
......@@ -49,12 +48,6 @@ public class DrugService extends DbSearchService implements IDrugService {
*/
private ChEMBLParser chEMBLParser;
/**
* Object used to get information about {@link MiriamType#HGNC} annotations and
* transformations.
*/
private HgncAnnotator hgncAnnotator;
/**
* Service that manages search history.
*/
......@@ -63,11 +56,9 @@ public class DrugService extends DbSearchService implements IDrugService {
@Autowired
public DrugService(DrugBankParser drugBankParser,
ChEMBLParser chEMBLParser,
HgncAnnotator hgncAnnotator,
ISearchHistoryService searchHistoryService) {
this.drugBankParser = drugBankParser;
this.chEMBLParser = chEMBLParser;
this.hgncAnnotator = hgncAnnotator;
this.searchHistoryService = searchHistoryService;
}
......@@ -227,28 +218,7 @@ public class DrugService extends DbSearchService implements IDrugService {
@Override
public List<Drug> getForTargets(Collection<Element> targets, DbSearchCriteria searchCriteria) {
List<Drug> drugList = new ArrayList<>();
Set<MiriamData> targetsMiriam = new HashSet<>();
for (Element target : targets) {
if (target instanceof Protein || target instanceof Gene || target instanceof Rna) {
boolean hgncFound = false;
for (MiriamData md : target.getMiriamData()) {
if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) {
targetsMiriam.add(md);
hgncFound = true;
}
}
if (!hgncFound) {
MiriamData md = new MiriamData(MiriamType.HGNC_SYMBOL, target.getName());
try {
if (hgncAnnotator.isValidHgncMiriam(md)) {
targetsMiriam.add(md);
}
} catch (AnnotatorException e) {
logger.error("Problem with accessing HGNC database", e);
}
}
}
}
Set<MiriamData> targetsMiriam = getHgncIdentifiers(targets);
try {
List<Drug> drugs = drugBankParser.getDrugListByTargets(targetsMiriam, searchCriteria.getOrganisms());
drugList.addAll(drugs);
......@@ -278,36 +248,10 @@ public class DrugService extends DbSearchService implements IDrugService {
iProgressUpdater.setProgress(progress * IProgressUpdater.MAX_PROGRESS);
MiriamData disease = originalModel.getProject().getDisease();
if (disease != null) {
Set<MiriamData> targetMiriams = new HashSet<>();
List<Model> models = new ArrayList<>();
models.add(originalModel);
models.addAll(originalModel.getSubmodels());
for (Model model : models) {
for (BioEntity element : model.getBioEntities()) {
for (MiriamData md : element.getMiriamData()) {
if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) {
targetMiriams.add(md);
}
}
boolean validClass = false;
for (Class<?> clazz : MiriamType.HGNC_SYMBOL.getValidClass()) {
if (clazz.isAssignableFrom(element.getClass())) {
validClass = true;
}
}
if (validClass) {
MiriamData md = new MiriamData(MiriamType.HGNC_SYMBOL, element.getName());
try {
if (hgncAnnotator.isValidHgncMiriam(md)) {
targetMiriams.add(md);
}
} catch (AnnotatorException e) {
logger.error("Problem with accessing HGNC database", e);
}
}
}
}
Set<MiriamData> targetMiriams = getHgncIdentifiers(models);
double counter = 0.0;
List<MiriamData> organisms = new ArrayList<>();
for (MiriamData md : targetMiriams) {
......
package lcsb.mapviewer.services.search.mirna;
import java.util.List;
import lcsb.mapviewer.annotation.data.MiRNA;
import lcsb.mapviewer.annotation.services.MiRNASearchException;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.services.search.IDbSearchService;
/**
......@@ -10,5 +14,6 @@ import lcsb.mapviewer.services.search.IDbSearchService;
*
*/
public interface IMiRNAService extends IDbSearchService<MiRNA> {
public List<String> getSuggestedQueryList(Project project) throws MiRNASearchException;
}
......@@ -14,6 +14,7 @@ import lcsb.mapviewer.annotation.services.MiRNASearchException;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator;
import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.species.*;
......@@ -122,21 +123,11 @@ public class MiRNAService extends DbSearchService implements IMiRNAService {
logger.debug("Caching mirna queries...");
double progress = 0.0;
iProgressUpdater.setProgress(progress * IProgressUpdater.MAX_PROGRESS);
Set<MiriamData> targetMiriams = new HashSet<>();
List<Model> models = new ArrayList<>();
models.add(originalModel);
models.addAll(originalModel.getSubmodels());
for (Model model : models) {
for (BioEntity element : model.getBioEntities()) {
for (MiriamData md : element.getMiriamData()) {
if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) {
targetMiriams.add(md);
} else if (MiriamType.ENTREZ.equals(md.getDataType())) {
targetMiriams.add(md);
}
}
}
}
Set<MiriamData> targetMiriams = getHgncIdentifiers(models);
targetMiriams.addAll(getEntrezIdentifiers(models));
double counter = 0.0;
int step = Math.max(targetMiriams.size() / 100, 1);
List<MiriamData> currentList = new ArrayList<>();
......@@ -146,8 +137,8 @@ public class MiRNAService extends DbSearchService implements IMiRNAService {
if (currentList.size() >= step) {
logger.debug("check mirna target: " + currentList);
try {
List<MiRNA> chemicalList = miRNAParser.getMiRnaListByTargets(currentList);
for (MiRNA chemical : chemicalList) {
List<MiRNA> mirnaList = miRNAParser.getMiRnaListByTargets(currentList);
for (MiRNA chemical : mirnaList) {
cacheMiriamData(chemical);
}
} catch (MiRNASearchException | AnnotatorException e) {
......@@ -158,6 +149,25 @@ public class MiRNAService extends DbSearchService implements IMiRNAService {
currentList.clear();
}
}
try {
getSuggestedQueryList(originalModel.getProject());
} catch (MiRNASearchException e) {
logger.error("Problem with accessing mirna info", e);
}
}
private Set<MiriamData> getEntrezIdentifiers(List<Model> models) {
Set<MiriamData> targetMiriams = new HashSet<>();
for (Model model : models) {
for (BioEntity element : model.getBioEntities()) {
for (MiriamData md : element.getMiriamData()) {
if (MiriamType.ENTREZ.equals(md.getDataType())) {
targetMiriams.add(md);
}
}
}
}
return targetMiriams;
}
/**
......@@ -190,4 +200,9 @@ public class MiRNAService extends DbSearchService implements IMiRNAService {
}
}
@Override
public List<String> getSuggestedQueryList(Project project) throws MiRNASearchException {
return miRNAParser.getSuggestedQueryList(project);
}
}
......@@ -12,6 +12,7 @@ import lcsb.mapviewer.annotation.data.MiRNA;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.annotation.services.TaxonomyBackend;
import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.model.Model;
......@@ -35,6 +36,7 @@ public class MiRNAServiceTest extends ServiceTestFunctions {
@Test
public void testCacheStub() throws Exception {
Model model = new ModelFullIndexed(null);
model.setProject(new Project());
miRNAService.cacheDataForModel(model, new IProgressUpdater() {
@Override
public void setProgress(double progress) {
......
Supports Markdown
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