Skip to content

Commit

Permalink
Merge 43ef0f5 into 14732ee
Browse files Browse the repository at this point in the history
  • Loading branch information
nathandunn committed Dec 11, 2019
2 parents 14732ee + 43ef0f5 commit b3ac28a
Show file tree
Hide file tree
Showing 44 changed files with 4,735 additions and 1,696 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class AnnotationEditorController extends AbstractApolloController implements Ann
def annotationEditorService
def organismService
def jsonWebUtilityService
def cannedCommentService
def cannedAttributeService
def availableStatusService
def brokerMessagingTemplate


Expand Down Expand Up @@ -994,6 +997,28 @@ class AnnotationEditorController extends AbstractApolloController implements Ann
render jre as JSON
}

private String getOntologyIdForType(String type){
JSONObject cvTerm = new JSONObject()
if(type.toUpperCase()==Gene.cvTerm.toUpperCase()){
JSONObject cvTermName = new JSONObject()
cvTermName.put(FeatureStringEnum.NAME.value,FeatureStringEnum.CV.value)
cvTerm.put(FeatureStringEnum.CV.value,cvTermName)
cvTerm.put(FeatureStringEnum.NAME.value,type)
}
else{
JSONObject cvTermName = new JSONObject()
cvTermName.put(FeatureStringEnum.NAME.value,FeatureStringEnum.SEQUENCE.value)
cvTerm.put(FeatureStringEnum.CV.value,cvTermName)
cvTerm.put(FeatureStringEnum.NAME.value,type)
}
return featureService.convertJSONToOntologyId(cvTerm)
}

private List<FeatureType> getFeatureTypeListForType(String type){
String ontologyId = getOntologyIdForType(type)
return FeatureType.findAllByOntologyId(ontologyId)
}

@RestApiMethod(description = "Get canned comments", path = "/annotationEditor/getCannedComments", verb = RestApiVerb.POST)
@RestApiParams(params = [
@RestApiParam(name = "username", type = "email", paramType = RestApiParamType.QUERY)
Expand All @@ -1006,7 +1031,68 @@ class AnnotationEditorController extends AbstractApolloController implements Ann
render status: HttpStatus.UNAUTHORIZED
return
}
render CannedComment.listOrderByComment() as JSON

Organism organism = Organism.findById(inputObject.getLong(FeatureStringEnum.ORGANISM_ID.value))
String type = inputObject.getString(FeatureStringEnum.TYPE.value)
List<FeatureType> featureTypeList = getFeatureTypeListForType(type)
render cannedCommentService.getCannedComments(organism,featureTypeList) as JSON
}

@RestApiMethod(description = "Get canned keys", path = "/annotationEditor/getCannedKeys", verb = RestApiVerb.POST)
@RestApiParams(params = [
@RestApiParam(name = "username", type = "email", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "password", type = "password", paramType = RestApiParamType.QUERY)
])
def getCannedKeys() {
log.debug "canned key data ${params.data}"
JSONObject inputObject = permissionService.handleInput(request, params)
if (!permissionService.hasPermissions(inputObject, PermissionEnum.READ)) {
render status: HttpStatus.UNAUTHORIZED
return
}

Organism organism = Organism.findById(inputObject.getLong(FeatureStringEnum.ORGANISM_ID.value))
String type = inputObject.getString(FeatureStringEnum.TYPE.value)
List<FeatureType> featureTypeList = getFeatureTypeListForType(type)
render cannedAttributeService.getCannedKeys(organism,featureTypeList) as JSON
}

@RestApiMethod(description = "Get canned values", path = "/annotationEditor/getCannedValues", verb = RestApiVerb.POST)
@RestApiParams(params = [
@RestApiParam(name = "username", type = "email", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "password", type = "password", paramType = RestApiParamType.QUERY)
])
def getCannedValues() {
log.debug "canned value data ${params.data}"
JSONObject inputObject = permissionService.handleInput(request, params)
if (!permissionService.hasPermissions(inputObject, PermissionEnum.READ)) {
render status: HttpStatus.UNAUTHORIZED
return
}

Organism organism = Organism.findById(inputObject.getLong(FeatureStringEnum.ORGANISM_ID.value))
String type = inputObject.getString(FeatureStringEnum.TYPE.value)
List<FeatureType> featureTypeList = getFeatureTypeListForType(type)
render cannedAttributeService.getCannedValues(organism,featureTypeList) as JSON
}

@RestApiMethod(description = "Get available statuses", path = "/annotationEditor/getAvailableStatuses", verb = RestApiVerb.POST)
@RestApiParams(params = [
@RestApiParam(name = "username", type = "email", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "password", type = "password", paramType = RestApiParamType.QUERY)
])
def getAvailableStatuses() {
log.debug "get available statuses${params.data}"
JSONObject inputObject = permissionService.handleInput(request, params)
if (!permissionService.hasPermissions(inputObject, PermissionEnum.READ)) {
render status: HttpStatus.UNAUTHORIZED
return
}

Organism organism = Organism.findById(inputObject.getLong(FeatureStringEnum.ORGANISM_ID.value))
String type = inputObject.getString(FeatureStringEnum.TYPE.value)
List<FeatureType> featureTypeList = getFeatureTypeListForType(type)
render availableStatusService.getAvailableStatuses(organism,featureTypeList) as JSON
}

@RestApiMethod(description = "Search sequences", path = "/annotationEditor/searchSequences", verb = RestApiVerb.POST)
Expand Down Expand Up @@ -1211,52 +1297,11 @@ class AnnotationEditorController extends AbstractApolloController implements Ann
properties.put(jsonProperty);
}

JSONArray cannedKeys = cannedAttributeService.getCannedKeys(sequence.organism,featureTypeList)
JSONArray cannedValues = cannedAttributeService.getCannedValues(sequence.organism,featureTypeList)
newFeature.put(FeatureStringEnum.CANNED_KEYS.value, cannedKeys)
newFeature.put(FeatureStringEnum.CANNED_VALUES.value, cannedValues)


List<CannedKey> cannedKeyList = new ArrayList<>()
JSONArray cannedKeys = new JSONArray();
newFeature.put(FeatureStringEnum.CANNED_KEYS.value, cannedKeys);
if (featureTypeList) {
cannedKeyList.addAll(CannedKey.executeQuery("select cc from CannedKey cc join cc.featureTypes ft where ft in (:featureTypeList)", [featureTypeList: featureTypeList]))
}
cannedKeyList.addAll(CannedKey.executeQuery("select cc from CannedKey cc where cc.featureTypes is empty"))

// // if there are organism filters for these canned comments for this organism, then apply them
List<CannedKeyOrganismFilter> cannedKeyOrganismFilters = CannedKeyOrganismFilter.findAllByCannedKeyInList(cannedKeyList)
if (cannedKeyOrganismFilters) {
CannedKeyOrganismFilter.findAllByOrganismAndCannedKeyInList(sequence.organism, cannedKeyList).each {
cannedKeys.put(it.cannedKey.label)
}
}
// // otherwise ignore them
else {
cannedKeyList.each {
cannedKeys.put(it.label)
}
}

// handle canned Values
List<CannedValue> cannedValueList = new ArrayList<>()
JSONArray cannedValues = new JSONArray();
newFeature.put(FeatureStringEnum.CANNED_VALUES.value, cannedValues);
if (featureTypeList) {
cannedValueList.addAll(CannedValue.executeQuery("select cc from CannedValue cc join cc.featureTypes ft where ft in (:featureTypeList)", [featureTypeList: featureTypeList]))
}
cannedValueList.addAll(CannedValue.executeQuery("select cc from CannedValue cc where cc.featureTypes is empty"))

// // if there are organism filters for these canned comments for this organism, then apply them
List<CannedValueOrganismFilter> cannedValueOrganismFilters = CannedValueOrganismFilter.findAllByCannedValueInList(cannedValueList)
if (cannedValueOrganismFilters) {
CannedValueOrganismFilter.findAllByOrganismAndCannedValueInList(sequence.organism, cannedValueList).each {
cannedValues.put(it.cannedValue.label)
}
}
// // otherwise ignore them
else {
cannedValueList.each {
cannedValues.put(it.label)
}
}
}
if (configWrapperService.hasDbxrefs() || configWrapperService.hasPubmedIds() || configWrapperService.hasGoIds()) {
JSONArray dbxrefs = new JSONArray();
Expand All @@ -1275,28 +1320,9 @@ class AnnotationEditorController extends AbstractApolloController implements Ann
comments.put(comment.value);
}

JSONArray cannedComments = new JSONArray();
newFeature.put(FeatureStringEnum.CANNED_COMMENTS.value, cannedComments);

List<CannedComment> cannedCommentList = new ArrayList<>()
if (featureTypeList) {
cannedCommentList.addAll(CannedComment.executeQuery("select cc from CannedComment cc join cc.featureTypes ft where ft in (:featureTypeList)", [featureTypeList: featureTypeList]))
}
cannedCommentList.addAll(CannedComment.executeQuery("select cc from CannedComment cc where cc.featureTypes is empty"))

// if there are organism filters for these canned comments for this organism, then apply them
List<CannedCommentOrganismFilter> cannedCommentOrganismFilters = CannedCommentOrganismFilter.findAllByCannedCommentInList(cannedCommentList)
if (cannedCommentOrganismFilters) {
CannedCommentOrganismFilter.findAllByOrganismAndCannedCommentInList(sequence.organism, cannedCommentList).each {
cannedComments.put(it.cannedComment.comment)
}
}
// otherwise ignore them
else {
cannedCommentList.each {
cannedComments.put(it.comment)
}
}
JSONArray cannedComments = cannedCommentService.getCannedComments(sequence.organism,featureTypeList)
newFeature.put(FeatureStringEnum.CANNED_COMMENTS.value, cannedComments);
}

JSONArray suggestedNames = new JSONArray();
Expand Down
16 changes: 16 additions & 0 deletions grails-app/controllers/org/bbop/apollo/AnnotatorController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class AnnotatorController {
, @RestApiParam(name = "name", type = "string", paramType = RestApiParamType.QUERY, description = "Updated feature name")
, @RestApiParam(name = "symbol", type = "string", paramType = RestApiParamType.QUERY, description = "Updated feature symbol")
, @RestApiParam(name = "description", type = "string", paramType = RestApiParamType.QUERY, description = "Updated feature description")
, @RestApiParam(name = "status", type = "string", paramType = RestApiParamType.QUERY, description = "Updated status")
]
)
@Transactional
Expand All @@ -199,6 +200,19 @@ class AnnotatorController {
feature.name = data.name
feature.symbol = data.symbol
feature.description = data.description
println "status input ${data.status}"

if(data.status==null){
// delete old status if it existed
Status oldStatus = data.status
feature.status == null
oldStatus.delete()
}
else{
Status status = Status.findOrSaveByValueAndFeature(data.status,feature)
feature.status = status
}
println "status output ${Status.findByValue(data.status)}"

feature.save(flush: true, failOnError: true)

Expand Down Expand Up @@ -385,6 +399,8 @@ class AnnotatorController {
fetchMode 'goAnnotations', FetchMode.JOIN
}
fetchMode 'owners', FetchMode.JOIN
fetchMode 'featureDBXrefs', FetchMode.JOIN
fetchMode 'featureProperties', FetchMode.JOIN
fetchMode 'featureLocations', FetchMode.JOIN
fetchMode 'featureLocations.sequence', FetchMode.JOIN
fetchMode 'parentFeatureRelationships', FetchMode.JOIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class NcbiProxyServiceController {
String db = params.db
String id = params.id
String operation = params.operation
println "params ${params}"
String urlString

switch (operation) {
Expand Down
41 changes: 41 additions & 0 deletions grails-app/services/org/bbop/apollo/AvailableStatusService.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.bbop.apollo

import grails.transaction.Transactional
import org.codehaus.groovy.grails.web.json.JSONArray

@Transactional
class AvailableStatusService {

JSONArray getAvailableStatuses(Organism organism, List<FeatureType> featureTypeList) {
JSONArray availableStatusesJSONArray = new JSONArray();
// add all CC with no type and organism
List<AvailableStatus> availableStatusList = new ArrayList<>()
if (featureTypeList) {
availableStatusList.addAll(AvailableStatus.executeQuery("select cc from AvailableStatus cc join cc.featureTypes ft where ft in (:featureTypeList)", [featureTypeList: featureTypeList]))
}
availableStatusList.addAll(AvailableStatus.executeQuery("select cc from AvailableStatus cc where cc.featureTypes is empty"))

// if there are organism filters for these canned comments for this organism, then apply them
List<AvailableStatusOrganismFilter> availableStatusOrganismFilters = AvailableStatusOrganismFilter.findAllByAvailableStatusInList(availableStatusList)
if (availableStatusOrganismFilters) {
// if the organism is in the list, that is good
AvailableStatusOrganismFilter.findAllByOrganismAndAvailableStatusInList(organism, availableStatusList).each {
availableStatusesJSONArray.put(it.availableStatus.value)
}
// we have to add anything from availableStatusList that isn't in another one
List<AvailableStatus> availableStatusesToExclude = AvailableStatusOrganismFilter.findAllByOrganismNotEqualAndAvailableStatusInList(organism, availableStatusList).availableStatus
for(AvailableStatus availableStatus in availableStatusList){
if(!availableStatusesJSONArray.contains(availableStatus.value) && !availableStatusesToExclude.contains(availableStatus)){
availableStatusesJSONArray.put(availableStatus.value)
}
}
}
// otherwise ignore them
else {
availableStatusList.each {
availableStatusesJSONArray.put(it.value)
}
}
return availableStatusesJSONArray
}
}
72 changes: 72 additions & 0 deletions grails-app/services/org/bbop/apollo/CannedAttributeService.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.bbop.apollo

import grails.transaction.Transactional
import org.codehaus.groovy.grails.web.json.JSONArray

@Transactional
class CannedAttributeService {

JSONArray getCannedKeys(Organism organism, List<FeatureType> featureTypeList) {
JSONArray cannedKeysJSONArray = new JSONArray();
List<CannedKey> cannedKeyList = new ArrayList<>()
if (featureTypeList) {
cannedKeyList.addAll(CannedKey.executeQuery("select cc from CannedKey cc join cc.featureTypes ft where ft in (:featureTypeList)", [featureTypeList: featureTypeList]))
}
cannedKeyList.addAll(CannedKey.executeQuery("select cc from CannedKey cc where cc.featureTypes is empty"))

// if there are organism filters for these canned comments for this organism, then apply them
List<CannedKeyOrganismFilter> cannedKeyOrganismFilters = CannedKeyOrganismFilter.findAllByCannedKeyInList(cannedKeyList)
if (cannedKeyOrganismFilters) {
CannedKeyOrganismFilter.findAllByOrganismAndCannedKeyInList(organism, cannedKeyList).each {
cannedKeysJSONArray.put(it.cannedKey.label)
}
// we have to add anything from cannedCommentList that isn't in another one
List<CannedKey> cannedKeysToExclude = CannedKeyOrganismFilter.findAllByOrganismNotEqualAndCannedKeyInList(organism, cannedKeyList).cannedKey
for(CannedKey cannedKey in cannedKeyList){
if(!cannedKeysJSONArray.contains(cannedKey.label) && !cannedKeysToExclude.contains(cannedKey)){
cannedKeysJSONArray.put(cannedKey.label)
}
}
}
// otherwise ignore them
else {
cannedKeyList.each {
cannedKeysJSONArray.put(it.label)
}
}
return cannedKeysJSONArray
}

JSONArray getCannedValues(Organism organism, List<FeatureType> featureTypeList) {

JSONArray cannedValuesJSONArray = new JSONArray();

List<CannedValue> cannedValueList = new ArrayList<>()
if (featureTypeList) {
cannedValueList.addAll(CannedValue.executeQuery("select cc from CannedValue cc join cc.featureTypes ft where ft in (:featureTypeList)", [featureTypeList: featureTypeList]))
}
cannedValueList.addAll(CannedValue.executeQuery("select cc from CannedValue cc where cc.featureTypes is empty"))

// if there are organism filters for these canned comments for this organism, then apply them
List<CannedValueOrganismFilter> cannedValueOrganismFilters = CannedValueOrganismFilter.findAllByCannedValueInList(cannedValueList)
if (cannedValueOrganismFilters) {
CannedValueOrganismFilter.findAllByOrganismAndCannedValueInList(organism, cannedValueList).each {
cannedValuesJSONArray.put(it.cannedValue.label)
}
// we have to add anything from cannedValueList that isn't in another one
List<CannedValue> cannedValuesToExclude = CannedValueOrganismFilter.findAllByOrganismNotEqualAndCannedValueInList(organism, cannedValueList).cannedValue
for(CannedValue cannedValue in cannedValueList){
if(!cannedValuesJSONArray.contains(cannedValue.label) && !cannedValuesToExclude.contains(cannedValue)){
cannedValuesJSONArray.put(cannedValue.label)
}
}
}
// otherwise ignore them
else {
cannedValueList.each {
cannedValuesJSONArray.put(it.label)
}
}
return cannedValuesJSONArray
}
}
Loading

0 comments on commit b3ac28a

Please sign in to comment.