From cc1650fa9e3f120b05b4e84be5fd795f78094318 Mon Sep 17 00:00:00 2001 From: Nathan Dunn Date: Thu, 30 Apr 2020 16:51:04 -0700 Subject: [PATCH] fixes #2414 --- grails-app/conf/Config.groovy | 1 + .../org/bbop/apollo/AnnotatorService.groovy | 131 ++++++++++-------- .../bbop/apollo/ConfigWrapperService.groovy | 4 + 3 files changed, 76 insertions(+), 60 deletions(-) diff --git a/grails-app/conf/Config.groovy b/grails-app/conf/Config.groovy index b75633e8d5..5e76b27ba5 100644 --- a/grails-app/conf/Config.groovy +++ b/grails-app/conf/Config.groovy @@ -204,6 +204,7 @@ apollo { overlapper_class = "org.bbop.apollo.sequence.OrfOverlapper" track_name_comparator = "/config/track_name_comparator.js" use_cds_for_new_transcripts = false + count_annotations = true transcript_overlapper = "CDS" feature_has_dbxrefs = true feature_has_attributes = true diff --git a/grails-app/services/org/bbop/apollo/AnnotatorService.groovy b/grails-app/services/org/bbop/apollo/AnnotatorService.groovy index 6091af5379..b6052c6728 100644 --- a/grails-app/services/org/bbop/apollo/AnnotatorService.groovy +++ b/grails-app/services/org/bbop/apollo/AnnotatorService.groovy @@ -1,6 +1,6 @@ package org.bbop.apollo -import grails.converters.JSON + import grails.transaction.Transactional import org.bbop.apollo.gwt.shared.FeatureStringEnum import org.bbop.apollo.gwt.shared.PermissionEnum @@ -19,10 +19,13 @@ class AnnotatorService { def trackService def variantService - Integer getAnnotationCount(Organism organism){ - def viewableTypes = requestHandlingService.viewableAnnotationList + requestHandlingService.viewableSequenceAlterationList - def results = Feature.executeQuery(" select count(f) from Feature f join f.featureLocations fl join fl.sequence s join s.organism o where o = :organism and f.class in :viewableTypes ",[organism:organism,viewableTypes: viewableTypes]) - return results[0] as Integer + Integer getAnnotationCount(Organism organism) { + if(configWrapperService.getCountAnnotations()){ + def viewableTypes = requestHandlingService.viewableAnnotationList + requestHandlingService.viewableSequenceAlterationList + def results = Feature.executeQuery(" select count(f) from Feature f join f.featureLocations fl join fl.sequence s join s.organism o where o = :organism and f.class in :viewableTypes ",[organism:organism,viewableTypes: viewableTypes]) + return results[0] as Integer + } + return 0 } def getAppState(String token) { @@ -40,75 +43,83 @@ class AnnotatorService { Sequence.executeQuery("select o,count(s) from Organism o join o.sequences s where o in (:organismList) group by o ", [organismList: organismList]).each() { sequenceIntegerMap.put(it[0], it[1]) } - Feature.executeQuery("select o,count(distinct f) from Feature f left join f.parentFeatureRelationships pfr join f.featureLocations fl join fl.sequence s join s.organism o where f.childFeatureRelationships is empty and o in (:organismList) and f.class in (:viewableTypes) group by o", [organismList: organismList, viewableTypes: requestHandlingService.viewableAnnotationList]).each { - annotationCountMap.put(it[0], it[1]) + if (configWrapperService.getCountAnnotations()) { + Feature.executeQuery("select o,count(distinct f) from Feature f left join f.parentFeatureRelationships pfr join f.featureLocations fl join fl.sequence s join s.organism o where f.childFeatureRelationships is empty and o in (:organismList) and f.class in (:viewableTypes) group by o", [organismList: organismList, viewableTypes: requestHandlingService.viewableAnnotationList]).each { + annotationCountMap.put(it[0], it[1]) + } + } else { + for (o in organismList) { + annotationCountMap.put(o, 0) + } } } - - JSONArray organismArray = new JSONArray() - for (Organism organism in organismList.findAll()) { - Integer sequenceCount = sequenceIntegerMap.get(organism) ?: 0 - JSONObject jsonObject = [ - id : organism.id as Long, - commonName : organism.commonName, - blatdb : organism.blatdb, - directory : organism.directory, - annotationCount : annotationCountMap.get(organism) ?: 0, - sequences : sequenceCount, - genus : organism.genus, - species : organism.species, - valid : organism.valid, - publicMode : organism.publicMode, - obsolete : organism.obsolete, - nonDefaultTranslationTable: organism.nonDefaultTranslationTable, - currentOrganism : defaultOrganismId != null ? organism.id == defaultOrganismId : false, - editable : organismBooleanMap.get(organism) ?: false, - officialGeneSetTrack : organism.officialGeneSetTrack - - ] as JSONObject - organismArray.add(jsonObject) + JSONArray organismArray = new JSONArray() + for (Organism organism in organismList.findAll()) { + Integer sequenceCount = sequenceIntegerMap.get(organism) ?: 0 + JSONObject jsonObject = [ + id : organism.id as Long, + commonName : organism.commonName, + blatdb : organism.blatdb, + directory : organism.directory, + annotationCount : annotationCountMap.get(organism) ?: 0, + sequences : sequenceCount, + genus : organism.genus, + species : organism.species, + valid : organism.valid, + publicMode : organism.publicMode, + obsolete : organism.obsolete, + nonDefaultTranslationTable: organism.nonDefaultTranslationTable, + currentOrganism : defaultOrganismId != null ? organism.id == defaultOrganismId : false, + editable : organismBooleanMap.get(organism) ?: false, + officialGeneSetTrack : organism.officialGeneSetTrack + + ] as JSONObject + organismArray.add(jsonObject) + } + appStateObject.put("organismList", organismArray) + UserOrganismPreferenceDTO currentUserOrganismPreferenceDTO = preferenceService.getCurrentOrganismPreference(permissionService.currentUser, null, token) + if (currentUserOrganismPreferenceDTO) { + OrganismDTO currentOrganism = currentUserOrganismPreferenceDTO?.organism + + if (userOrganismPreference?.organism) { + currentOrganism.annotationCount = getAnnotationCount(userOrganismPreference.organism) + currentOrganism.variantEffectCount = variantService.getSequenceAlterationEffectsCountForOrgansim(userOrganismPreference.organism) } - appStateObject.put("organismList", organismArray) - UserOrganismPreferenceDTO currentUserOrganismPreferenceDTO = preferenceService.getCurrentOrganismPreference(permissionService.currentUser, null, token) - if (currentUserOrganismPreferenceDTO) { - OrganismDTO currentOrganism = currentUserOrganismPreferenceDTO?.organism - - if(userOrganismPreference?.organism){ - currentOrganism.annotationCount = getAnnotationCount(userOrganismPreference.organism) - currentOrganism.variantEffectCount = variantService.getSequenceAlterationEffectsCountForOrgansim(userOrganismPreference.organism) - } - Organism organism = Organism.findById(currentOrganism.id) - currentOrganism.officialGeneSetTrack = organism?.officialGeneSetTrack - appStateObject.put("currentOrganism", currentOrganism) + Organism organism = Organism.findById(currentOrganism.id) + currentOrganism.officialGeneSetTrack = organism?.officialGeneSetTrack + appStateObject.put("currentOrganism", currentOrganism) - if (!currentUserOrganismPreferenceDTO.sequence) { - Sequence sequence = Sequence.findByOrganism(organism, [sort: "name", order: "asc", max: 1]) - // often the case when creating it - currentUserOrganismPreferenceDTO.sequence = preferenceService.getDTOFromSequence(sequence) - } - appStateObject.put("currentSequence", currentUserOrganismPreferenceDTO.sequence) + if (!currentUserOrganismPreferenceDTO.sequence) { + Sequence sequence = Sequence.findByOrganism(organism, [sort: "name", order: "asc", max: 1]) + // often the case when creating it + currentUserOrganismPreferenceDTO.sequence = preferenceService.getDTOFromSequence(sequence) + } + appStateObject.put("currentSequence", currentUserOrganismPreferenceDTO.sequence) - if (currentUserOrganismPreferenceDTO.startbp && currentUserOrganismPreferenceDTO.endbp) { - appStateObject.put("currentStartBp", currentUserOrganismPreferenceDTO.startbp) - appStateObject.put("currentEndBp", currentUserOrganismPreferenceDTO.endbp) - } + if (currentUserOrganismPreferenceDTO.startbp && currentUserOrganismPreferenceDTO.endbp) { + appStateObject.put("currentStartBp", currentUserOrganismPreferenceDTO.startbp) + appStateObject.put("currentEndBp", currentUserOrganismPreferenceDTO.endbp) } - appStateObject.put(FeatureStringEnum.COMMON_DATA_DIRECTORY.value,trackService.commonDataDirectory) - } - catch (PermissionException e) { - def error = [error: "Error: " + e] - log.error(error.error) - return error } + appStateObject.put(FeatureStringEnum.COMMON_DATA_DIRECTORY.value, trackService.commonDataDirectory) + } + catch ( + PermissionException e + ) { + def error = [error: "Error: " + e] + log.error(error.error) + return error + } - return appStateObject - } + + return appStateObject +} } diff --git a/grails-app/services/org/bbop/apollo/ConfigWrapperService.groovy b/grails-app/services/org/bbop/apollo/ConfigWrapperService.groovy index b56534ceb3..11ae617dc8 100644 --- a/grails-app/services/org/bbop/apollo/ConfigWrapperService.groovy +++ b/grails-app/services/org/bbop/apollo/ConfigWrapperService.groovy @@ -17,6 +17,10 @@ class ConfigWrapperService { return grailsApplication.config.apollo.use_cds_for_new_transcripts } + Boolean getCountAnnotations(){ + return grailsApplication.config.apollo.count_annotations + } + String getTranscriptOverlapper() { return grailsApplication.config.apollo.transcript_overlapper }