Search in sources :

Example 1 with GenomeBrowserTrack

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());
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) PluginController(org.molgenis.web.PluginController) URLDecoder(java.net.URLDecoder) MenuReaderService(org.molgenis.core.ui.menu.MenuReaderService) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) AnnotationJobExecutionMetaData(org.molgenis.data.annotation.web.meta.AnnotationJobExecutionMetaData) NegotiatorController(org.molgenis.dataexplorer.negotiator.NegotiatorController) JobExecutionMetaData(org.molgenis.jobs.model.JobExecutionMetaData) Model(org.springframework.ui.Model) JSONObject(org.json.JSONObject) Gson(com.google.gson.Gson) DataExplorerDownloadHandler(org.molgenis.dataexplorer.download.DataExplorerDownloadHandler) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) AttributeFactory(org.molgenis.data.meta.model.AttributeFactory) org.molgenis.data(org.molgenis.data) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack) EntityTypeUtils(org.molgenis.data.support.EntityTypeUtils) EntityType(org.molgenis.data.meta.model.EntityType) Collectors(java.util.stream.Collectors) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) UserPermissionEvaluator(org.molgenis.security.core.UserPermissionEvaluator) ParseException(freemarker.core.ParseException) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) Permission(org.molgenis.security.core.Permission) java.util(java.util) LocalDateTime(java.time.LocalDateTime) QueryImpl(org.molgenis.data.support.QueryImpl) Controller(org.springframework.stereotype.Controller) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) Function(java.util.function.Function) AppSettings(org.molgenis.settings.AppSettings) DownloadType(org.molgenis.dataexplorer.controller.DataRequest.DownloadType) ServletOutputStream(javax.servlet.ServletOutputStream) EntityUtils.getTypedValue(org.molgenis.data.util.EntityUtils.getTypedValue) URI(org.molgenis.dataexplorer.controller.DataExplorerController.URI) MessageSource(org.springframework.context.MessageSource) Logger(org.slf4j.Logger) READ(org.molgenis.security.core.Permission.READ) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) GenomeBrowserService(org.molgenis.genomebrowser.service.GenomeBrowserService) SecurityUtils(org.molgenis.security.core.utils.SecurityUtils) WRITE(org.molgenis.security.core.Permission.WRITE) DateTimeFormatter(java.time.format.DateTimeFormatter) ANNOTATION_JOB_EXECUTION(org.molgenis.data.annotation.web.meta.AnnotationJobExecutionMetaData.ANNOTATION_JOB_EXECUTION) Package(org.molgenis.data.meta.model.Package) DataExplorerSettings(org.molgenis.dataexplorer.settings.DataExplorerSettings) DOWNLOAD_TYPE_CSV(org.molgenis.dataexplorer.controller.DataRequest.DownloadType.DOWNLOAD_TYPE_CSV) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack)

Example 2 with GenomeBrowserTrack

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;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack)

Example 3 with GenomeBrowserTrack

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;
}
Also used : GenomeBrowserAttributes(org.molgenis.genomebrowser.meta.GenomeBrowserAttributes) HashMap(java.util.HashMap) GenomeBrowserSettings(org.molgenis.genomebrowser.meta.GenomeBrowserSettings) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack)

Example 4 with GenomeBrowserTrack

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) GenomeBrowserAttributes(org.molgenis.genomebrowser.meta.GenomeBrowserAttributes) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack) Test(org.testng.annotations.Test)

Example 5 with GenomeBrowserTrack

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();
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) GenomeBrowserAttributes(org.molgenis.genomebrowser.meta.GenomeBrowserAttributes) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack) Test(org.testng.annotations.Test)

Aggregations

GenomeBrowserTrack (org.molgenis.genomebrowser.GenomeBrowserTrack)6 EntityType (org.molgenis.data.meta.model.EntityType)5 GenomeBrowserAttributes (org.molgenis.genomebrowser.meta.GenomeBrowserAttributes)4 Test (org.testng.annotations.Test)3 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)2 QueryImpl (org.molgenis.data.support.QueryImpl)2 Gson (com.google.gson.Gson)1 ParseException (freemarker.core.ParseException)1 IOException (java.io.IOException)1 URLDecoder (java.net.URLDecoder)1 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 java.util (java.util)1 HashMap (java.util.HashMap)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 StringUtils (org.apache.commons.lang3.StringUtils)1 JSONObject (org.json.JSONObject)1