Skip to content

Commit ccc5c64

Browse files
authored
Merge pull request #1073 from SynBioHub/issue1072
Add support to download GFF3 files
2 parents 3a61a63 + 35ce153 commit ccc5c64

9 files changed

Lines changed: 195 additions & 78 deletions

File tree

java/src/main/java/org/synbiohub/ConvertToGenBankJob.java

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,42 @@ public class ConvertToGenBankJob extends Job
1313
public boolean requireCompliant;
1414
public boolean enforceBestPractices;
1515
public boolean typesInURI;
16-
public boolean keepGoing;
17-
public String topLevelURI;
16+
public boolean keepGoing;
17+
public boolean gff3Out;
18+
public String topLevelURI;
1819

19-
public void execute() throws Exception
20-
{
21-
ByteArrayOutputStream logOutputStream = new ByteArrayOutputStream();
22-
ByteArrayOutputStream errorOutputStream = new ByteArrayOutputStream();
23-
24-
SBOLDocument doc = SBOLValidate.validate(
25-
new PrintStream(logOutputStream),
26-
new PrintStream(errorOutputStream),
27-
sbolFilename,
28-
"",
29-
"",
30-
requireComplete,
31-
requireCompliant,
32-
enforceBestPractices,
33-
typesInURI,
34-
"",
35-
keepGoing,
36-
"",
37-
"",
38-
sbolFilename,
39-
topLevelURI,
40-
true,
41-
false,
42-
false,
43-
false,
44-
"",
45-
false,
46-
false,
47-
false);
20+
public void execute() throws Exception
21+
{
22+
ByteArrayOutputStream logOutputStream = new ByteArrayOutputStream();
23+
ByteArrayOutputStream errorOutputStream = new ByteArrayOutputStream();
24+
25+
System.err.println("GFF3="+gff3Out);
26+
27+
SBOLDocument doc = SBOLValidate.validate(
28+
new PrintStream(logOutputStream),
29+
new PrintStream(errorOutputStream),
30+
sbolFilename,
31+
"",
32+
"",
33+
requireComplete,
34+
requireCompliant,
35+
enforceBestPractices,
36+
typesInURI,
37+
"",
38+
keepGoing,
39+
"",
40+
"",
41+
sbolFilename,
42+
topLevelURI,
43+
!gff3Out,
44+
false,
45+
false,
46+
false,
47+
gff3Out,
48+
"",
49+
false,
50+
false,
51+
false);
4852

4953
String log = new String(logOutputStream.toByteArray(), StandardCharsets.UTF_8);
5054
String errorLog = new String(errorOutputStream.toByteArray(), StandardCharsets.UTF_8);

lib/api/gff3.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
var pug = require('pug')
2+
3+
const { fetchSBOLObjectRecursive } = require('../fetch/fetch-sbol-object-recursive')
4+
5+
var serializeSBOL = require('../serializeSBOL')
6+
7+
var config = require('../config')
8+
9+
var getUrisFromReq = require('../getUrisFromReq')
10+
11+
const convertToGFF3 = require('../conversion/convert-to-gff3')
12+
13+
const tmp = require('tmp-promise')
14+
15+
var fs = require('mz/fs')
16+
17+
module.exports = function (req, res) {
18+
const { graphUri, uri } = getUrisFromReq(req, res)
19+
20+
var sbol
21+
22+
function saveTempFile () {
23+
return tmp.tmpName().then((tmpFilename) => {
24+
return fs.writeFile(tmpFilename, serializeSBOL(sbol)).then(() => {
25+
return Promise.resolve(tmpFilename)
26+
})
27+
})
28+
}
29+
30+
fetchSBOLObjectRecursive(uri, graphUri).then((result) => {
31+
sbol = result.sbol
32+
33+
console.log('-- converting to gff3')
34+
35+
return saveTempFile().then((tmpFilename) => {
36+
return convertToGFF3(tmpFilename, {
37+
38+
}).then((result) => {
39+
const { success, log, errorLog } = result
40+
41+
if (!success) {
42+
const locals = {
43+
config: config.get(),
44+
section: 'invalid',
45+
user: req.user,
46+
errors: [ errorLog ]
47+
}
48+
49+
return fs.unlink(tmpFilename).then(() => {
50+
res.send(pug.renderFile('templates/views/errors/invalid.jade', locals))
51+
})
52+
} else {
53+
return fs.unlink(tmpFilename).then(() => {
54+
res.header('content-type', 'text/plain').send(log)
55+
})
56+
// res.header('content-type', 'text/plain').send(log);
57+
}
58+
})
59+
})
60+
}).catch((err) => {
61+
if (err) {
62+
const locals = {
63+
config: config.get(),
64+
section: 'errors',
65+
user: req.user,
66+
errors: [ uri + ' Not Found' ]
67+
}
68+
69+
res.send(pug.renderFile('templates/views/errors/errors.jade', locals))
70+
}
71+
})
72+
}

lib/app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var api = {
6666
summary: require('./api/summary'),
6767
fasta: require('./api/fasta'),
6868
genBank: require('./api/genBank'),
69+
gff3: require('./api/gff3'),
6970
metadata: require('./api/metadata'),
7071
autocomplete: require('./api/autocomplete'),
7172
count: require('./api/count'),
@@ -385,6 +386,7 @@ function App () {
385386
app.get('/public/:collectionId/:displayId/:version/:filename.json', api.summary)
386387
app.get('/public/:collectionId/:displayId/:version/:filename.fasta', api.fasta)
387388
app.get('/public/:collectionId/:displayId/:version/:filename.gb', api.genBank)
389+
app.get('/public/:collectionId/:displayId/:version/:filename.gff', api.gff3)
388390
app.get('/public/:collectionId/:displayId/:version/sbol', api.sbol)
389391
app.get('/public/:collectionId/:displayId/:version/sbolnr', api.sbolnr)
390392
app.get('/public/:collectionId/:displayId/:version/metadata', api.metadata)
@@ -394,6 +396,7 @@ function App () {
394396
app.get('/user/:userId/:collectionId/:displayId/:version/:filename.json', api.summary)
395397
app.get('/user/:userId/:collectionId/:displayId/:version/:filename.fasta', api.fasta)
396398
app.get('/user/:userId/:collectionId/:displayId/:version/:filename.gb', api.genBank)
399+
app.get('/user/:userId/:collectionId/:displayId/:version/:filename.gff', api.gff3)
397400
app.get('/user/:userId/:collectionId/:displayId/:version/sbol', api.sbol)
398401
app.get('/user/:userId/:collectionId/:displayId/:version/sbolnr', api.sbolnr)
399402
app.get('/user/:userId/:collectionId/:displayId/:version/metadata', api.metadata)
@@ -403,6 +406,7 @@ function App () {
403406
app.get('/user/:userId/:collectionId/:displayId/:version/:hash/share/:filename.json', api.summary)
404407
app.get('/user/:userId/:collectionId/:displayId/:version/:hash/share/:filename.fasta', api.fasta)
405408
app.get('/user/:userId/:collectionId/:displayId/:version/:hash/share/:filename.gb', api.genBank)
409+
app.get('/user/:userId/:collectionId/:displayId/:version/:hash/share/:filename.gff', api.gff3)
406410
app.get('/user/:userId/:collectionId/:displayId/:version/:hash/share/sbol', api.sbol)
407411
app.get('/user/:userId/:collectionId/:displayId/:version/:hash/share/sbolnr', api.sbolnr)
408412
app.get('/user/:userId/:collectionId/:displayId/:version/:hash/share/metadata', api.metadata)

lib/conversion/convert-to-genbank.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ function convertToGenBank (inFilename, opts) {
1212
enforceBestPractices: config.get('requireBestPractice'),
1313
typesInURI: false,
1414
keepGoing: false,
15+
gff3Out: false,
1516
topLevelURI: ''
1617

1718
}, opts)
1819

1920
return java('convertToGenBank', opts).then((result) => {
20-
const { success, log, errorLog, resultFilename } = result
21+
// const { success, log, errorLog, resultFilename } = result
2122

2223
return Promise.resolve(result)
2324
})

lib/conversion/convert-to-gff3.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
const java = require('../java')
3+
const extend = require('xtend')
4+
const config = require('../config')
5+
6+
function convertToGFF3 (inFilename, opts) {
7+
opts = extend({
8+
9+
sbolFilename: inFilename,
10+
requireComplete: config.get('requireComplete'),
11+
requireCompliant: config.get('requireCompliant'),
12+
enforceBestPractices: config.get('requireBestPractice'),
13+
typesInURI: false,
14+
keepGoing: false,
15+
gff3Out: true,
16+
topLevelURI: ''
17+
18+
}, opts)
19+
20+
return java('convertToGenBank', opts).then((result) => {
21+
// const { success, log, errorLog, resultFilename } = result
22+
23+
return Promise.resolve(result)
24+
})
25+
}
26+
27+
module.exports = convertToGFF3

templates/layouts/topLevel.jade

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ block generalTopLevelButtons
1919
if rdfType.name == 'Component'
2020
li
2121
a(href=meta.url + '/' + meta.id + '.gb') Download GenBank
22+
if rdfType.name == 'Component'
23+
li
24+
a(href=meta.url + '/' + meta.id + '.gff') Download GFF3
2225
if rdfType.name == 'Component' || rdfType.name == 'Sequence'
2326
li
2427
a(href=meta.url + '/' + meta.id + '.fasta') Download FASTA

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/SBOLTestRunner/
22
/synbiohub-docker/
33
/SynBioHubRunner/
4+
/libSBOLj/
45

0 commit comments

Comments
 (0)