Skip to content

Commit c490846

Browse files
committed
updated JBrowseController to serve minimalSession on demo request
1 parent 84d0e43 commit c490846

File tree

2 files changed

+147
-1
lines changed

2 files changed

+147
-1
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"configuration": {},
3+
"assemblies":
4+
{
5+
"name": "hg38",
6+
"aliases": ["GRCh38"],
7+
"sequence": {
8+
"type": "ReferenceSequenceTrack",
9+
"trackId": "P6R5xbRqRr",
10+
"adapter": {
11+
"type": "BgzipFastaAdapter",
12+
"fastaLocation": {
13+
"uri": "https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz"
14+
},
15+
"faiLocation": {
16+
"uri": "https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz.fai"
17+
},
18+
"gziLocation": {
19+
"uri": "https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz.gzi"
20+
}
21+
}
22+
},
23+
"refNameAliases": {
24+
"adapter": {
25+
"type": "RefNameAliasAdapter",
26+
"location": {
27+
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/hg38_aliases.txt"
28+
}
29+
}
30+
}
31+
},
32+
"tracks": [
33+
{
34+
"type": "VariantTrack",
35+
"trackId": "clinvar_ncbi_hg38",
36+
"name": "ClinVar variants (NCBI)",
37+
"assemblyNames": ["hg38"],
38+
"category": ["Annotation"],
39+
"adapter": {
40+
"type": "VcfTabixAdapter",
41+
"vcfGzLocation": {
42+
"uri": "https://ftp.ncbi.nlm.nih.gov/pub/clinvar/vcf_GRCh38/clinvar.vcf.gz"
43+
},
44+
"index": {
45+
"location": {
46+
"uri": "https://ftp.ncbi.nlm.nih.gov/pub/clinvar/vcf_GRCh38/clinvar.vcf.gz.tbi"
47+
}
48+
}
49+
}
50+
},
51+
{
52+
"type": "FeatureTrack",
53+
"trackId": "ncbi_refseq_109_hg38_latest",
54+
"name": "NCBI RefSeq (GFF3Tabix)",
55+
"assemblyNames": ["hg38"],
56+
"category": ["Annotation"],
57+
"adapter": {
58+
"type": "Gff3TabixAdapter",
59+
"gffGzLocation": {
60+
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GRCh38_latest_genomic.sort.gff.gz"
61+
},
62+
"index": {
63+
"location": {
64+
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GRCh38_latest_genomic.sort.gff.gz.tbi"
65+
}
66+
}
67+
}
68+
}
69+
],
70+
"connections": []
71+
}

jbrowse/src/org/labkey/jbrowse/JBrowseController.java

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616

1717
package org.labkey.jbrowse;
1818

19+
import com.google.gson.stream.JsonReader;
1920
import htsjdk.samtools.util.CloseableIterator;
2021
import htsjdk.variant.variantcontext.Genotype;
2122
import htsjdk.variant.variantcontext.VariantContext;
2223
import htsjdk.variant.vcf.VCFFileReader;
24+
import org.apache.commons.io.IOUtils;
2325
import org.apache.commons.lang3.StringUtils;
2426
import org.jetbrains.annotations.NotNull;
2527
import org.json.JSONArray;
2628
import org.json.JSONObject;
29+
import org.json.JSONTokener;
2730
import org.labkey.api.action.ApiResponse;
2831
import org.labkey.api.action.ApiSimpleResponse;
2932
import org.labkey.api.action.MutatingApiAction;
@@ -45,12 +48,15 @@
4548
import org.labkey.api.data.TableInfo;
4649
import org.labkey.api.data.TableSelector;
4750
import org.labkey.api.exp.api.ExpData;
51+
import org.labkey.api.module.Module;
52+
import org.labkey.api.module.ModuleLoader;
4853
import org.labkey.api.pipeline.PipeRoot;
4954
import org.labkey.api.pipeline.PipelineService;
5055
import org.labkey.api.pipeline.PipelineValidationException;
5156
import org.labkey.api.query.FieldKey;
5257
import org.labkey.api.query.QueryService;
5358
import org.labkey.api.query.UserSchema;
59+
import org.labkey.api.resource.FileResource;
5460
import org.labkey.api.security.RequiresPermission;
5561
import org.labkey.api.security.permissions.AdminOperationsPermission;
5662
import org.labkey.api.security.permissions.AdminPermission;
@@ -59,6 +65,7 @@
5965
import org.labkey.api.security.permissions.UpdatePermission;
6066
import org.labkey.api.util.ExceptionUtil;
6167
import org.labkey.api.util.PageFlowUtil;
68+
import org.labkey.api.util.Path;
6269
import org.labkey.api.view.JspView;
6370
import org.labkey.api.view.NavTree;
6471
import org.labkey.api.view.UnauthorizedException;
@@ -67,11 +74,17 @@
6774
import org.labkey.jbrowse.model.Database;
6875
import org.labkey.jbrowse.model.JsonFile;
6976
import org.labkey.jbrowse.pipeline.JBrowseSessionPipelineJob;
77+
import org.labkey.sequenceanalysis.SequenceAnalysisModule;
7078
import org.springframework.validation.BindException;
7179
import org.springframework.validation.Errors;
7280
import org.springframework.web.servlet.ModelAndView;
7381

82+
import java.io.File;
83+
import java.io.FileInputStream;
7484
import java.io.IOException;
85+
import java.io.FileNotFoundException;
86+
import java.io.InputStream;
87+
import java.nio.charset.StandardCharsets;
7588
import java.sql.SQLException;
7689
import java.util.ArrayList;
7790
import java.util.Arrays;
@@ -82,6 +95,9 @@
8295
import java.util.Map;
8396
import java.util.Set;
8497

98+
99+
import java.nio.file.Files;
100+
85101
public class JBrowseController extends SpringActionController
86102
{
87103
private static final DefaultActionResolver _actionResolver = new DefaultActionResolver(JBrowseController.class);
@@ -704,4 +720,63 @@ public void setStop(Integer stop)
704720
_stop = stop;
705721
}
706722
}
707-
}
723+
724+
public static class GetSessionForm
725+
{
726+
private String session;
727+
728+
public String getSession()
729+
{
730+
return session;
731+
}
732+
733+
public void setSession(String session)
734+
{
735+
this.session = session;
736+
}
737+
}
738+
739+
@RequiresPermission(ReadPermission.class)
740+
public class GetSessionAction extends ReadOnlyApiAction<GetSessionForm>
741+
{
742+
private static final String DEMO = "demo";
743+
744+
@Override
745+
public void validateForm(GetSessionForm form, Errors errors)
746+
{
747+
if (StringUtils.isEmpty(form.getSession()))
748+
{
749+
errors.reject(ERROR_MSG, "Must provide the session Id");
750+
}
751+
}
752+
753+
@Override
754+
public Object execute(GetSessionForm form, BindException errors) throws Exception
755+
{
756+
JSONObject resp;
757+
if (DEMO.equalsIgnoreCase(form.getSession()))
758+
{
759+
Module module = ModuleLoader.getInstance().getModule(JBrowseModule.class);
760+
FileResource r = (FileResource)module.getModuleResolver().lookup(Path.parse("external/minimalSession.json"));
761+
File jsonFile = r.getFile();
762+
if (jsonFile == null)
763+
{
764+
throw new FileNotFoundException("Unable to find JSON file: external/minimalSession.json");
765+
}
766+
767+
768+
try (InputStream is = new FileInputStream(jsonFile))
769+
{
770+
resp = new JSONObject(IOUtils.toString(is, StandardCharsets.UTF_8));
771+
}
772+
}
773+
else
774+
{
775+
resp = null;
776+
}
777+
778+
return new ApiSimpleResponse(resp);
779+
}
780+
}
781+
}
782+

0 commit comments

Comments
 (0)