-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to fetch variant data from track via web services (#1867)
* move checkPermission to TrackService * Add new enums to FeatureStringEnum * Implement ability to fetch variant data from a track via web services * Bump htsjdk to 2.14.3 * fixed for the BAM canvas (#1869) * fixed for the BAM canvas * fixed biotypes to match codebase * Use 'seqId' instead of 'sequence' in JSON * Enable caching * add API documentation * Update REST API docs * just updated the labels brielfy * fixed mismatches in sequence header * fixed a long-running bug in caching
- Loading branch information
1 parent
b75d84a
commit 04d9a6d
Showing
8 changed files
with
1,635 additions
and
1,019 deletions.
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
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
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
73 changes: 73 additions & 0 deletions
73
grails-app/controllers/org/bbop/apollo/VcfController.groovy
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,73 @@ | ||
package org.bbop.apollo | ||
|
||
import grails.converters.JSON | ||
import htsjdk.variant.vcf.VCFFileReader | ||
import org.bbop.apollo.gwt.shared.FeatureStringEnum | ||
import org.bbop.apollo.gwt.shared.PermissionEnum | ||
import org.codehaus.groovy.grails.web.json.JSONArray | ||
import org.codehaus.groovy.grails.web.json.JSONObject | ||
import org.restapidoc.annotation.RestApi | ||
import org.restapidoc.annotation.RestApiMethod | ||
import org.restapidoc.annotation.RestApiParam | ||
import org.restapidoc.annotation.RestApiParams | ||
import org.restapidoc.pojo.RestApiParamType | ||
import org.restapidoc.pojo.RestApiVerb | ||
|
||
import javax.servlet.http.HttpServletResponse | ||
|
||
@RestApi(name = "VCF Services", description = "Methods for retrieving VCF track data as JSON") | ||
class VcfController { | ||
|
||
def preferenceService | ||
def permissionService | ||
def vcfService | ||
def trackService | ||
|
||
@RestApiMethod(description = "Get VCF track data for a given range as JSON", path = "/vcf/<organism_name>/<track_name>/<sequence_name>:<fmin>..<fmax>.<type>?includeGenotypes=<includeGenotypes>&ignoreCache=<ignoreCache>", verb = RestApiVerb.GET) | ||
@RestApiParams(params = [ | ||
@RestApiParam(name = "organismString", type = "string", paramType = RestApiParamType.QUERY, description = "Organism common name or ID (required)"), | ||
@RestApiParam(name = "trackName", type = "string", paramType = RestApiParamType.QUERY, description = "Track name by label in trackList.json (required)"), | ||
@RestApiParam(name = "sequence", type = "string", paramType = RestApiParamType.QUERY, description = "Sequence name (required)"), | ||
@RestApiParam(name = "fmin", type = "integer", paramType = RestApiParamType.QUERY, description = "Minimum range (required)"), | ||
@RestApiParam(name = "fmax", type = "integer", paramType = RestApiParamType.QUERY, description = "Maximum range (required)"), | ||
@RestApiParam(name = "type", type = "string", paramType = RestApiParamType.QUERY, description = ".json (required)"), | ||
@RestApiParam(name = "includeGenotypes", type = "boolean", paramType = RestApiParamType.QUERY, description = "(default: false). If true, will include genotypes associated with variants from VCF."), | ||
@RestApiParam(name = "ignoreCache", type = "boolean", paramType = RestApiParamType.QUERY, description = "(default: false). Use cache for request, if available."), | ||
]) | ||
def featuresByLocation(String organismString, String trackName, String sequence, Long fmin, Long fmax, String type, boolean includeGenotypes) { | ||
if(!trackService.checkPermission(request, response, organismString)) return | ||
|
||
JSONArray featuresArray = new JSONArray() | ||
Organism organism = preferenceService.getOrganismForToken(organismString) | ||
JSONObject trackListObject = trackService.getTrackList(organism.directory) | ||
String trackUrlTemplate | ||
for(JSONObject track : trackListObject.getJSONArray(FeatureStringEnum.TRACKS.value)) { | ||
if(track.getString(FeatureStringEnum.LABEL.value) == trackName) { | ||
trackUrlTemplate = track.urlTemplate | ||
break | ||
} | ||
} | ||
|
||
Boolean ignoreCache = params.ignoreCache != null ? Boolean.valueOf(params.ignoreCache) : false | ||
if (!ignoreCache) { | ||
String responseString = trackService.checkCache(organismString, trackName, sequence, fmin, fmax, type, null) | ||
if (responseString) { | ||
render JSON.parse(responseString) as JSON | ||
return | ||
} | ||
} | ||
|
||
File file = new File(organism.directory + File.separator + trackUrlTemplate) | ||
try { | ||
VCFFileReader vcfFileReader = new VCFFileReader(file) | ||
featuresArray = vcfService.processVcfRecords(organism, vcfFileReader, sequence, fmin, fmax, includeGenotypes) | ||
} | ||
catch (IOException e) { | ||
log.error(e.stackTrace) | ||
} | ||
|
||
trackService.cacheRequest(featuresArray.toString(), organismString, trackName, sequence, fmin, fmax, type, null) | ||
render featuresArray as JSON | ||
} | ||
|
||
} |
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
Oops, something went wrong.