Commit 3a44f0ec authored by Piotr Gawron's avatar Piotr Gawron
Browse files

don't show targets that don't belong to searched disease

parent 1a1b329e
......@@ -225,7 +225,7 @@ public class Target implements Serializable {
@Override
public String toString() {
return "[" + this.getClass().getSimpleName() + "]: " + name + ", source: " + source + ", organism: " + organism
+ "; ";
+ "; disease: " + associatedDisease;
}
public MiriamData getAssociatedDisease() {
......
......@@ -68,7 +68,7 @@ public class ChemicalParser {
ListChemicalEntityDto dto = objectMapper.readValue(content, ListChemicalEntityDto.class);
return fetchChemicals(dto);
return fetchChemicals(dto, disease);
} catch (DapiConnectionException | IOException e) {
throw new ChemicalSearchException("Problem with accessing DAPI", e);
}
......@@ -136,18 +136,10 @@ public class ChemicalParser {
ListChemicalEntityDto dto = objectMapper.readValue(content, ListChemicalEntityDto.class);
List<Chemical> chemicals = fetchChemicals(dto);
List<Chemical> chemicals = fetchChemicals(dto, disease);
for (Chemical drug : chemicals) {
Set<Target> targetsToRemove = new HashSet<>();
for (Target drugTarget : drug.getTargets()) {
if (!drugTarget.getAssociatedDisease().equals(disease)) {
targetsToRemove.add(drugTarget);
}
}
drug.removeTargets(targetsToRemove);
result.put(drug.getChemicalId(), drug);
}
}
return new ArrayList<>(result.values());
} catch (DapiConnectionException | IOException e) {
......@@ -220,14 +212,14 @@ public class ChemicalParser {
+ URLEncoder.encode(disease.getPrefixedIdentifier(), "UTF-8"));
ListChemicalEntityDto result = objectMapper.readValue(content, ListChemicalEntityDto.class);
List<Chemical> chemicals = fetchChemicals(result);
List<Chemical> chemicals = fetchChemicals(result, disease);
if (chemicals.size() == 0) {
content = dapiConnector
.getAuthenticatedContent(
url + "/drugs/?columns=sourceIdentifier&synonym=" + URLEncoder.encode(chemicalName, "UTF-8"));
result = objectMapper.readValue(content, ListChemicalEntityDto.class);
chemicals = fetchChemicals(result);
chemicals = fetchChemicals(result, disease);
}
return chemicals;
} catch (DapiConnectionException | IOException e) {
......@@ -235,10 +227,10 @@ public class ChemicalParser {
}
}
private List<Chemical> fetchChemicals(ListChemicalEntityDto list) throws DapiConnectionException {
private List<Chemical> fetchChemicals(ListChemicalEntityDto list, MiriamData disease) throws DapiConnectionException {
List<Chemical> result = new ArrayList<>();
for (ChemicalEntityDto entity : list.getContent()) {
Chemical chemical = getByIdentifier(MiriamType.getMiriamDataFromPrefixIdentifier(entity.getSourceIdentifier()));
Chemical chemical = getByIdentifier(MiriamType.getMiriamDataFromPrefixIdentifier(entity.getSourceIdentifier()), disease);
if (chemical == null) {
logger.warn("Invalid chemical identifier: " + entity.getSourceIdentifier());
} else {
......@@ -248,7 +240,7 @@ public class ChemicalParser {
return result;
}
private Chemical getByIdentifier(MiriamData identifier) throws DapiConnectionException {
private Chemical getByIdentifier(MiriamData identifier, MiriamData disease) throws DapiConnectionException {
String url = dapiConnector.getLatestReleaseUrl(DAPI_DATABASE_NAME);
if (url == null) {
return null;
......@@ -258,7 +250,15 @@ public class ChemicalParser {
try {
ChemicalEntityDto result = objectMapper.readValue(content, ChemicalEntityDto.class);
return chemicalEntityDtoConverter.dtoToChemical(result);
Chemical chemical = chemicalEntityDtoConverter.dtoToChemical(result);
Set<Target> targetsToRemove = new HashSet<>();
for (Target t:chemical.getTargets()) {
if (disease!=null && !Objects.equals(t.getAssociatedDisease(), disease)) {
targetsToRemove.add(t);
}
}
chemical.removeTargets(targetsToRemove);
return chemical;
} catch (IOException e) {
throw new DapiConnectionException("Problem with accessing dapi", e);
}
......
......@@ -13,6 +13,7 @@ import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ActiveProfiles;
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;
......@@ -36,13 +37,15 @@ public class ChemicalServiceTest extends ServiceTestFunctions {
@Test
public void testgetChemicalByName() throws Exception {
MiriamData pdDiseaseID = new MiriamData(MiriamType.MESH_2012, "D010300");
MiriamData parkinsonDisease = new MiriamData(MiriamType.MESH_2012, "D010300");
String name = "GSSG";
Chemical result = chemicalService.getByName(name, new DbSearchCriteria().disease(pdDiseaseID));
Chemical result = chemicalService.getByName(name, new DbSearchCriteria().disease(parkinsonDisease));
assertNotNull(result);
assertEquals("D019803", result.getChemicalId().getResource());
logger.debug(result.getTargets());
for (Target t: result.getTargets()) {
assertEquals(t.getAssociatedDisease(), parkinsonDisease);
}
assertEquals("No warnings expected.", 0, getWarnings().size());
}
......
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