diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/DrugbankHTMLParser.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/DrugbankHTMLParser.java index 74b46508ad21d85e7fe81ede99ad0ead9419344f..de70f2f49512d700cc2a4348d59833f1168a960d 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/DrugbankHTMLParser.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/DrugbankHTMLParser.java @@ -607,40 +607,51 @@ public class DrugbankHTMLParser extends DrugAnnotation implements IExternalServi } @Override - public List<Drug> getDrugListByTarget(MiriamData target, Collection<MiriamData> organisms) throws DrugSearchException { + public List<Drug> getDrugListByTarget(MiriamData targetMiriamData, Collection<MiriamData> organisms) throws DrugSearchException { List<Drug> result = new ArrayList<>(); - if (target == null) { + if (targetMiriamData == null) { return result; } - if (!(MiriamType.HGNC_SYMBOL.equals(target.getDataType()))) { + if (!(MiriamType.HGNC_SYMBOL.equals(targetMiriamData.getDataType()))) { throw new InvalidArgumentException("Only " + MiriamType.HGNC_SYMBOL + " type is accepted"); } - String url = URL_TARGETS + target.getResource(); + String url = URL_TARGETS + targetMiriamData.getResource(); - String page; try { - page = getWebPageContent(url); - } catch (IOException e) { - throw new DrugSearchException("Cannot access drug database", e); - } + String page = getWebPageContent(url); - Set<String> drugNames = new HashSet<>(); + Set<String> drugNames = new HashSet<>(); - Matcher matcher = targetPattern.matcher(page); - while (matcher.find()) { - String drugbankTargetId = matcher.group(0); - drugNames.addAll(getDrugNamesForTarget(new MiriamData(MiriamType.DRUGBANK_TARGET_V4, drugbankTargetId), target, organisms)); - } - for (String string : drugNames) { - Drug drug = findDrug(string); - if (drug == null) { - logger.warn("Cannot find drug that should be there: " + string); - } else { - result.add(drug); + Matcher matcher = targetPattern.matcher(page); + while (matcher.find()) { + String drugbankTargetId = matcher.group(0); + drugNames.addAll(getDrugNamesForTarget(new MiriamData(MiriamType.DRUGBANK_TARGET_V4, drugbankTargetId), targetMiriamData, organisms)); + } + for (String string : drugNames) { + Drug drug = findDrug(string); + if (drug == null) { + logger.warn("Cannot find drug that should be there: " + string); + } else { + boolean targets = false; + for (Target target : drug.getTargets()) { + for (MiriamData gene : target.getGenes()) { + if (gene.equals(targetMiriamData)) { + targets = true; + } + } + } + if (targets) { + result.add(drug); + } else { + logger.debug("Skipping drug that doesn't target required target. Drug name: " + drug.getName() + "; target: " + targetMiriamData); + } + } } - } - return result; + return result; + } catch (IOException e) { + throw new DrugSearchException("Cannot access drug database", e); + } } /** diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/DrugbankHTMLParserTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/DrugbankHTMLParserTest.java index 11b429e1e4bca814655f992bbb3c2bc2084228a3..b68e455da37eb7e0b00243a6afc9858cfb3ea534 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/DrugbankHTMLParserTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/DrugbankHTMLParserTest.java @@ -290,6 +290,21 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions { } } + @Test + public void testFindDrugByTFTarget() throws Exception { + try { + List<Drug> drugs = drugBankHTMLParser.getDrugListByTarget(new MiriamData(MiriamType.HGNC_SYMBOL, "TF")); + assertNotNull(drugs); + for (Drug drug : drugs) { + assertFalse(drug.getName().equalsIgnoreCase("Iron saccharate")); + } + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + @Test public void testFindAluminiumByName() throws Exception { try {