Skip to content

Commit b8b5456

Browse files
authored
Finalize implementation of fields/groups provider (#209)
* Use JBrowse fields API to drive details popup and restore VariantTable
1 parent c219bf8 commit b8b5456

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1870
-822
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.labkey.api.studies;
2+
3+
import org.labkey.api.data.Container;
4+
import org.labkey.api.module.Module;
5+
import org.labkey.api.security.User;
6+
import org.labkey.api.util.Path;
7+
8+
import java.io.IOException;
9+
10+
/**
11+
* Created by bimber on 11/3/2016.
12+
*/
13+
abstract public class StudiesService
14+
{
15+
static StudiesService _instance;
16+
17+
public static StudiesService get()
18+
{
19+
return _instance;
20+
}
21+
22+
static public void setInstance(StudiesService instance)
23+
{
24+
_instance = instance;
25+
}
26+
27+
abstract public void importFolderDefinition(Container container, User user, Module m, Path sourceFolderDirPath) throws IOException;
28+
}

Studies/src/org/labkey/studies/StudiesModule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.labkey.api.data.Container;
66
import org.labkey.api.module.DefaultModule;
77
import org.labkey.api.module.ModuleContext;
8+
import org.labkey.api.studies.StudiesService;
89
import org.labkey.api.view.WebPartFactory;
910

1011
import java.util.Collection;
@@ -44,6 +45,8 @@ protected Collection<WebPartFactory> createWebPartFactories()
4445
protected void init()
4546
{
4647
addController(StudiesController.NAME, StudiesController.class);
48+
49+
StudiesService.setInstance(StudiesServiceImpl.get());
4750
}
4851

4952
@Override
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package org.labkey.studies;
2+
3+
import org.apache.logging.log4j.Logger;
4+
import org.labkey.api.admin.ImportOptions;
5+
import org.labkey.api.data.Container;
6+
import org.labkey.api.module.Module;
7+
import org.labkey.api.pipeline.PipeRoot;
8+
import org.labkey.api.pipeline.PipelineService;
9+
import org.labkey.api.resource.DirectoryResource;
10+
import org.labkey.api.resource.Resource;
11+
import org.labkey.api.security.User;
12+
import org.labkey.api.studies.StudiesService;
13+
import org.labkey.api.util.FileUtil;
14+
import org.labkey.api.util.Path;
15+
import org.labkey.api.util.logging.LogHelper;
16+
17+
import java.io.FileNotFoundException;
18+
import java.io.IOException;
19+
import java.io.InputStream;
20+
import java.io.OutputStream;
21+
import java.nio.file.Files;
22+
23+
public class StudiesServiceImpl extends StudiesService
24+
{
25+
private static final StudiesServiceImpl _instance = new StudiesServiceImpl();
26+
private static final Logger _log = LogHelper.getLogger(StudiesServiceImpl.class, "StudiesService messages");
27+
28+
public static StudiesServiceImpl get()
29+
{
30+
return _instance;
31+
}
32+
33+
private StudiesServiceImpl()
34+
{
35+
36+
}
37+
38+
@Override
39+
public void importFolderDefinition(Container container, User user, Module m, Path sourceFolderDirPath) throws IOException
40+
{
41+
Resource root = m.getModuleResource(sourceFolderDirPath);
42+
PipeRoot pipeRoot = PipelineService.get().findPipelineRoot(container);
43+
java.nio.file.Path pipeRootPath = pipeRoot.getRootNioPath();
44+
45+
java.nio.file.Path folderXmlPath;
46+
47+
if (root instanceof DirectoryResource && ((DirectoryResource)root).getDir().equals(pipeRootPath.toFile()))
48+
{
49+
// The pipeline root is already pointed at the folder definition, like it might be on a dev machine.
50+
// No need to copy, especially since copying can cause infinite recursion when the paths are nested
51+
folderXmlPath = pipeRootPath.resolve("folder.xml");
52+
}
53+
else
54+
{
55+
java.nio.file.Path folderPath = pipeRootPath.resolve("moduleFolderImport");
56+
folderXmlPath = folderPath.resolve("folder.xml");
57+
if (Files.exists(folderPath))
58+
{
59+
FileUtil.deleteDir(folderPath);
60+
}
61+
copyResourceToPath(root, folderPath);
62+
}
63+
64+
if (!Files.exists(folderXmlPath))
65+
{
66+
throw new FileNotFoundException("Couldn't find an extracted " + folderXmlPath);
67+
}
68+
ImportOptions options = new ImportOptions(container.getId(), user.getUserId());
69+
options.setSkipQueryValidation(true);
70+
71+
PipelineService.get().runFolderImportJob(container, user, null, folderXmlPath, "folder.xml", pipeRoot, options);
72+
}
73+
74+
private void copyResourceToPath(Resource resource, java.nio.file.Path target) throws IOException
75+
{
76+
if (resource.isCollection())
77+
{
78+
Files.createDirectory(target);
79+
for (Resource child : resource.list())
80+
{
81+
java.nio.file.Path childTarget = target.resolve(child.getName());
82+
copyResourceToPath(child, childTarget);
83+
}
84+
}
85+
else
86+
{
87+
try (InputStream in = resource.getInputStream();
88+
OutputStream out = Files.newOutputStream(target))
89+
{
90+
FileUtil.copyData(in, out);
91+
}
92+
}
93+
}
94+
}

jbrowse/api-src/org/labkey/api/jbrowse/GroupsProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
import org.labkey.api.data.Container;
55
import org.labkey.api.security.User;
66

7-
import java.util.Set;
7+
import java.util.List;
88

99
public interface GroupsProvider
1010
{
11-
@Nullable Set<String> getGroupMembers(String groupName, Container c, User u);
12-
boolean hasGroup(String groupName, Container c, User u);
11+
@Nullable List<String> getGroupMembers(String trackId, String groupName, Container c, User u);
1312
boolean isAvailable(Container c, User u);
1413
}

jbrowse/api-src/org/labkey/api/jbrowse/JBrowseFieldCustomizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.labkey.api.security.User;
55

66
public interface JBrowseFieldCustomizer {
7-
public void customizeField(JBrowseFieldDescriptor field);
7+
public void customizeField(JBrowseFieldDescriptor field, Container c, User u);
88

99
public boolean isAvailable(Container c, User u);
1010
}

jbrowse/api-src/org/labkey/api/jbrowse/JBrowseFieldDescriptor.java

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@ public class JBrowseFieldDescriptor {
1111
private final String _fieldName;
1212
private final VCFHeaderLineType _type;
1313
private String _label;
14-
private final String _description;
15-
private final boolean _isInDefaultColumns;
16-
private final boolean _isIndexed;
14+
private String _description;
15+
private boolean _isInDefaultColumns;
16+
private boolean _isIndexed;
1717
private boolean _isMultiValued = false;
1818
private List<String> _allowableValues = null;
1919
private boolean _isHidden = false;
2020
private String _colWidth = null;
21-
private Integer _orderKey = null;
21+
private Integer _orderKey = 8;
2222

2323
// NOTE: this should support "jexl:xxxxxx" syntax, like other JBrowse formatting
2424
private String _formatString = null;
25+
private String _category = null;
26+
private String _url = null;
2527

2628
public JBrowseFieldDescriptor(String luceneFieldName, @Nullable String description, boolean isInDefaultColumns, boolean isIndexed, VCFHeaderLineType type, Integer orderKey) {
2729
_fieldName = luceneFieldName;
@@ -49,7 +51,14 @@ public JBrowseFieldDescriptor formatString(String formatString) {
4951
}
5052

5153
public JBrowseFieldDescriptor allowableValues(List<String> allowableValues) {
52-
_allowableValues = Collections.unmodifiableList(allowableValues);
54+
_allowableValues = allowableValues == null ? null : Collections.unmodifiableList(allowableValues);
55+
56+
// Only change the value if we are certain there are multiple values:
57+
if (_allowableValues != null && !_allowableValues.isEmpty())
58+
{
59+
_isMultiValued = true;
60+
}
61+
5362
return this;
5463
}
5564

@@ -103,6 +112,21 @@ public void setLabel(String label) {
103112
_label = label;
104113
}
105114

115+
public void setInDefaultColumns(boolean inDefaultColumns)
116+
{
117+
_isInDefaultColumns = inDefaultColumns;
118+
}
119+
120+
public void setCategory(String category)
121+
{
122+
_category = category;
123+
}
124+
125+
public void setUrl(String url)
126+
{
127+
_url = url;
128+
}
129+
106130
public void setMultiValued(boolean multiValued) {
107131
_isMultiValued = multiValued;
108132
}
@@ -111,6 +135,10 @@ public void setHidden(boolean hidden) {
111135
_isHidden = hidden;
112136
}
113137

138+
public void setIndexed(boolean indexed) {
139+
_isIndexed = indexed;
140+
}
141+
114142
public void setColWidth(String colWidth) {
115143
_colWidth = colWidth;
116144
}
@@ -119,6 +147,21 @@ public void setOrderKey(Integer orderKey) {
119147
_orderKey = orderKey;
120148
}
121149

150+
public void setAllowableValues(List<String> allowableValues)
151+
{
152+
_allowableValues = allowableValues;
153+
}
154+
155+
public void setFormatString(String formatString)
156+
{
157+
_formatString = formatString;
158+
}
159+
160+
public void setDescription(String description)
161+
{
162+
_description = description;
163+
}
164+
122165
public JSONObject toJSON() {
123166
JSONObject fieldDescriptorJSON = new JSONObject();
124167
fieldDescriptorJSON.put("name", _fieldName);
@@ -133,6 +176,8 @@ public JSONObject toJSON() {
133176
fieldDescriptorJSON.put("formatString", _formatString);
134177
fieldDescriptorJSON.put("orderKey", _orderKey);
135178
fieldDescriptorJSON.put("allowableValues", _allowableValues);
179+
fieldDescriptorJSON.put("category", _category);
180+
fieldDescriptorJSON.put("url", _url);
136181

137182
return fieldDescriptorJSON;
138183
}

jbrowse/package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jbrowse/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@jbrowse/plugin-linear-genome-view": "^1.7.4",
2828
"@jbrowse/react-linear-genome-view": "^1.7.4",
2929
"@labkey/api": "^1.21.0",
30-
"@labkey/components": "^2.345.0",
30+
"@labkey/components": "^2.351.0",
3131
"@gmod/vcf": "^5.0.6",
3232
"react": "^16.14.0",
3333
"assert": "^2.0.0",

jbrowse/resources/external/mGAPSession.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
{
3636
"type": "ExtendedVariantTrack",
3737
"trackId": "mgap_hg38",
38-
"name": "mgap",
38+
"name": "mGAP",
3939
"assemblyNames": [
4040
"hg38"
4141
],

jbrowse/src/client/JBrowse/Browser/Browser.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import '../jbrowse.css';
88
import JBrowseFooter from './components/JBrowseFooter';
99
import { ErrorBoundary } from '@labkey/components';
1010
import { fetchSession } from '../utils';
11+
import JBrowseFilterPanel from './components/JBrowseFilterPanel';
1112

1213
const nativePlugins = [ExtendedVariantPlugin, LogSession]
1314
const refTheme = createTheme()
@@ -39,20 +40,22 @@ function View(){
3940
}, []);
4041

4142
if (session === null){
42-
return(<p>Error - no session provided.</p>)
43+
return (<p>Error - no session provided.</p>)
4344
}
4445
else if (state === null){
4546
return (<p>Loading...</p>)
4647
}
4748
else if (state == "invalid") {
4849
return (<p>Error fetching config. See console for more details</p>)
4950
}
51+
5052
return (
5153
//TODO: can we make this expand to full page height?
5254
<div style={{height: "100%"}}>
5355
<ErrorBoundary>
5456
<JBrowseLinearGenomeView viewState={state as ViewModel} />
5557
<JBrowseFooter viewState={state} bgColor={bgColor}/>
58+
<JBrowseFilterPanel session={state.session}/>
5659
</ErrorBoundary>
5760
</div>
5861
)

0 commit comments

Comments
 (0)