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

Fix 1134 go refactor v1 #2162

Merged
merged 10 commits into from May 23, 2019
4 changes: 2 additions & 2 deletions docs/Setup.md
Expand Up @@ -27,9 +27,9 @@ Other possible [build settings for JBrowse](http://gmod.org/wiki/JBrowse_Configu

Node versions 6+ have been tested. I would recommend using [nvm](https://github.com/creationix/nvm) and ``nvm install 8```

### Install python
### Install python, make

Node has a python dependency. `sudo apt-get install python`
Node has a python dependency. `sudo apt-get install python make`

### Install jdk

Expand Down
Expand Up @@ -3,7 +3,6 @@ package org.bbop.apollo.go
import grails.converters.JSON
import grails.transaction.Transactional
import org.bbop.apollo.Feature
import org.bbop.apollo.Organism
import org.bbop.apollo.User
import org.codehaus.groovy.grails.web.json.JSONObject
import org.restapidoc.annotation.RestApiMethod
Expand Down Expand Up @@ -83,7 +82,7 @@ class GoAnnotationController {
goAnnotation.evidenceRef = dataObject.evidenceCode
goAnnotation.negate = dataObject.negate ?: false
goAnnotation.withOrFromArray = dataObject.withOrFrom
goAnnotation.referenceArray = dataObject.references
goAnnotation.notesArray = dataObject.references
goAnnotation.lastUpdated = new Date()
goAnnotation.dateCreated = new Date()
goAnnotation.addToOwners(user)
Expand Down Expand Up @@ -118,7 +117,7 @@ class GoAnnotationController {
goAnnotation.evidenceRef = dataObject.evidenceCode
goAnnotation.negate = dataObject.negate ?: false
goAnnotation.withOrFromArray = dataObject.withOrFrom
goAnnotation.referenceArray = dataObject.references
goAnnotation.notesArray = dataObject.references
goAnnotation.lastUpdated = new Date()
goAnnotation.addToOwners(user)
goAnnotation.save(flush: true, failOnError: true,insert: false)
Expand Down
6 changes: 4 additions & 2 deletions grails-app/domain/org/bbop/apollo/go/GoAnnotation.groovy
Expand Up @@ -13,9 +13,10 @@ class GoAnnotation {
geneProductRelationshipRef nullable: true, blank: false
negate nullable: false
withOrFromArray nullable: true, blank: true
referenceArray nullable: true, blank: true
notesArray nullable: true, blank: true
dateCreated nullable: false
lastUpdated nullable: false
reference nullable: false, blank: false
}

static hasMany = [
Expand All @@ -28,7 +29,8 @@ class GoAnnotation {
String geneProductRelationshipRef
Boolean negate
String withOrFromArray
String referenceArray
String notesArray
String reference
Date lastUpdated
Date dateCreated

Expand Down
6 changes: 3 additions & 3 deletions grails-app/services/org/bbop/apollo/GpadHandlerService.groovy
Expand Up @@ -56,9 +56,9 @@ class GpadHandlerService {
writeObject.out.write(goAnnotation.goRef)
writeObject.out.write("\t")
//5 Reference ::= ID 1 PMID:30695063
// writeObject.out.write(goAnnotation.referenceArray)
if (goAnnotation.referenceArray) {
JSONArray referenceArray = new JsonSlurper().parseText(goAnnotation.referenceArray) as JSONArray
// writeObject.out.write(goAnnotation.notesArray)
if (goAnnotation.notesArray) {
JSONArray referenceArray = new JsonSlurper().parseText(goAnnotation.notesArray) as JSONArray
List<String> referenceList = referenceArray.collect()
writeObject.out.write(referenceList.join("|"))
}
Expand Down
59 changes: 46 additions & 13 deletions grails-app/services/org/bbop/apollo/SequenceService.groovy
Expand Up @@ -248,23 +248,56 @@ class SequenceService {
crc.update(sequence.name.getBytes());
String hex = String.format("%08x", crc.getValue())
String[] dirs = splitStringByNumberOfCharacters(hex, 3)
String seqDir = String.format("%s/seq/%s/%s/%s", sequence.organism.directory, dirs[0], dirs[1], dirs[2]);
String filePath = seqDir + "/" + sequence.name + "-" + chunkNumber + ".txt"
File file = new File(filePath)
if (file.exists()) {
return new File(filePath).text.toUpperCase()

Organism organism = sequence.organism
File trackListFile = new File(organism.trackList)
JSONObject trackListJsonObject = JSON.parse(trackListFile.text) as JSONObject
JSONArray tracksArray = trackListJsonObject.getJSONArray("tracks")

// support http://agrjbrowse2.s3-website-us-east-1.amazonaws.com/FlyBase/fruitfly/seq/{refseq_dirpath}/{refseq}-/seq/d3c/34b/35/2L-0.txtz
// convert to: http://agrjbrowse2.s3-website-us-east-1.amazonaws.com/FlyBase/fruitfly/seq/d3c/34b/35/2L-0.txtz
// support "seq/{refseq_dirpath}/{refseq}-",
String urlTemplate = sequence.organism.directory
Boolean isCompressed = false
for (def track in tracksArray) {
if (track.label == "DNA") {
urlTemplate = track.urlTemplate
isCompressed = track.compress == 1
}
}
// attempt with gzip
filePath = seqDir + "/" + sequence.name + "-" + chunkNumber + ".txtz"
file = new File(filePath)
if (file.exists()) {
def inflaterStream = new GZIPInputStream(new ByteArrayInputStream(file.bytes))
def uncompressedStr = inflaterStream.getText('UTF-8')
return uncompressedStr.toUpperCase()
// this will be automatically replaced correctly
urlTemplate = urlTemplate.replaceAll("\\{refseq\\}",sequence.name)
String seqPath = String.format("%s/%s/%s", dirs[0], dirs[1], dirs[2])
urlTemplate = urlTemplate.replaceAll("\\{refseq_dirpath\\}",seqPath)
String filePath = urlTemplate + chunkNumber + ".txt${isCompressed ? 'z' : ''}"
/**
* handle remote data
*/
if (filePath.startsWith("http")) {
def url = new URL(filePath)
if (isCompressed) {
def inflaterStream = new GZIPInputStream(new ByteArrayInputStream(url.bytes))
def uncompressedStr = inflaterStream.getText('UTF-8')
return uncompressedStr.toUpperCase()
} else {
return url.text
}
}

if(!filePath.startsWith("\\/")){
filePath = sequence.organism.directory + "/" + filePath
}
File file = new File(filePath)
if(file.exists()){
if (isCompressed) {
def inflaterStream = new GZIPInputStream(new ByteArrayInputStream(file.bytes))
def uncompressedStr = inflaterStream.getText('UTF-8')
return uncompressedStr.toUpperCase()
} else {
return file.text.toUpperCase()
}
}
throw new RuntimeException("File not found on server: " + filePath)

}

String[] splitStringByNumberOfCharacters(String label, int size) {
Expand Down
Expand Up @@ -35,7 +35,7 @@ class GoAnnotationService {
goObject.put("evidenceCode",goAnnotation.evidenceRef)
goObject.put("negate",goAnnotation.negate)
goObject.put("withOrFrom",goAnnotation.withOrFromArray)
goObject.put("references",goAnnotation.referenceArray)
goObject.put("references",goAnnotation.notesArray)
annotations.add(goObject)
}

Expand Down