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

ChemicalView and ChemicalViewFactory removed

parent 5b7ffad1
No related branches found
No related tags found
1 merge request!75Resolve "MiRNA - Show all - duplicated entries"
......@@ -2,12 +2,14 @@ package lcsb.mapviewer.annotation.data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.commons.lang3.StringUtils;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.model.map.MiriamData;
/**
......@@ -269,4 +271,23 @@ public class Chemical implements Serializable {
return result.toString();
}
/**
* Comparator of the objects by their name.
*
* @author Piotr Gawron
*
*/
public static class NameComparator implements Comparator<Chemical> {
/**
* Default string comparator.
*/
private StringComparator stringComparator = new StringComparator();
@Override
public int compare(Chemical arg0, Chemical arg1) {
return stringComparator.compare(arg0.getChemicalName(), arg1.getChemicalName());
}
}
}
......@@ -17,8 +17,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.annotation.data.Chemical;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.annotation.services.ChemicalParser;
import lcsb.mapviewer.annotation.services.ChemicalSearchException;
import lcsb.mapviewer.annotation.services.PubmedParser;
import lcsb.mapviewer.annotation.services.PubmedSearchException;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator;
import lcsb.mapviewer.common.IProgressUpdater;
......@@ -61,16 +64,17 @@ public class ChemicalService implements IChemicalService {
private ChemicalParser chemicalParser;
/**
* Factory object used for creation of {@link ChemicalView} elements.
* Object used to perform operations on {@link MiriamType#HGNC} annotations.
*/
@Autowired
private ChemicalViewFactory chemicalViewFactory;
private HgncAnnotator hgncAnnotator;
/**
* Object used to perform operations on {@link MiriamType#HGNC} annotations.
* Service accessing
* <a href="http://europepmc.org/RestfulWebService">pubmed</a>.
*/
@Autowired
private HgncAnnotator hgncAnnotator;
private PubmedParser pubmedParser;
/**
* Service that manages search history.
......@@ -215,7 +219,8 @@ public class ChemicalService implements IChemicalService {
if (result.size() == 0) {
return null;
} else {
// return chemicalViewFactory.create(result.get(0), searchCriteria.getModel(), searchCriteria.getColorSet());
// return chemicalViewFactory.create(result.get(0),
// searchCriteria.getModel(), searchCriteria.getColorSet());
return result.get(0);
}
......@@ -256,8 +261,7 @@ public class ChemicalService implements IChemicalService {
logger.error("Problem with accessing chemical database", e);
}
Collections.sort(chemicalList, new ChemicalView.NameComparator());
Collections.sort(chemicalList, new Chemical.NameComparator());
return chemicalList;
}
......@@ -300,13 +304,19 @@ public class ChemicalService implements IChemicalService {
}
}
double counter = 0.0;
Set<MiriamData> annotations = new HashSet<>();
for (MiriamData md : targetMiriams) {
try {
List<Chemical> chemicalList = chemicalParser.getChemicalListByTarget(md, disease);
for (Chemical chemical : chemicalList) {
chemicalViewFactory.create(chemical);
annotations.addAll(getAllMiriamDataForChemical(chemical));
}
} catch (ChemicalSearchException e) {
for (MiriamData miriamData : annotations) {
if (miriamData.getDataType().equals(MiriamType.PUBMED)) {
pubmedParser.getPubmedArticleById(Integer.valueOf(miriamData.getResource()));
}
}
} catch (ChemicalSearchException | NumberFormatException | PubmedSearchException e) {
logger.error("Problem with accessing info about chemical for target: " + md, e);
}
counter += 1;
......@@ -318,4 +328,16 @@ public class ChemicalService implements IChemicalService {
}
}
private Set<MiriamData> getAllMiriamDataForChemical(Chemical chemical) {
Set<MiriamData> result = new HashSet<>();
result.add(chemical.getCasID());
result.add(chemical.getChemicalId());
for (Target target : chemical.getInferenceNetwork()) {
result.addAll(target.getGenes());
result.addAll(target.getReferences());
}
return result;
}
}
package lcsb.mapviewer.services.search.db.chemical;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import org.apache.log4j.Logger;
import lcsb.mapviewer.annotation.data.Article;
import lcsb.mapviewer.annotation.data.Chemical;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.services.search.ISearchResultView;
import lcsb.mapviewer.services.search.db.TargetView;
import lcsb.mapviewer.services.view.AbstractView;
import lcsb.mapviewer.services.view.AnnotationView;
/**
* Data of the chemical from external database to be visualized in the client
* side.
*
* @author Ayan Rota
*
*/
public class ChemicalView extends AbstractView<Chemical> implements ISearchResultView, Serializable {
/**
*
*/
private static final long serialVersionUID = 91486136745430139L;
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(ChemicalView.class);
/**
* Is the chemical selected by the client or not.
*/
private boolean selected = false;
/**
* Name of the chemical.
*/
private String name;
/**
* Detailed description of the MeSH object.
*/
private String description;
/**
* List of synonyms.
*/
private List<String> synonyms = new ArrayList<>();
/**
* Link for cas id.
*/
private AnnotationView casLink;
/**
* The direct Evedince if any.
*/
private String directEvidence;
/**
* List of links to extenral databases.
*/
private List<Article> directEvidencePubs = new ArrayList<>();
/**
* Link for source.
*/
private AnnotationView sourceLink;
/**
* List of targets for the chemical.
*/
private List<TargetView> targetRows = new ArrayList<>();
/***
* Constructor that initialize the data with information from the
* parameter*object.
**
* @param chemical
* original Chemical from which the data will be initialized
*/
protected ChemicalView(Chemical chemical) {
// chemical is not db entity so don't pass it to super constructor
super(null);
}
/**
* Default constructor. Should be used only for deserialization.
*/
protected ChemicalView() {
}
/**
* Default constructor that creates a copy.
*
* @param original
* origianl object that should be copied
*/
public ChemicalView(ChemicalView original) {
super(null);
selected = original.isSelected();
name = original.getName();
targetRows.addAll(original.getTargetRows());
}
/**
* Comparator of the objects by their name.
*
* @author Piotr Gawron
*
*/
public static class NameComparator implements Comparator<Chemical> {
/**
* Default string comparator.
*/
private StringComparator stringComparator = new StringComparator();
@Override
public int compare(Chemical arg0, Chemical arg1) {
return stringComparator.compare(arg0.getChemicalName(), arg1.getChemicalName());
}
}
/**
* @return the selected
*/
public boolean isSelected() {
return selected;
}
/**
* @param selected
* the selected to set
*/
public void setSelected(boolean selected) {
this.selected = selected;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the directEvedince
*/
public String getDirectEvedince() {
return directEvidence;
}
/**
* @param directEvedince
* the directEvedince to set
*/
public void setDirectEvedince(String directEvedince) {
this.directEvidence = directEvedince;
}
/**
* @return the targetRows
*/
public List<TargetView> getTargetRows() {
return targetRows;
}
/**
* @param targetRows
* the targetRows to set
*/
public void setTargetRows(List<TargetView> targetRows) {
this.targetRows = targetRows;
}
/**
* Adds object to {@link #directEvidencePubs}.
*
* @param article
* object to add
*/
public void addDirectEvidence(Article article) {
directEvidencePubs.add(article);
}
/**
* @return casLink
*/
public AnnotationView getCasLink() {
return casLink;
}
/**
* @param casLink
* a link to Cas
*/
public void setCasLink(AnnotationView casLink) {
this.casLink = casLink;
}
/**
* @return direct evidence.
*/
public String getDirectEvidence() {
return directEvidence;
}
/**
* @param directEvidence
* a text to indicate if there is direct evidence found.
*/
public void setDirectEvidence(String directEvidence) {
this.directEvidence = directEvidence;
}
/**
* @return the link to the source database of chemicals.
*/
public AnnotationView getSourceLink() {
return sourceLink;
}
/**
* @param sourceLink
* the link to database of chemicals.
*/
public void setSourceLink(AnnotationView sourceLink) {
this.sourceLink = sourceLink;
}
/**
* Returns link to pubmed that enlist all references.
*
* @return link to pubmed that enlist all references
*/
public String getAllDirectEvidenceLinks() {
String result = "http://www.ncbi.nlm.nih.gov/pubmed/?term=";
for (Article publication : directEvidencePubs) {
result += publication.getId() + " ";
}
return result;
}
/**
* @return all articles/publications associated with the chemical direct
* evidence.
*/
public List<Article> getDirectEvidencePubs() {
return directEvidencePubs;
}
/**
* @param directEvidencePubs
* all articles/publications associated with the chemical direct
* evidence.
*/
public void setDirectEvidencePubs(List<Article> directEvidencePubs) {
this.directEvidencePubs = directEvidencePubs;
}
/**
* @param description
* description of the Chemicals.
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @return description of Chemical.
*/
public String getDescription() {
return description;
}
/**
* @return list of Synonyms.
*/
public List<String> getSynonyms() {
return synonyms;
}
/**
* @param synonyms
* list of Synonyms.
*/
public void setSynonyms(List<String> synonyms) {
this.synonyms = synonyms;
}
@Override
public String getUniqueId() {
return name;
}
@Override
public void setUniqueId(String uniqueId) {
this.name = uniqueId;
}
}
package lcsb.mapviewer.services.search.db.chemical;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import com.google.gson.Gson;
import lcsb.mapviewer.annotation.data.Article;
import lcsb.mapviewer.annotation.data.ArticleCitationComparator;
import lcsb.mapviewer.annotation.data.Chemical;
import lcsb.mapviewer.annotation.data.MeSH;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.annotation.services.MeSHParser;
import lcsb.mapviewer.annotation.services.PubmedParser;
import lcsb.mapviewer.annotation.services.PubmedSearchException;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
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.Element;
import lcsb.mapviewer.services.overlay.IconManager;
import lcsb.mapviewer.services.overlay.IconType;
import lcsb.mapviewer.services.search.SearchResultFactory;
import lcsb.mapviewer.services.search.data.ElementIdentifier;
import lcsb.mapviewer.services.search.db.DrugTargetViewVisibilityComparator;
import lcsb.mapviewer.services.search.db.TargetView;
import lcsb.mapviewer.services.search.db.TargetViewFactory;
import lcsb.mapviewer.services.view.AnnotationViewFactory;
/**
* Factory class for {@link ChemicalView} class.
*
* @author Ayan Rota
*
*/
public class ChemicalViewFactory extends SearchResultFactory<Chemical, ChemicalView> {
/**
* Default class logger.
*/
private static Logger logger = Logger.getLogger(ChemicalViewFactory.class);
/**
* Factory object used for creation of
* {@link lcsb.mapviewer.services.view.AnnotationView} elements.
*/
@Autowired
private AnnotationViewFactory annotationViewFactory;
/**
* Service accessing
* <a href="http://europepmc.org/RestfulWebService">pubmed</a>.
*/
@Autowired
private PubmedParser pubmedParser;
/**
* Factory object used for creation of {@link TargetView} elements.
*/
@Autowired
private TargetViewFactory drugTargetViewFactory;
/**
* Service accessing <a href="http://europepmc.org/RestfulWebService">mesh</a>
* .
*/
@Autowired
private MeSHParser meSHParser;
@Override
public ChemicalView create(Chemical chemical) {
return create(chemical, null, 0);
}
/**
* Creates {@link ChemicalView}.
*
* @param chemical
* original Chemical from which the data will be initialized
* @param model
* model where the view will be presented
* @param set
* which set of icons should be used
*
* @return {@link ChemicalView} object for given chemical. links are placed
* according to model given in the parameter.
*/
public ChemicalView create(Chemical chemical, Model model, int set) {
ChemicalView chemicalView = new ChemicalView(chemical);
if (chemical == null) {
return chemicalView;
}
chemicalView.setName(chemical.getChemicalName());
if (chemical.getDirectEvidence() != null) {
chemicalView.setDirectEvedince(chemical.getDirectEvidence().getValue());
}
if (chemical.getChemicalId() != null) {
chemicalView.setSourceLink(annotationViewFactory.create(chemical.getChemicalId()));
try {
MeSH mesh = meSHParser.getMeSH(chemical.getChemicalId());
if (mesh != null) {
chemicalView.setDescription(mesh.getDescription());
chemicalView.setSynonyms(mesh.getSynonyms());
} else {
chemicalView.setDescription("Mesh term not available");
}
} catch (AnnotatorException e) {
logger.error("Problem with accessing mesh database", e);
chemicalView.setDescription("Mesh term not available");
}
}
if (chemical.getCasID() != null) {
chemicalView.setCasLink(annotationViewFactory.create(chemical.getCasID()));
}
List<Article> articles = new ArrayList<Article>();
for (MiriamData publication : chemical.getDirectEvidencePublication()) {
if (publication.getDataType().equals(MiriamType.PUBMED)) {
Integer id = Integer.parseInt(publication.getResource());
try {
Article article = pubmedParser.getPubmedArticleById(id);
if (article != null) {
articles.add(article);
}
} catch (PubmedSearchException e) {
logger.error("Problem with accessing info about pubmed", e);
}
} else {
logger.warn("Unknown publication type: " + publication);
}
}
Collections.sort(articles, new ArticleCitationComparator());
chemicalView.setDirectEvidencePubs(articles);
List<TargetView> targetsRows = new ArrayList<>();
int differentNames = 0;
for (Target geneEntry : chemical.getInferenceNetwork()) {
targetsRows.add(drugTargetViewFactory.create(geneEntry, model));
}
Collections.sort(targetsRows, new DrugTargetViewVisibilityComparator());
for (TargetView geneTargetView : targetsRows) {
if (geneTargetView.getSelectable()) {
String icon = IconManager.getInstance().getIconForIndex(differentNames++, IconType.CHEMICAL, set);
geneTargetView.setIcon(icon);
geneTargetView.setSelected(true);
}
}
chemicalView.setTargetRows(targetsRows);
return chemicalView;
}
@Override
public String createGson(ChemicalView object) {
return new Gson().toJson(object);
}
@Override
public List<ElementIdentifier> searchResultToElementIdentifier(ChemicalView chemical, Model inputModel) {
List<ElementIdentifier> result = new ArrayList<>();
List<Model> models = new ArrayList<>();
models.addAll(inputModel.getSubmodels());
models.add(inputModel);
for (Model model : models) {
for (TargetView target : chemical.getTargetRows()) {
if (target.getSelected() && target.getIcon() != null) {
for (Element element : model.getElements()) {
if (elementMatch(target, element)) {
result.add(new ElementIdentifier(element, target.getIcon()));
}
}
}
}
}
return result;
}
}
......@@ -15,10 +15,8 @@ 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.GeneRow;
import lcsb.mapviewer.services.search.db.TargetView;
import lcsb.mapviewer.services.search.db.chemical.ChemicalViewFactory;
import lcsb.mapviewer.services.search.db.chemical.IChemicalService;
public class SearchResultFactoryTest extends ServiceTestFunctions {
......@@ -26,7 +24,7 @@ public class SearchResultFactoryTest extends ServiceTestFunctions {
Logger logger = Logger.getLogger(SearchResultFactoryTest.class);
@Autowired
ChemicalViewFactory factory;
FullCommentViewFactory factory;
@Autowired
IChemicalService chemicalService;
......
......@@ -79,7 +79,6 @@ import lcsb.mapviewer.services.interfaces.IProjectService;
import lcsb.mapviewer.services.interfaces.IReferenceGenomeService;
import lcsb.mapviewer.services.interfaces.ISearchService;
import lcsb.mapviewer.services.interfaces.IUserService;
import lcsb.mapviewer.services.search.db.chemical.ChemicalViewFactory;
import lcsb.mapviewer.services.search.db.chemical.IChemicalService;
import lcsb.mapviewer.services.search.db.drug.DrugViewFactory;
import lcsb.mapviewer.services.search.db.drug.IDrugService;
......@@ -194,9 +193,6 @@ public abstract class WebTestFunctions {
@Autowired
protected DrugViewFactory drugViewFactory;
@Autowired
protected ChemicalViewFactory chemicalViewFactory;
@Autowired
protected IReferenceGenomeService referenceGenomeService;
......
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