use of gov.nih.nci.ctd2.dashboard.dao.DashboardDao in project nci-ctd2-dashboard by CBIIT.
the class BrowseAPI method getSubmission.
@Transactional
@RequestMapping(value = "{subjectClass}/{subjectName}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getSubmission(@PathVariable String subjectClass, @PathVariable String subjectName, @RequestParam(value = "center", required = false, defaultValue = "") String center, @RequestParam(value = "role", required = false, defaultValue = "") String role, @RequestParam(value = "tier", required = false, defaultValue = "") String tiers, @RequestParam(value = "maximum", required = false, defaultValue = "") String maximum) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
SubjectResponse.Filter filter = SubjectResponse.createFilter(center, role, tiers, maximum);
DashboardEntity subject = null;
if (subjectClass.equalsIgnoreCase("evidence") || subjectClass.equalsIgnoreCase("eco")) {
/* API spec asks for Evidence but stable URL uses eco */
var obj = dashboardDao.getEntityByStableURL("eco", "eco/" + subjectName);
if (obj instanceof ECOTerm) {
subject = (ECOTerm) obj;
} else {
log.error("unexpected subject type:" + obj.getClass().getName());
}
} else if (subjectClass.equalsIgnoreCase("gene")) {
List<Gene> genes = dashboardDao.findGenesBySymbol(subjectName);
if (genes.size() > 0) {
Gene gene = genes.get(0);
List<Protein> p = dashboardDao.findProteinByGene(gene);
Xref xref = new XrefImpl();
xref.setDatabaseId(p.get(0).getUniprotId());
xref.setDatabaseName("UniProt");
gene.getXrefs().add(xref);
subject = gene;
}
} else {
var obj = dashboardDao.getEntityByStableURL(subjectClass, subjectClass + "/" + subjectName);
if (obj instanceof Subject) {
subject = (Subject) obj;
} else {
log.error("unexpected subject type: " + (obj == null ? null : obj.getClass().getName()));
}
}
if (subject == null) {
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
SubjectResponse subjectResponse = SubjectResponse.createInstance(subject, filter, dashboardDao);
log.debug("ready to serialize");
JSONSerializer jsonSerializer = CTD2Serializer.createJSONSerializer();
String json = "{}";
try {
json = jsonSerializer.deepSerialize(subjectResponse);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
return new ResponseEntity<String>(json, headers, HttpStatus.OK);
}
use of gov.nih.nci.ctd2.dashboard.dao.DashboardDao in project nci-ctd2-dashboard by CBIIT.
the class SubjectResponse method createInstance.
private static SubjectResponse createInstance(final Subject subject, final Filter filter, DashboardDao dashboardDao) {
int[] tierCount = new int[3];
Set<Integer> set = new HashSet<Integer>();
for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectBySubject(subject)) {
ObservedSubjectRole observedSubjectRole = observedSubject.getObservedSubjectRole();
String subjectRole = observedSubjectRole.getSubjectRole().getDisplayName();
if (filter.rolesIncluded.size() > 0 && !filter.rolesIncluded.contains(subjectRole))
continue;
ObservationTemplate observatinoTemplate = observedSubject.getObservation().getSubmission().getObservationTemplate();
Integer observationTier = observatinoTemplate.getTier();
String centerNameBrief = observatinoTemplate.getSubmissionCenter().getStableURL().substring(7);
if (filter.centerIncluded.size() > 0 && !filter.centerIncluded.contains(centerNameBrief))
continue;
if ((Arrays.asList(filter.tiersIncluded).contains(observationTier))) {
set.add(observedSubject.getObservation().getId());
tierCount[observationTier.intValue() - 1]++;
if (filter.limit > 0 && set.size() >= filter.limit) {
break;
}
}
}
List<ObservationItem> observations = dashboardDao.findObservationInfo(new ArrayList<Integer>(set));
Set<String> roles = new TreeSet<String>();
for (int i = 0; i < observations.size(); i++) {
for (SubjectItem sub : observations.get(i).subject_list) {
if (sub.getName().equals(subject.getDisplayName())) {
roles.add(sub.getRole());
break;
}
}
}
String[] uris = observations.stream().map(x -> x.uri).toArray(String[]::new);
SubjectResponse subjectResponse = new SubjectResponse(subject, uris, roles.toArray(new String[0]), tierCount);
return subjectResponse;
}
use of gov.nih.nci.ctd2.dashboard.dao.DashboardDao in project nci-ctd2-dashboard by CBIIT.
the class SearchAPI method getSubmission.
@Transactional
@RequestMapping(value = "{term}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getSubmission(@PathVariable String term, @RequestParam(value = "center", required = false, defaultValue = "") String center, @RequestParam(value = "role", required = false, defaultValue = "") String role, @RequestParam(value = "tier", required = false, defaultValue = "") String tiers, @RequestParam(value = "maximum", required = false, defaultValue = "") String maximum) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
SubjectResponse.Filter filter = SubjectResponse.createFilter(center, role, tiers, maximum);
List<SubjectResponse> allSubjects = new ArrayList<SubjectResponse>();
List<SubjectResult> results = dashboardDao.search(term.toLowerCase()).subject_result;
for (SubjectResult subjectResult : results) {
try {
Class<? extends DashboardEntity> clazz = Class.forName("gov.nih.nci.ctd2.dashboard.model." + subjectResult.className).asSubclass(DashboardEntity.class);
;
DashboardEntity result = dashboardDao.getEntityById(clazz, subjectResult.id);
SubjectResponse subjectResponse = SubjectResponse.createInstance(result, filter, dashboardDao);
if (subjectResponse == null) {
continue;
}
allSubjects.add(subjectResponse);
} catch (ClassNotFoundException e) {
e.printStackTrace();
continue;
}
}
log.debug("ready to serialize");
JSONSerializer jsonSerializer = CTD2Serializer.createJSONSerializer();
String json = "{}";
try {
json = jsonSerializer.deepSerialize(allSubjects);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
return new ResponseEntity<String>(json, headers, HttpStatus.OK);
}
use of gov.nih.nci.ctd2.dashboard.dao.DashboardDao in project nci-ctd2-dashboard by CBIIT.
the class SampleImporter method run.
@Override
public void run() {
DashboardFactory dashboardFactory = getDashboardFactory();
DashboardDao dashboardDao = getDashboardDao();
Synonym synonym = dashboardFactory.create(Synonym.class);
synonym.setDisplayName("S1");
Synonym synonym2 = dashboardFactory.create(Synonym.class);
synonym.setDisplayName("S2");
Synonym synonym3 = dashboardFactory.create(Synonym.class);
synonym3.setDisplayName("S3");
// Save with id
Gene gene = dashboardFactory.create(Gene.class);
gene.setDisplayName("G1");
gene.setEntrezGeneId("E1");
gene.getSynonyms().add(synonym);
gene.getSynonyms().add(synonym2);
dashboardDao.save(gene);
// save without id
Gene gene2 = dashboardFactory.create(Gene.class);
gene2.setEntrezGeneId("E2");
gene.setDisplayName("G2");
dashboardDao.save(gene2);
Transcript transcript = dashboardFactory.create(Transcript.class);
transcript.setGene(gene2);
transcript.setRefseqId("NM_21431");
gene.setDisplayName("T1");
dashboardDao.save(transcript);
Protein protein = dashboardFactory.create(Protein.class);
protein.getTranscripts().add(transcript);
protein.setUniprotId("1000");
protein.setDisplayName("P1");
dashboardDao.save(protein);
AnimalModel animalModel = dashboardFactory.create(AnimalModel.class);
animalModel.getSynonyms().add(synonym3);
animalModel.setDisplayName("MM1");
dashboardDao.save(animalModel);
UrlEvidence urlEvidence = dashboardFactory.create(UrlEvidence.class);
urlEvidence.setUrl("http://ctd2.nci.nih.gov/");
LabelEvidence labelEvidence = dashboardFactory.create(LabelEvidence.class);
labelEvidence.setDisplayName("L1");
log.info("Imported " + dashboardDao.findEntities(DashboardEntity.class).size() + " entities.");
}
use of gov.nih.nci.ctd2.dashboard.dao.DashboardDao in project nci-ctd2-dashboard by CBIIT.
the class DashboardAdminMain method main.
@Transactional
public static void main(String[] args) {
final CommandLineParser parser = new GnuParser();
Options gnuOptions = new Options();
gnuOptions.addOption("h", "help", false, "shows this help document and quits.").addOption("am", "animal-model-data", false, "imports animal model data.").addOption("cl", "cell-line-data", false, "imports cell line data.").addOption("cp", "compound-data", false, "imports compound data.").addOption("e", "eco-term", false, "import ECO terms.").addOption("g", "gene-data", false, "imports gene data.").addOption("p", "protein-data", false, "imports protein data.").addOption("r", "rank-subjects", false, "prioritize and rank the subjects according to the observation data.").addOption("sh", "shrna-data", false, "imports shrna data.").addOption("si", "sirna-data", false, "imports sirna data.").addOption("ts", "tissue-sample-data", false, "imports tissue sample data.").addOption("cv", "controlled-vocabulary", false, "imports the dashboard controlled vocabulary.").addOption("o", "observation-data", false, "imports dashboard observation data.").addOption("s", "sample-data", false, "imports sample data.").addOption("t", "taxonomy-data", false, "imports organism data.").addOption("i", "index", false, "creates lucene index.");
// Here goes the parsing attempt
try {
CommandLine commandLine = parser.parse(gnuOptions, args);
if (commandLine.getOptions().length == 0) {
// Here goes help message about running admin
throw new ParseException("Nothing to do!");
}
if (commandLine.hasOption("h")) {
printHelpAndExit(gnuOptions, 0);
}
if (commandLine.hasOption("am")) {
launchJob("animalModelImporterJob");
}
if (commandLine.hasOption("cl")) {
launchJob("cellLineDataImporterJob");
}
if (commandLine.hasOption("cp")) {
launchJob("compoundDataImporterJob");
}
if (commandLine.hasOption("g")) {
launchJob("geneDataImporterJob");
}
if (commandLine.hasOption("p")) {
launchJob("proteinDataImporterJob");
}
if (commandLine.hasOption("sh")) {
launchJob("TRCshRNADataImporterJob");
}
if (commandLine.hasOption("si")) {
launchJob("siRNADataImporterJob");
}
if (commandLine.hasOption("ts")) {
launchJob("tissueSampleDataImporterJob");
}
if (commandLine.hasOption("cv")) {
launchJob("controlledVocabularyImporterJob");
}
if (commandLine.hasOption("o")) {
launchJob("observationDataImporterJob");
String dataURL = (String) appContext.getBean("dataURL");
APIDataBuilder b = (APIDataBuilder) appContext.getBean("apiDataBuilder");
b.prepareData(dataURL);
}
if (commandLine.hasOption("s")) {
log.info("Running sample importer...");
// This is just for demonstration purposes
SampleImporter sampleImporter = (SampleImporter) appContext.getBean("sampleImporter");
sampleImporter.run();
}
if (commandLine.hasOption("t")) {
launchJob("taxonomyDataImporterJob");
}
if (commandLine.hasOption("e")) {
launchJob("ecotermDataImporterJob");
}
if (commandLine.hasOption("r")) {
SubjectScorer subjectScorer = (SubjectScorer) appContext.getBean("subjectScorer");
subjectScorer.scoreAllRoles();
OverallSummary overallSummary = (OverallSummary) appContext.getBean("overallSummary");
overallSummary.summarize();
}
if (commandLine.hasOption("i")) {
DashboardDao dashboardDao = (DashboardDao) appContext.getBean("dashboardDao");
dashboardDao.cleanIndex((Integer) appContext.getBean("indexBatchSize"));
}
log.info("All done.");
System.exit(0);
} catch (ParseException e) {
System.err.println(e.getMessage());
printHelpAndExit(gnuOptions, -1);
}
}
Aggregations