use of ubic.gemma.model.common.description.BibliographicReference in project Gemma by PavlidisLab.
the class ExpressionExperimentPrimaryPubCli method doWork.
@Override
protected Exception doWork(String[] args) {
Exception err = processCommandLine(args);
if (err != null)
return err;
ExpressionExperimentService ees = this.getBean(ExpressionExperimentService.class);
Persister ph = this.getPersisterHelper();
PubMedXMLFetcher fetcher = new PubMedXMLFetcher();
// collect some statistics
Collection<String> nullPubCount = new ArrayList<>();
Collection<String> samePubCount = new ArrayList<>();
Collection<String> diffPubCount = new ArrayList<>();
Collection<String> failedEe = new ArrayList<>();
ExpressionExperimentBibRefFinder finder = new ExpressionExperimentBibRefFinder();
for (BioAssaySet bioassay : expressionExperiments) {
if (!(bioassay instanceof ExpressionExperiment)) {
log.info(bioassay.getName() + " is not an ExpressionExperiment");
continue;
}
ExpressionExperiment experiment = (ExpressionExperiment) bioassay;
// if ( experiment.getPrimaryPublication() != null ) continue;
if (experiment.getPrimaryPublication() == null) {
log.warn(experiment + " has no existing primary publication");
}
experiment = ees.thawLite(experiment);
// get from GEO or get from a file
BibliographicReference ref = fetcher.retrieveByHTTP(pubmedIds.get(experiment.getShortName()));
if (ref == null) {
if (this.pubmedIdFilename != null) {
log.warn("Pubmed ID for " + experiment.getShortName() + " was not found in " + this.pubmedIdFilename);
}
ref = finder.locatePrimaryReference(experiment);
if (ref == null) {
log.error("No ref for " + experiment);
failedEe.add(experiment.getShortName());
continue;
}
}
// collect some statistics
if (experiment.getPrimaryPublication() == null) {
nullPubCount.add(experiment.getShortName());
} else if (experiment.getPrimaryPublication().getPubAccession().getAccession().equals(pubmedIds.get(experiment.getShortName()).toString())) {
samePubCount.add(experiment.getShortName());
} else {
diffPubCount.add(experiment.getShortName());
}
try {
log.info("Found pubAccession " + ref.getPubAccession().getAccession() + " for " + experiment);
ref = (BibliographicReference) ph.persist(ref);
experiment.setPrimaryPublication(ref);
ees.update(experiment);
} catch (Exception e) {
log.error(experiment.getShortName() + " (id=" + experiment.getId() + ") update failed.");
e.printStackTrace();
}
}
// print statistics
log.info("\n\n========== Summary ==========");
log.info("Total number of experiments: " + expressionExperiments.size());
log.info("Same publication: " + samePubCount.size());
log.info("Diff publication: " + diffPubCount.size());
log.info("No initial publication: " + nullPubCount.size());
log.info("No publications found: " + failedEe.size());
log.info("\n\n========== Details ==========");
log.info("Diff publication: " + Arrays.toString(diffPubCount.toArray()));
log.info("No initial publication: " + Arrays.toString(nullPubCount.toArray()));
log.info("No publications found: " + Arrays.toString(failedEe.toArray()));
return null;
}
use of ubic.gemma.model.common.description.BibliographicReference in project Gemma by PavlidisLab.
the class GeneralSearchControllerImpl method fillValueObjects.
@SuppressWarnings("unchecked")
private void fillValueObjects(Class<?> entityClass, List<SearchResult> results, SearchSettings settings) {
StopWatch timer = new StopWatch();
timer.start();
Collection<?> vos;
if (ExpressionExperiment.class.isAssignableFrom(entityClass)) {
vos = this.filterEE(expressionExperimentService.loadValueObjects(EntityUtils.getIds(results), false), settings);
if (!SecurityUtil.isUserAdmin()) {
auditableUtil.removeTroubledEes((Collection<ExpressionExperimentValueObject>) vos);
}
} else if (ArrayDesign.class.isAssignableFrom(entityClass)) {
vos = this.filterAD(arrayDesignService.loadValueObjectsByIds(EntityUtils.getIds(results)), settings);
if (!SecurityUtil.isUserAdmin()) {
auditableUtil.removeTroubledArrayDesigns((Collection<ArrayDesignValueObject>) vos);
}
} else if (CompositeSequence.class.isAssignableFrom(entityClass)) {
Collection<CompositeSequenceValueObject> css = new ArrayList<>();
for (SearchResult sr : results) {
CompositeSequenceValueObject csvo = compositeSequenceService.loadValueObject((CompositeSequence) sr.getResultObject());
css.add(csvo);
}
vos = css;
} else if (BibliographicReference.class.isAssignableFrom(entityClass)) {
Collection<BibliographicReference> bss = bibliographicReferenceService.load(EntityUtils.getIds(results));
bss = bibliographicReferenceService.thaw(bss);
vos = bibliographicReferenceService.loadValueObjects(bss);
} else if (Gene.class.isAssignableFrom(entityClass)) {
Collection<Gene> genes = geneService.load(EntityUtils.getIds(results));
genes = geneService.thawLite(genes);
vos = geneService.loadValueObjects(genes);
} else if (Characteristic.class.isAssignableFrom(entityClass)) {
Collection<CharacteristicValueObject> cvos = new ArrayList<>();
for (SearchResult sr : results) {
Characteristic ch = (Characteristic) sr.getResultObject();
cvos.add(new CharacteristicValueObject(ch));
}
vos = cvos;
} else if (CharacteristicValueObject.class.isAssignableFrom(entityClass)) {
Collection<CharacteristicValueObject> cvos = new ArrayList<>();
for (SearchResult sr : results) {
CharacteristicValueObject ch = (CharacteristicValueObject) sr.getResultObject();
cvos.add(ch);
}
vos = cvos;
} else if (BioSequenceValueObject.class.isAssignableFrom(entityClass)) {
return;
} else if (GeneSet.class.isAssignableFrom(entityClass)) {
vos = geneSetService.getValueObjects(EntityUtils.getIds(results));
} else if (ExpressionExperimentSet.class.isAssignableFrom(entityClass)) {
vos = experimentSetService.loadValueObjects(experimentSetService.load(EntityUtils.getIds(results)));
} else if (FactorValue.class.isAssignableFrom(entityClass)) {
Collection<FactorValueValueObject> fvo = new ArrayList<>();
for (SearchResult sr : results) {
fvo.add(new FactorValueValueObject((FactorValue) sr.getResultObject()));
}
vos = fvo;
} else {
throw new UnsupportedOperationException("Don't know how to make value objects for class=" + entityClass);
}
if (vos == null || vos.isEmpty()) {
// it causing front end errors, if vos is empty make sure to get rid of all search results
for (Iterator<SearchResult> it = results.iterator(); it.hasNext(); ) {
it.next();
it.remove();
}
return;
}
// retained objects...
Map<Long, Object> idMap = EntityUtils.getIdMap(vos);
for (Iterator<SearchResult> it = results.iterator(); it.hasNext(); ) {
SearchResult sr = it.next();
if (!idMap.containsKey(sr.getId())) {
it.remove();
continue;
}
sr.setResultObject(idMap.get(sr.getId()));
}
if (timer.getTime() > 1000) {
BaseFormController.log.info("Value object conversion after search: " + timer.getTime() + "ms");
}
}
use of ubic.gemma.model.common.description.BibliographicReference in project Gemma by PavlidisLab.
the class BibliographicReferenceControllerImpl method add.
@Override
public ModelAndView add(HttpServletRequest request, HttpServletResponse response) {
// FIXME: allow use of the primary key as well.
String pubMedId = request.getParameter("accession");
if (StringUtils.isBlank(pubMedId)) {
throw new EntityNotFoundException("Must provide a PubMed Id");
}
BibliographicReference bibRef = bibliographicReferenceService.findByExternalId(pubMedId);
BibliographicReferenceValueObject vo;
if (bibRef == null) {
bibRef = this.pubMedXmlFetcher.retrieveByHTTP(Integer.parseInt(pubMedId));
if (bibRef == null) {
throw new EntityNotFoundException("Could not locate reference with pubmed id=" + pubMedId);
}
vo = new BibliographicReferenceValueObject((BibliographicReference) persisterHelper.persist(bibRef));
this.saveMessage(request, "Added " + pubMedId + " to the system.");
} else if (StringUtils.isNotBlank(request.getParameter("refresh"))) {
vo = this.update(pubMedId);
this.saveMessage(request, "Updated record for pubmed id " + pubMedId);
} else {
throw new IllegalArgumentException("Action not understood");
}
return new ModelAndView("bibRefView").addObject("bibliographicReferenceId", vo.getId()).addObject("existsInSystem", Boolean.TRUE).addObject("bibliographicReference", vo);
}
use of ubic.gemma.model.common.description.BibliographicReference in project Gemma by PavlidisLab.
the class BibliographicReferenceControllerImpl method showAllForExperiments.
@Override
public ModelAndView showAllForExperiments(HttpServletRequest request, HttpServletResponse response) {
Map<ExpressionExperiment, BibliographicReference> eeToBibRefs = bibliographicReferenceService.getAllExperimentLinkedReferences();
// map sorted in natural order of the keys
SortedMap<CitationValueObject, Collection<ExpressionExperimentValueObject>> citationToEEs = new TreeMap<>();
for (Entry<ExpressionExperiment, BibliographicReference> entry : eeToBibRefs.entrySet()) {
if (entry.getValue().getTitle() == null || entry.getValue().getTitle().isEmpty() || entry.getValue().getAuthorList() == null || entry.getValue().getAuthorList().isEmpty()) {
continue;
}
CitationValueObject cvo = CitationValueObject.convert2CitationValueObject(entry.getValue());
if (!citationToEEs.containsKey(cvo)) {
citationToEEs.put(cvo, new ArrayList<ExpressionExperimentValueObject>());
}
ExpressionExperiment ee = entry.getKey();
ee.setBioAssays(null);
ee.setAccession(null);
ee.setExperimentalDesign(null);
citationToEEs.get(cvo).add(new ExpressionExperimentValueObject(ee));
}
return new ModelAndView("bibRefAllExperiments").addObject("citationToEEs", citationToEEs);
}
use of ubic.gemma.model.common.description.BibliographicReference in project Gemma by PavlidisLab.
the class BibliographicReferenceControllerImpl method browse.
@Override
public JsonReaderResponse<BibliographicReferenceValueObject> browse(ListBatchCommand batch) {
Integer count = this.bibliographicReferenceService.countAll();
List<BibliographicReference> records = this.getBatch(batch);
Map<BibliographicReference, Collection<ExpressionExperiment>> relatedExperiments = this.bibliographicReferenceService.getRelatedExperiments(records);
List<BibliographicReferenceValueObject> valueObjects = new ArrayList<>();
for (BibliographicReference ref : records) {
ref = this.bibliographicReferenceService.thaw(ref);
BibliographicReferenceValueObject vo = new BibliographicReferenceValueObject(ref);
if (relatedExperiments.containsKey(ref)) {
vo.setExperiments(expressionExperimentService.loadValueObjects(relatedExperiments.get(ref)));
}
valueObjects.add(vo);
// adding phenotype information to the Bibliographic Reference
Collection<PhenotypeAssociation> phenotypeAssociations = this.phenotypeAssociationService.findPhenotypesForBibliographicReference(vo.getPubAccession());
Collection<BibliographicPhenotypesValueObject> bibliographicPhenotypesValueObjects = BibliographicPhenotypesValueObject.phenotypeAssociations2BibliographicPhenotypesValueObjects(phenotypeAssociations);
vo.setBibliographicPhenotypes(bibliographicPhenotypesValueObjects);
}
return new JsonReaderResponse<>(valueObjects, count);
}
Aggregations