This repository has been archived by the owner on Jan 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Add serializer for DataType retrieval #66
Open
Jarvanerp
wants to merge
5
commits into
gb-dev
Choose a base branch
from
gb-dev-data-export
base: gb-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c8bd375
Add implementation of serializer for datatype retrieval call.
f024b23
Changes to RestExportService based on feedback
bc5ca6f
Change input from JSONArray to JSONObject
fb81fbc
Make changes based on feedback
2da53ac
Change name of DataTypeRetrieved to Datatypes for frontend consistency
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
package org.transmartproject.db | ||
|
||
import grails.transaction.Transactional | ||
import groovy.json.JsonException | ||
import groovy.json.JsonSlurper | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.transmartproject.core.dataquery.highdim.HighDimensionResource | ||
import org.transmartproject.core.dataquery.highdim.assayconstraints.AssayConstraint | ||
import org.transmartproject.core.exceptions.InvalidArgumentsException | ||
import org.transmartproject.core.exceptions.NoSuchResourceException | ||
import org.transmartproject.core.ontology.ConceptsResource | ||
import org.transmartproject.core.ontology.OntologyTerm | ||
import org.transmartproject.export.Datatypes | ||
import org.transmartproject.export.Tasks.DataExportFetchTask | ||
import org.transmartproject.export.Tasks.DataExportFetchTaskFactory | ||
import org.transmartproject.core.dataquery.highdim.HighDimensionResource | ||
import org.transmartproject.core.ontology.ConceptsResource | ||
|
||
import static org.transmartproject.core.ontology.OntologyTerm.VisualAttributes.HIGH_DIMENSIONAL | ||
|
||
|
@@ -27,47 +32,39 @@ class RestExportService { | |
task.getTsv() | ||
} | ||
|
||
def formatDataTypes(List datatypes){ | ||
//Maybe make this a marshaller. | ||
def returnDataTypeList = [] | ||
def dataTypesList = [] | ||
datatypes.each { dataTypeMap -> | ||
dataTypeMap.each {key, value-> | ||
if (key in dataTypesList){ | ||
returnDataTypeList.each { map -> | ||
if (key in map.values()){ | ||
value.each{it.remove('datatypeCode')} | ||
map.get('cohorts').add([concepts:value]) | ||
} | ||
} | ||
} else{ | ||
dataTypesList.add(key) | ||
def datatypeCode = value.collect({it -> | ||
it.get('datatypeCode')}) | ||
value.each{it.remove('datatypeCode')} | ||
def datatypeMap = [dataType:key, | ||
dataTypeCode: datatypeCode[0], | ||
cohorts:[[concepts:value]]] | ||
returnDataTypeList.add(datatypeMap) | ||
} | ||
public List<Datatypes> retrieveDataTypes(params) { | ||
if (!(params.containsKey('concepts'))) { | ||
throw new NoSuchResourceException("No parameter named concepts was given.") | ||
} | ||
|
||
if (params.get('concepts') == "") { | ||
throw new InvalidArgumentsException("Parameter concepts has no value.") | ||
} | ||
|
||
def jsonSlurper = new JsonSlurper() | ||
def conceptParameters = params.get('concepts').decodeURL() | ||
List<Datatypes> dataTypes = [] | ||
try { | ||
def conceptArguments = jsonSlurper.parseText(conceptParameters) | ||
int cohortNumber = 0 | ||
conceptArguments.cohorts.collect { it -> | ||
cohortNumber += 1 | ||
getDataTypes(it, dataTypes, cohortNumber) | ||
} | ||
dataTypes | ||
} catch (JsonException e) { | ||
throw new InvalidArgumentsException("Given parameter was non valid JSON.") | ||
} | ||
returnDataTypeList | ||
} | ||
|
||
|
||
def getDataTypes(List conceptKeysList){ | ||
List cohortDataTypes = [] | ||
Map datatypesMap = [:] | ||
conceptKeysList.each { conceptKey -> | ||
OntologyTerm concept = conceptsResourceService.getByKey(conceptKey) | ||
datatypesMap = getHighDimDataType(concept, datatypesMap) | ||
private List<Datatypes> getDataTypes(Map conceptKeysList, List dataTypes, int cohortNumber) { | ||
conceptKeysList.conceptKeys.collect { conceptKey -> | ||
getDataType(conceptKey, dataTypes, cohortNumber) | ||
} | ||
cohortDataTypes += datatypesMap | ||
cohortDataTypes | ||
} | ||
|
||
def getHighDimDataType(OntologyTerm term, Map datatypesMap) { | ||
private void getDataType(String conceptKey, List dataTypes, int cohortNumber) { | ||
OntologyTerm term = conceptsResourceService.getByKey(conceptKey) | ||
// Retrieve all descendant terms that have the HIGH_DIMENSIONAL attribute | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this comment is intended as a description of this method right?
|
||
def terms = term.getAllDescendants() + term | ||
def highDimTerms = terms.findAll { it.visualAttributes.contains(HIGH_DIMENSIONAL) } | ||
|
@@ -83,34 +80,38 @@ class RestExportService { | |
}) | ||
] | ||
) | ||
//datatypes contains the number of patients for each datatype. | ||
def datatypes = highDimensionResourceService.getSubResourcesAssayMultiMap([constraint]) | ||
datatypes.collect({ key, value -> | ||
String datatype = key.dataTypeDescription | ||
String datatypeCode = key.dataTypeName | ||
if (datatype in datatypesMap.keySet()){ | ||
// term.getPatientCount() can also be value.size(). They give different numbers but I'm not sure | ||
// what's the difference | ||
datatypesMap[datatype].add([numOfPatients: term.getPatientCount(), conceptPath: term.fullName , datatypeCode: datatypeCode]) | ||
} else{ | ||
datatypesMap[datatype] = [[numOfPatients: term.getPatientCount(), conceptPath: term.fullName, datatypeCode: datatypeCode]] | ||
} | ||
addDataType(term, dataTypes, cohortNumber, key) | ||
}) | ||
datatypesMap | ||
} | ||
else { | ||
} else { | ||
// No high dimensional data found for this term, this means it is clinical data | ||
String datatype = "Clinical data" | ||
String datatypeCode = "clinical" | ||
if (datatype in datatypesMap.keySet()){ | ||
// term.getPatientCount() can also be value.size(). They give different numbers but I'm not sure | ||
// what's the difference | ||
datatypesMap[datatype].add([numOfPatients: term.patientCount, conceptPath: term.fullName , datatypeCode: datatypeCode]) | ||
} else{ | ||
datatypesMap[datatype] = [[numOfPatients: term.patientCount, conceptPath: term.fullName, datatypeCode: datatypeCode]] | ||
} | ||
datatypesMap | ||
addDataType(term, dataTypes, cohortNumber) | ||
} | ||
} | ||
|
||
private void addDataType(OntologyTerm term, List dataTypes, int cohortNumber, datatype = null) { | ||
String dataTypeString = datatype ? datatype.dataTypeDescription : "Clinical data" | ||
String dataTypeCode = datatype ? datatype.dataTypeName : "clinical" | ||
List tempDataTypes = dataTypes.collect { it.dataType } | ||
if (dataTypeString in tempDataTypes) { | ||
int index = tempDataTypes.indexOf(dataTypeString) | ||
Datatypes dataType = dataTypes[index] | ||
addOntologyTerm(term, dataType, cohortNumber) | ||
} else { | ||
Datatypes dataType = new Datatypes(dataType: dataTypeString, dataTypeCode: dataTypeCode) | ||
addOntologyTerm(term, dataType, cohortNumber) | ||
dataTypes.add(dataType) | ||
} | ||
} | ||
|
||
private void addOntologyTerm(OntologyTerm term, Datatypes dataType, int cohortNumberID) { | ||
if (cohortNumberID in dataType.OntologyTermsMap.keySet()) { | ||
dataType.OntologyTermsMap[cohortNumberID].add(term) | ||
} else { | ||
dataType.OntologyTermsMap[cohortNumberID] = [term] | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.transmartproject.export | ||
|
||
import org.transmartproject.core.ontology.OntologyTerm | ||
|
||
class Datatypes { | ||
|
||
Map<Integer, List<OntologyTerm>> OntologyTermsMap = [:] | ||
|
||
String dataType | ||
|
||
String dataTypeCode | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be replaced with