Skip to content
Snippets Groups Projects
Commit b77c155b authored by Piotr Gawron's avatar Piotr Gawron
Browse files

drugbank results are manually limited by the name match

searched name must match at least on of:
* drug name
* brand name
* synonym
parent 5bb69452
No related branches found
No related tags found
No related merge requests found
package lcsb.mapviewer.annotation.services;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collection;
......@@ -447,6 +448,10 @@ public class DrugbankHTMLParser extends DrugAnnotation implements IExternalServi
result.setBloodBrainBarrier(getBloodBrainBarrier(page));
result.setApproved(getApproved(page));
if (!nameMatch(result, name)) {
result = null;
}
}
} catch (IOException e) {
throw new DrugSearchException(e);
......@@ -454,6 +459,35 @@ public class DrugbankHTMLParser extends DrugAnnotation implements IExternalServi
return result;
}
/**
* Check if drug data mateches with the search name.
*
* @param drug
* drug to be checked
* @param name
* name of the drug that we were looking for
* @return true if if drug data matches with the search name
*/
private boolean nameMatch(Drug drug, String name) {
Set<String> foundNames = new HashSet<>();
foundNames.add(drug.getName());
foundNames.addAll(drug.getSynonyms());
foundNames.addAll(drug.getBrandNames());
String lowerCaseName;
try {
lowerCaseName = java.net.URLDecoder.decode(name, "UTF-8").toLowerCase().replaceAll("[^A-Za-z0-9]", "");
} catch (UnsupportedEncodingException e) {
lowerCaseName = name.toLowerCase().replaceAll("[^A-Za-z0-9]", "");
}
for (String string : foundNames) {
String query = string.toLowerCase().replaceAll("[^A-Za-z0-9]", "");
if (query.contains(lowerCaseName)) {
return true;
}
}
return false;
}
/**
* Finds blood brain barrier info about drug in the webpage content.
*
......
......@@ -197,18 +197,6 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
}
}
// at some point this search threw exception
@Test
public void testFindDrugKainicAcid() throws Exception {
try {
Drug test = drugBankHTMLParser.findDrug("kainic acid");
assertNotNull(test);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testFindDrugAmantadineWithBrandNames() throws Exception {
try {
......@@ -305,7 +293,7 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
@Test
public void testFindAluminiumByName() throws Exception {
try {
Drug drug = drugBankHTMLParser.findDrug("Aluminium");
Drug drug = drugBankHTMLParser.findDrug("Aluminium");
assertTrue(drug.getName().equalsIgnoreCase("Aluminium"));
} catch (Exception e) {
......@@ -314,6 +302,21 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
}
}
@Test
public void testFindBIIB054ByName() throws Exception {
try {
Drug drug = drugBankHTMLParser.findDrug("BIIB054");
if (drug != null) {
// check if are not pointint to BIIB021
assertFalse(drug.getSources().get(0).getResource().equalsIgnoreCase("DB12359"));
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testFindDrugByHgncTargetAndFilteredOutByOrganism() throws Exception {
try {
......@@ -483,7 +486,7 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
assertEquals("Ibuprofen", test.getName());
assertEquals("DB01050", test.getSources().get(0).getResource());
assertNotNull(test.getDescription());
assertEquals(8, test.getTargets().size());
assertTrue(test.getTargets().size()>=8);
} catch (Exception e) {
e.printStackTrace();
......@@ -731,5 +734,5 @@ public class DrugbankHTMLParserTest extends AnnotationTestFunctions {
assertEquals(2, target.getReferences().size());
assertEquals("Galactoside O-acetyltransferase", target.getName());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment