Commit 5084a51e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

mirna view factory removed

parent 53974549
......@@ -15,8 +15,11 @@ import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.annotation.data.MiRNA;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.annotation.data.TargettingStructure;
import lcsb.mapviewer.annotation.services.MiRNAParser;
import lcsb.mapviewer.annotation.services.MiRNASearchException;
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;
......@@ -60,16 +63,17 @@ public class MiRNAService implements IMiRNAService {
private HgncAnnotator hgncAnnotator;
/**
* Factory object used for creation of {@link MiRNAView} elements.
* Service that manages search history.
*/
@Autowired
private MiRNAViewFactory miRNAViewFactory;
private ISearchHistoryService searchHistoryService;
/**
* Service that manages search history.
* Service accessing
* <a href="http://europepmc.org/RestfulWebService">pubmed</a>.
*/
@Autowired
private ISearchHistoryService searchHistoryService;
private PubmedParser pubmedParser;
/**
* Default constructor.
......@@ -162,7 +166,7 @@ public class MiRNAService implements IMiRNAService {
for (MiRNA drug : mirnaList) {
removeUnknownOrganisms(drug, searchCriteria.getOrganisms());
}
Collections.sort(mirnaList, new MiRNAView.NameComparator());
return mirnaList;
}
......@@ -227,9 +231,9 @@ public class MiRNAService implements IMiRNAService {
try {
List<MiRNA> chemicalList = miRNAParser.getMiRnaListByTargets(currentList);
for (MiRNA chemical : chemicalList) {
miRNAViewFactory.create(chemical);
cacheMiriamData(chemical);
}
} catch (MiRNASearchException e) {
} catch (MiRNASearchException | AnnotatorException e) {
logger.error("Problem with accessing info about mirna for target: " + md, e);
}
progress = counter / (double) targetMiriams.size();
......@@ -239,4 +243,25 @@ public class MiRNAService implements IMiRNAService {
}
}
private void cacheMiriamData(TargettingStructure targettingStructure) throws AnnotatorException {
Set<MiriamData> result = new HashSet<>();
result.addAll(targettingStructure.getSources());
for (Target target : targettingStructure.getTargets()) {
result.addAll(target.getGenes());
result.addAll(target.getReferences());
}
for (MiriamData miriamData : result) {
if (miriamData.getDataType().equals(MiriamType.PUBMED)) {
try {
pubmedParser.getPubmedArticleById(Integer.valueOf(miriamData.getResource()));
} catch (NumberFormatException | PubmedSearchException e) {
throw new AnnotatorException(e);
}
}
}
}
}
package lcsb.mapviewer.services.search.db.mirna;
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.MiRNA;
import lcsb.mapviewer.annotation.data.Target;
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;
/**
* Factory class for {@link MiRNAView} class.
*
* @author Ayan Rota
*
*/
public class MiRNAViewFactory extends SearchResultFactory<MiRNA, MiRNAView> {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(MiRNAViewFactory.class);
/**
* Factory object for {@link TargetView} elements.
*/
@Autowired
private TargetViewFactory drugTargetViewFactory;
@Override
public MiRNAView create(MiRNA miRNA) {
return create(miRNA, null, 0);
}
/**
* Creates {@link MiRNAView}.
*
* @param miRNA
* original MiRNA 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 MiRNAView} object for given miRNA. links are placed
* according to model given in the parameter.
*/
public MiRNAView create(MiRNA miRNA, Model model, int set) {
MiRNAView miRNAView = new MiRNAView(miRNA);
if (miRNA == null) {
return miRNAView;
}
miRNAView.setName(miRNA.getName());
List<TargetView> targetsRows = new ArrayList<>();
int differentNames = 0;
for (Target geneEntry : miRNA.getTargets()) {
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.MI_RNA, set);
geneTargetView.setIcon(icon);
geneTargetView.setSelected(true);
}
}
miRNAView.setTargetRows(targetsRows);
return miRNAView;
}
@Override
public String createGson(MiRNAView object) {
return new Gson().toJson(object);
}
@Override
public List<ElementIdentifier> searchResultToElementIdentifier(MiRNAView searchResult, 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 : searchResult.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;
}
}
......@@ -68,7 +68,6 @@
<bean id="FullReactionViewFactory" class="lcsb.mapviewer.services.search.data.FullReactionViewFactory"/>
<bean id="LightAliasViewFactory" class="lcsb.mapviewer.services.search.data.LightAliasViewFactory"/>
<bean id="MiRNAViewFactory" class="lcsb.mapviewer.services.search.db.mirna.MiRNAViewFactory"/>
<bean id="TargetViewFactory" class="lcsb.mapviewer.services.search.db.TargetViewFactory"/>
<bean id="ElementMatcher" class="lcsb.mapviewer.services.search.ElementMatcher"/>
......
Markdown is supported
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