Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preeti variant finder #167

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e12c9c8
test
dkjang Aug 14, 2018
ddc98e5
Variant finder more code change
dkjang Aug 16, 2018
86e851b
animation added to variant finder filter
dkjang Aug 17, 2018
da982a5
Variant finder slide added
dkjang Aug 20, 2018
eb441dc
Phenotype search added to variant finder
dkjang Aug 21, 2018
81928ab
Merge branch 'master' of https://github.com/broadinstitute/dig-diabet…
preetisi Sep 18, 2018
803b927
Merge branch 'master' of https://github.com/broadinstitute/dig-diabet…
preetisi Sep 27, 2018
c44d247
new ajax method and rest call to getData
preetisi Oct 8, 2018
5428e1b
Merge branch 'master' of https://github.com/broadinstitute/dig-diabet…
preetisi Oct 8, 2018
9a9b81b
Merge branch 'master' of https://github.com/broadinstitute/dig-diabet…
preetisi Oct 25, 2018
71e7357
on submit request make a ajax call to getData and return a JSON object
preetisi Oct 31, 2018
a40b7f5
intermittent changes after code review
preetisi Nov 6, 2018
64be9e8
Merge branch 'master' into preeti-variant-finder
preetisi Nov 6, 2018
6937184
fix the parameters for grails
preetisi Nov 8, 2018
fd96b6d
reversing a few changes for a working version of getData f=so that DK…
preetisi Nov 8, 2018
a68e7a7
Merge branch 'master' of https://github.com/broadinstitute/dig-diabet…
preetisi Nov 13, 2018
1382312
temp function to render VF table added
dkjang Nov 13, 2018
2a228cf
fix the empty protein change
preetisi Nov 13, 2018
0df5fd4
Merge branch 'preeti-variant-finder' of https://github.com/broadinsti…
preetisi Nov 13, 2018
33ff121
VF table stying code in temp place.
dkjang Nov 14, 2018
5d51dcb
Merge branch 'preeti-variant-finder' of https://github.com/broadinsti…
dkjang Nov 14, 2018
d2d4021
process the output json from getData call
preetisi Nov 14, 2018
cded636
process the output json object
preetisi Nov 15, 2018
f827873
Update grails-app/views/layouts/t2dGenesCore.gsp
dkjang Nov 15, 2018
5b2e25e
Merge branch 'preeti-variant-finder' of https://github.com/broadinsti…
dkjang Nov 15, 2018
f30126b
change hashmap to linkedhashmap
preetisi Nov 15, 2018
8df7199
check if the value if null then ouput json key should be empty string
preetisi Nov 15, 2018
769465a
add translated name for dataset and phenotpye
preetisi Nov 15, 2018
ab24d5f
VF result table rendering code added
dkjang Nov 15, 2018
5de7dff
Links added to variant ids and gene ids. Coded modified to re-renderi…
dkjang Nov 16, 2018
3893997
Key to annotation name + sorting column highlight done
dkjang Nov 16, 2018
c8b7650
add pproperty and dproperty map
preetisi Nov 27, 2018
f29fac4
recovered from wierd code removal.
dkjang Dec 4, 2018
81a1032
built properties map, filters map and converted that to json object f…
preetisi Dec 14, 2018
639afde
update the key name dataset to dataset_id
preetisi Dec 14, 2018
def8771
Merge branch 'preeti-variant-finder' of https://github.com/broadinsti…
dkjang Dec 14, 2018
dbcdbdd
re-writing the pProperty Map
preetisi Jan 3, 2019
4ef732a
Merge branch 'preeti-variant-finder' of https://github.com/broadinsti…
preetisi Jan 3, 2019
c1ce8f6
fix the entities map
preetisi Jan 7, 2019
f657995
fix the EAF and MAF values - entities map
preetisi Jan 8, 2019
92f51b3
add MINA, MINU
preetisi Jan 8, 2019
14de52e
VF table fix (remove empty columns + display columns in correct order)
dkjang Jan 8, 2019
6066fcd
Rounding odds ratio is added
dkjang Jan 8, 2019
fdc4273
add MAF
preetisi Jan 9, 2019
5feba4d
fix the edit form
preetisi Jan 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion grails-app/conf/portalResources.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ modules = {
resource url: 'js/lib/lodash.min.js'



}
igvNarrow { // IGV on a page with core
resource url: 'https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css'
Expand Down Expand Up @@ -243,6 +242,11 @@ modules = {
resource url: 'js/lib/dport/traitSample.js'
}
traitsFilter {

resource url: 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css'

resource url: 'js/lib/bootstrap-select.js'

resource url: 'js/lib/dport/traitsFilter.js'
}
higlass {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.broadinstitute.mpg

import com.google.gson.JsonObject
import grails.converters.JSON
import groovy.json.JsonSlurper
import org.apache.juli.logging.LogFactory
Expand Down Expand Up @@ -221,6 +222,8 @@ class VariantSearchController {
return jsonQueries
}



/***
* Someone has requested the 'search builder' page. If they are coming to this page without a search
* context then encParams will be empty. If instead they are trying to revise their search then
Expand Down Expand Up @@ -338,6 +341,7 @@ class VariantSearchController {
* @return
*/
def launchAVariantSearch() {

displayCombinedVariantSearch(params.filters, params.props, params.specificGene)
}

Expand Down Expand Up @@ -466,6 +470,20 @@ class VariantSearchController {
}


/***
* Returns association statistics across 25 traits for a single variant. The launching page is traitInfo
* @return
*/
def ajaxVariantFinderGetData() {
JSONArray jsonParams = JSON.parse(params.data)
JSONObject jsonObject = restServerService.getVariantFinderSpecificData(jsonParams)
render(status: 200, contentType: "application/json") {
[variant: jsonObject]
}

}





Expand Down Expand Up @@ -1227,6 +1245,8 @@ class VariantSearchController {
}

private void displayCombinedVariantSearch(String filters, String requestForAdditionalProperties,String specificGene) {

// JSONObject getDataOutput = RestServerService.v
ArrayList<JSONObject> listOfQueries = (new JsonSlurper()).parseText(filters)
ArrayList<String> listOfCodedFilters = parseFilterJson(listOfQueries);

Expand Down
222 changes: 214 additions & 8 deletions grails-app/services/org/broadinstitute/mpg/RestServerService.groovy
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.broadinstitute.mpg

import com.google.gson.JsonObject
import grails.plugins.rest.client.RestBuilder
import grails.plugins.rest.client.RestResponse
import grails.transaction.Transactional
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import org.apache.juli.logging.LogFactory
import org.broadinstitute.mpg.diabetes.BurdenService
Expand All @@ -22,6 +22,7 @@ import org.broadinstitute.mpg.diabetes.util.PortalException
import org.codehaus.groovy.grails.commons.GrailsApplication
import org.codehaus.groovy.grails.web.json.JSONArray
import org.codehaus.groovy.grails.web.json.JSONObject
//import sun.plugin.javascript.navig.Link

@Transactional
class RestServerService {
Expand Down Expand Up @@ -2118,15 +2119,97 @@ time required=${(afterCall.time - beforeCall.time) / 1000} seconds
JsonSlurper slurper = new JsonSlurper()

JSONObject apiResults = this.getClumpDataRestCall(phenotype, dataSetName,r2)


String jsonParsedFromApi = processInfoFromGetClumpDataCall( apiResults, "", ",\n\"dataset\":\"${dataSetName}\"" )

JSONObject dataJsonObject = slurper.parseText(jsonParsedFromApi)

return dataJsonObject
}

/***
* Gather up the data that is used in the variant finder tool
*
* @param listOfMap
*/
public JSONObject getVariantFinderSpecificData(JSONArray inputListOfMap) {
JSONObject apiResults = this.variantFinderGetDataRestCall(inputListOfMap)
JSONObject resultObject = this.processInfoFromGetDataRestCall(apiResults)

return resultObject
}

/***
* Process the data after getData rest API call
*
* @param apiResults
*/
public JSONObject processInfoFromGetDataRestCall(JSONObject apiResults) {
def g = grailsApplication.mainContext.getBean('org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib')
JSONObject resultObject = new JSONObject();
if (!apiResults["is_error"]) {
List<Map> listOfEachVariantInfoMap = []
Map<String,Object> variantInfoMap = new HashMap<>()
int numberOfVariantsRecords = apiResults.numRecords
for (int j = 0; j < numberOfVariantsRecords; j++) {
List<String> keys = []
LinkedHashMap<String,Object> commonAnnotationMap = new LinkedHashMap<>()
LinkedHashMap<String,Object> eachVariantInfoMap = new LinkedHashMap<>()
for (int i = 0; i < apiResults.variants[j]?.size(); i++) {
keys << (new JSONObject(apiResults.variants[j][i]).keys()).next()
}
List<Map> listOfEntitiesMap = []
for(int l = 0; l< keys.size();l++){
//create new entitiesMap only when the dataset is different

def value = apiResults.variants[j][l][keys[l]]
if(value instanceof String || value instanceof Integer){
commonAnnotationMap.put(keys[l],value)
}
if(value.equals(null)){
String emptyString = " "
//add empty String if the value doesn't exist
commonAnnotationMap.put(keys[l],emptyString)
}
eachVariantInfoMap.put("common_annotation",commonAnnotationMap)
if(value instanceof Map){
Iterator<String> keysItr = value.keys();
while (keysItr.hasNext()) {
LinkedHashMap<String,Object> entitiesMap = new LinkedHashMap<>()
String keyOfMap = keysItr.next();
Object valueOfValueMap = value.get(keyOfMap);
//get the translated name of the dataset
String translatedDatasetName = g.message(code: 'metadata.' + keyOfMap, default: keyOfMap);
entitiesMap.put("dataset" ,translatedDatasetName)
if(valueOfValueMap instanceof Map){
Iterator<String> nextkeysItr = valueOfValueMap.keys();
while (nextkeysItr.hasNext()) {
String nextkeyOfMap = nextkeysItr.next();
Object nextvalueOfMap = value.get(keyOfMap).get(nextkeyOfMap);
//get the translated name of phenotype
String translatedPhenotypeName = g.message(code: 'metadata.' + nextkeyOfMap, default: nextkeyOfMap);
entitiesMap.put("phenotype", translatedPhenotypeName)
entitiesMap.put(keys[l],nextvalueOfMap)
}
}
else{

String translatedPhenotypeName = g.message(code: 'metadata.' + "T2D", default: "T2D");
entitiesMap.put("phenotype", translatedPhenotypeName)
entitiesMap.put(keys[l],valueOfValueMap)
}

listOfEntitiesMap.add(entitiesMap)
}

}
}
eachVariantInfoMap.put("entities",listOfEntitiesMap)
listOfEachVariantInfoMap.add(eachVariantInfoMap)
}
variantInfoMap.put("variants",listOfEachVariantInfoMap)
resultObject = new JSONObject(variantInfoMap)
}
return resultObject
}


public JSONObject gatherSpecificTraitsPerVariantResults( String variantName, List<LinkedHashMap<String,String>> propsToUse) {
Expand Down Expand Up @@ -2816,7 +2899,12 @@ time required=${(afterCall.time - beforeCall.time) / 1000} seconds
}
}

} else if (value instanceof ArrayList) {
}
else if (value == null) {
String emptyValue = " "
variantSpecificList << "{\"level\":\"${key}\",\"count\":\"${emptyValue}\"}"
}
else if (value instanceof ArrayList) {
ArrayList arrayListValue = value as ArrayList
log.error("An ArrayList is not an expected result. Did the return data format change?")
}
Expand Down Expand Up @@ -2980,13 +3068,132 @@ time required=${(afterCall.time - beforeCall.time) / 1000} seconds
*/
String clumpDataJsonPayloadString = """ {"phenotype": "${phenotype}","dataset": "${datasetName}", "r2": "${r2}",
"pagination":{"size":5000,"offset":0},"p_valueThreshold":1.0 } """.toString()

JSONObject VectorDataJson = this.postClumpDataRestCall(clumpDataJsonPayloadString);


return VectorDataJson;
}

public List<Map<String,Object>> getFilterList(JSONArray listOfInputMap){
List listOfFilterMaps = []
for(int i = 0;i<listOfInputMap.length();i++){
Map<String, Object> eachFilter = new HashMap<String, Object>();
for(int j=0;j<listOfInputMap[i].values().size();j++){
if(listOfInputMap[i].keys()[j] == "operator"){
if(listOfInputMap[i].values()[j] == "<"){
eachFilter.put("operator",listOfInputMap[i].values()[j].toString().replace("<","LT"))
}
else {
eachFilter.put("operator", listOfInputMap[i].values()[j].toString().replace(">", "GT")
)
}
}
else if(listOfInputMap[i].keys()[j] == "dataset"){
eachFilter.put("dataset_id",listOfInputMap[i].values()[j])
}
else{
eachFilter.put(listOfInputMap[i].keys()[j].toString(),listOfInputMap[i].values()[j])
}
eachFilter.put("operand_type",listOfInputMap[i]['value'].getClass().getSimpleName())
}
//replace the keyname of dataset to dataset_id
//eachFilter[]
listOfFilterMaps.add(new JSONObject(eachFilter))
}

return listOfFilterMaps
}

public Map<String,Map> getPproperties(JSONArray listOfInputMap){
Map<String, Map<String,List>> operandMap = new HashMap<>()
List<String> operandsToFetch = []
//iterate over the jsonObject

for(int i = 0;i<listOfInputMap.length();i++){
def operand = listOfInputMap[i]['operand']
def dataset = listOfInputMap[i]['dataset_id']
def phenotype = listOfInputMap[i]['phenotype']

operandsToFetch = metaDataService.getPhenotypeSpecificSampleGroupPropertyList(phenotype, dataset, [/^MINA/,/^MAF/, /^MINU/, /^(OR|ODDS|BETA)/, /^P_(EMMAX|FIRTH|FE|VALUE)/])
if (operandsToFetch.size() == 0) {
operandsToFetch.add(operand);
}

for (int j = 0; j < operandsToFetch.size(); j++) {
operand = operandsToFetch[j];
def datasetMap = operandMap.get(operand)
if (datasetMap == null) {
datasetMap = new HashMap<String, List>()
operandMap.put(operand, datasetMap)
}

def phenoList = datasetMap.get(dataset)
if (phenoList == null) {
phenoList = []
datasetMap.put(dataset, phenoList)
}
phenoList.add(phenotype)
}
}
return operandMap
}

public List<String> getCproperties(JSONArray listOfInputMap){
List<String> cProperties = []
cProperties.add("CHROM")
cProperties.add("CLOSEST_GENE")
cProperties.add("Consequence")
cProperties.add("DBSNP_ID")
cProperties.add("Effect_Allele")
cProperties.add("POS")
cProperties.add("Protein_change")
cProperties.add("Reference_Allele")
cProperties.add("VAR_ID")

return cProperties
}

public Map<String,Object> getDproperies(JSONArray listOfInputMap){

Map<String,Object> dPropertyMap = new HashMap<>()
// dPropertyMap.put("empty","")

return dPropertyMap
}


public Map<String,Object> generateGetDataJsonInput(JSONArray listOfInputMap){

Map <String,Object> properties = new HashMap<>()
Map <String,Object> inputGetDataJsonObject = new HashMap<>()
inputGetDataJsonObject.put("passback", "abc123")
inputGetDataJsonObject.put("entity", "variant")
inputGetDataJsonObject.put("page_start", -1)
inputGetDataJsonObject.put("page_size", -1)
inputGetDataJsonObject.put("limit",1000)
inputGetDataJsonObject.put("count", false)
inputGetDataJsonObject.put("result_format", "verbose")
inputGetDataJsonObject.put("order_by",[])
inputGetDataJsonObject.put("properties",properties)
properties.put("cproperty", getCproperties(listOfInputMap))
properties.put("dproperty",getDproperies(listOfInputMap))
properties.put("pproperty", getPproperties(listOfInputMap))
inputGetDataJsonObject.put("filters",getFilterList(listOfInputMap))

return inputGetDataJsonObject
}

/***
* this is the core function for making a call to getData and return the data as a map.
*/
def variantFinderGetDataRestCall(JSONArray listOfInputMap){
Map<String, Object> inputGetDataMap = this.generateGetDataJsonInput(listOfInputMap);
inputGetDataMap.toString()
def json = JsonOutput.toJson(inputGetDataMap)
JSONObject jsonObject = postGetDataCall(json)
return jsonObject
}



/***
* Note: this call is not used interactively, but used instead to fill the grails domain object that holds
Expand Down Expand Up @@ -3036,7 +3243,6 @@ time required=${(afterCall.time - beforeCall.time) / 1000} seconds
Gene.refresh(geneName, chromosome, startPosition, endPosition)
}
}

return returnValue
}

Expand Down
Loading