Skip to content

Commit

Permalink
fixes #2414
Browse files Browse the repository at this point in the history
  • Loading branch information
nathandunn committed Apr 30, 2020
1 parent 28cb629 commit cc1650f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 60 deletions.
1 change: 1 addition & 0 deletions grails-app/conf/Config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
131 changes: 71 additions & 60 deletions grails-app/services/org/bbop/apollo/AnnotatorService.groovy
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) {
Expand All @@ -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
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit cc1650f

Please sign in to comment.