use of org.molgenis.genomebrowser.GenomeBrowserTrack in project molgenis by molgenis.
the class DataExplorerController method getTracksJson.
/**
* Get readable genome entities
*/
private List<JSONObject> getTracksJson(Map<String, GenomeBrowserTrack> entityTracks) {
Map<String, GenomeBrowserTrack> allTracks = new HashMap<>();
allTracks.putAll(entityTracks);
for (GenomeBrowserTrack track : entityTracks.values()) {
allTracks.putAll(genomeBrowserService.getReferenceTracks(track));
}
return allTracks.values().stream().map(track -> track.toTrackJson()).collect(Collectors.toList());
}
use of org.molgenis.genomebrowser.GenomeBrowserTrack in project molgenis by molgenis.
the class DataExplorerController method getModule.
@GetMapping("/module/{moduleId}")
public String getModule(@PathVariable("moduleId") String moduleId, @RequestParam("entity") String entityTypeId, Model model) {
EntityType selectedEntityType;
Map<String, GenomeBrowserTrack> entityTracks;
switch(moduleId) {
case MOD_DATA:
selectedEntityType = dataService.getMeta().getEntityTypeById(entityTypeId);
entityTracks = genomeBrowserService.getGenomeBrowserTracks(selectedEntityType);
model.addAttribute("genomeTracks", getTracksJson(entityTracks));
// if multiple tracks are available we assume chrom and pos attribute are the same
if (!entityTracks.isEmpty()) {
// FIXME: how to do this cleaner
GenomeBrowserTrack track = entityTracks.entrySet().iterator().next().getValue();
model.addAttribute("pos_attr", track.getGenomeBrowserAttrs().getPos());
model.addAttribute("chrom_attr", track.getGenomeBrowserAttrs().getChrom());
}
model.addAttribute("showDirectoryButton", directoryController.showDirectoryButton(entityTypeId));
model.addAttribute("NegotiatorEnabled", directoryController.showDirectoryButton(entityTypeId));
break;
case MOD_ENTITIESREPORT:
// TODO: figure out if we need to know pos and chrom attrs here
selectedEntityType = dataService.getMeta().getEntityTypeById(entityTypeId);
entityTracks = genomeBrowserService.getGenomeBrowserTracks(selectedEntityType);
model.addAttribute("genomeTracks", getTracksJson(entityTracks));
model.addAttribute("showDirectoryButton", directoryController.showDirectoryButton(entityTypeId));
model.addAttribute("NegotiatorEnabled", directoryController.showDirectoryButton(entityTypeId));
model.addAttribute("datasetRepository", dataService.getRepository(entityTypeId));
model.addAttribute("viewName", dataExplorerSettings.getEntityReport(entityTypeId));
break;
case MOD_ANNOTATORS:
// self-explanatory
if (!permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.WRITEMETA)) {
throw new MolgenisDataAccessException("No " + Permission.WRITEMETA + " permission on entity [" + entityTypeId + "], this permission is necessary run the annotators.");
}
Entity annotationRun = dataService.findOne(ANNOTATION_JOB_EXECUTION, new QueryImpl<>().eq(AnnotationJobExecutionMetaData.TARGET_NAME, entityTypeId).sort(new Sort(JobExecutionMetaData.START_DATE, Sort.Direction.DESC)));
model.addAttribute("annotationRun", annotationRun);
model.addAttribute("entityTypeId", entityTypeId);
break;
}
// TODO bad request in case of invalid module id
return "view-dataexplorer-mod-" + moduleId;
}
use of org.molgenis.genomebrowser.GenomeBrowserTrack in project molgenis by molgenis.
the class GenomeBrowserService method getGenomeBrowserTracks.
public Map<String, GenomeBrowserTrack> getGenomeBrowserTracks(EntityType entityType, List<GenomeBrowserAttributes> defaultGenomeBrowserAttributes) {
Map<String, GenomeBrowserTrack> settings = new HashMap<>();
dataService.findAll(GENOMEBROWSERSETTINGS, new QueryImpl<GenomeBrowserSettings>().eq(GenomeBrowserSettingsMetadata.ENTITY, entityType.getIdValue()), GenomeBrowserSettings.class).forEach(referenceSettings -> settings.put(referenceSettings.getIdentifier(), GenomeBrowserTrack.create(referenceSettings)));
if (settings.isEmpty()) {
// if not check if attrs match any default config
Collections.sort(defaultGenomeBrowserAttributes);
for (GenomeBrowserAttributes genomeBrowserAttributes : defaultGenomeBrowserAttributes) {
List<String> attributeNames = Lists.newArrayList(entityType.getAttributeNames());
if (areAllAttributeAvailable(genomeBrowserAttributes, attributeNames)) {
GenomeBrowserTrack genomeBrowserTrack = getDefaultGenomeBrowserSettingsEntity(entityType, genomeBrowserAttributes);
settings.put(genomeBrowserTrack.getId(), genomeBrowserTrack);
break;
}
}
}
return settings;
}
use of org.molgenis.genomebrowser.GenomeBrowserTrack in project molgenis by molgenis.
the class GenomeBrowserServiceTest method testGetReferenceTracks.
@Test
public void testGetReferenceTracks() {
EntityType entity = mock(EntityType.class);
when(entity.getLabel()).thenReturn("label");
GenomeBrowserAttributes genomeBrowserAttributes = getGenomeBrowserAttributes("postion", "chrom", "normal", "mutant");
GenomeBrowserTrack reference = GenomeBrowserTrack.create("ref_id", "label", "ref_label", entity, GenomeBrowserSettings.TrackType.VARIANT, null, GenomeBrowserSettings.MolgenisReferenceMode.ALL, genomeBrowserAttributes, null, null, null, null);
EntityType molgenisEntity = mock(EntityType.class);
GenomeBrowserTrack track = GenomeBrowserTrack.create("id", "label", "entityLabel", molgenisEntity, GenomeBrowserSettings.TrackType.VARIANT, Collections.singletonList(reference), GenomeBrowserSettings.MolgenisReferenceMode.CONFIGURED, genomeBrowserAttributes, "alert(\"test\")", "attr 1:attr1,reference attribute:REF,position on genome:POS", null, null);
Map<String, GenomeBrowserTrack> result = genomeBrowserService.getReferenceTracks(track);
assertEquals(result.size(), 1);
assertEquals(result.get("ref_id"), reference);
}
use of org.molgenis.genomebrowser.GenomeBrowserTrack in project molgenis by molgenis.
the class GenomeBrowserServiceTest method testGetReferenceTracksNone.
@Test
public void testGetReferenceTracksNone() {
EntityType entity = mock(EntityType.class);
when(entity.getLabel()).thenReturn("label");
GenomeBrowserAttributes genomeBrowserAttributes = getGenomeBrowserAttributes("postion", "chrom", "normal", "mutant");
GenomeBrowserTrack reference = GenomeBrowserTrack.create("ref_id", "label", "ref_label", entity, GenomeBrowserSettings.TrackType.VARIANT, null, GenomeBrowserSettings.MolgenisReferenceMode.NONE, genomeBrowserAttributes, null, null, null, null);
EntityType molgenisEntity = mock(EntityType.class);
GenomeBrowserTrack track = GenomeBrowserTrack.create("id", "label", "entityLabel", molgenisEntity, GenomeBrowserSettings.TrackType.VARIANT, Collections.singletonList(reference), GenomeBrowserSettings.MolgenisReferenceMode.NONE, genomeBrowserAttributes, "alert(\"test\")", "attr 1:attr1,reference attribute:REF,position on genome:POS", null, null);
Map<String, GenomeBrowserTrack> result = genomeBrowserService.getReferenceTracks(track);
assertEquals(result.size(), 0);
verify(dataService, never()).getMeta();
}
Aggregations