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

when matching other target there was problem when no gene was defiend

parent e9ec958a
No related branches found
No related tags found
1 merge request!98Resolve "doubled results when searching for dugs"
......@@ -103,8 +103,17 @@ public class ElementMatcher {
return false;
case OTHER:
// in other case just compare names
String name = target.getGenes().get(0).getResource();
return element.getName().equalsIgnoreCase(name);
String targetName = null;
if (target.getGenes().size() > 0) {
targetName = target.getGenes().get(0).getResource();
}
if (targetName == null) {
targetName = target.getName();
}
if (targetName == null) {
return false;
}
return element.getName().equalsIgnoreCase(targetName);
default:
throw new InvalidArgumentException("Unknown drug target type: " + target.getType());
}
......
......@@ -13,7 +13,8 @@ import lcsb.mapviewer.services.search.layout.AllSearchLayoutTests;
@SuiteClasses({ AllCommentTests.class, //
AllSearchDbTests.class, //
AllSearchDataTests.class, //
AllSearchLayoutTests.class,//
AllSearchLayoutTests.class, //
ElementMatcherTest.class, //
})
public class AllSearchTests {
......
package lcsb.mapviewer.services.search;
import static org.junit.Assert.assertTrue;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.annotation.data.Chemical;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.services.ServiceTestFunctions;
import lcsb.mapviewer.services.search.comment.FullCommentViewFactory;
import lcsb.mapviewer.services.search.db.DbSearchCriteria;
import lcsb.mapviewer.services.search.db.chemical.IChemicalService;
public class SearchResultFactoryTest extends ServiceTestFunctions {
Logger logger = Logger.getLogger(SearchResultFactoryTest.class);
@Autowired
FullCommentViewFactory factory;
@Autowired
IChemicalService chemicalService;
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testElementMatch() {
String geneName = "GDNF";
Chemical view = chemicalService.getByName("Amphetamine", new DbSearchCriteria().disease(new MiriamData(MiriamType.MESH_2012, "D010300")));
Target target = null;
for (Target t : view.getInferenceNetwork()) {
for (MiriamData row : t.getGenes()) {
if (row.getResource().equals(geneName)) {
target = t;
}
}
}
Element element = new Rna("id");
element.setName(geneName);
assertTrue(factory.elementMatch(target, element));
}
}
package lcsb.mapviewer.services.search;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.annotation.data.Chemical;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.annotation.data.TargetType;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.services.ServiceTestFunctions;
import lcsb.mapviewer.services.search.db.DbSearchCriteria;
public class ElementMatcherTest extends ServiceTestFunctions {
@Autowired
ElementMatcher elementMatcher;
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testMatchOther() {
Target target = new Target();
target.setType(TargetType.OTHER);
assertFalse(elementMatcher.elementMatch(target, new GenericProtein("s1")));
}
@Test
public void testElementMatch() {
String geneName = "GDNF";
Chemical view = chemicalService.getByName("Amphetamine", new DbSearchCriteria().disease(new MiriamData(MiriamType.MESH_2012, "D010300")));
Target target = null;
for (Target t : view.getInferenceNetwork()) {
for (MiriamData row : t.getGenes()) {
if (row.getResource().equals(geneName)) {
target = t;
}
}
}
Element element = new Rna("id");
element.setName(geneName);
assertTrue(elementMatcher.elementMatch(target, element));
}
}
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