Skip to content

Commit

Permalink
Allow folder-level setting of 10x defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
bbimber committed Jan 31, 2024
1 parent 92b1f80 commit c181b87
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 3 deletions.
1 change: 1 addition & 0 deletions singlecell/resources/views/cDNAImport.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<dependencies>
<dependency path="laboratory.context" />
<dependency path="extWidgets/ExcelUploadPanel.js"/>
<dependency path="singlecell/panel/TenxSettingsPanel.js"/>
<dependency path="singlecell/panel/PoolImportPanel.js"/>
<dependency path="singlecell/panel/cDNAImportPanel.js"/>

Expand Down
1 change: 1 addition & 0 deletions singlecell/resources/views/poolImport.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<dependencies>
<dependency path="laboratory.context" />
<dependency path="extWidgets/ExcelUploadPanel.js"/>
<dependency path="singlecell/panel/TenxSettingsPanel.js"/>
<dependency path="singlecell/panel/PoolImportPanel.js"/>

<dependency path="internal/jQuery"/>
Expand Down
67 changes: 65 additions & 2 deletions singlecell/resources/web/singlecell/panel/PoolImportPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Ext4.define('SingleCell.panel.PoolImportPanel', {
name: 'assaytype',
labels: ['Assay Type', 'Assay Type', 'Assay', 'treatment'],
allowRowSpan: false,
alwaysShow: true,
allowBlank: false,
transform: 'assaytype'
},{
Expand Down Expand Up @@ -159,11 +160,16 @@ Ext4.define('SingleCell.panel.PoolImportPanel', {
},

assaytype: function(val, panel) {
var requireAssayType = panel.down('#requireAssayType').getValue();
if (val && (val === '--' || val === '-')) {
val = 'N/A';
val = null;
}

if (!requireAssayType && !val) {
return 'N/A';
}

return val || 'N/A';
return val;
},

subject: function(val, panel) {
Expand Down Expand Up @@ -387,6 +393,28 @@ Ext4.define('SingleCell.panel.PoolImportPanel', {
});

this.callParent(arguments);

Ext4.Msg.wait('Loading...');
LABKEY.Ajax.request({
method: 'POST',
url: LABKEY.ActionURL.buildURL('singlecell', 'getTenXImportDefaults'),
scope: this,
success: function(response){
LDK.Utils.decodeHttpResponseJson(response);
if (response.responseJSON){
this.configDefaults = response.responseJSON;
for (var name in this.configDefaults){
var item = this.down('#' + name);
if (item){
item.setValue(this.configDefaults[name]);
}
}

Ext4.Msg.hide();
}
},
failure: LDK.Utils.getErrorCallback()
});
},

getPanelItems: function(){
Expand Down Expand Up @@ -466,6 +494,31 @@ Ext4.define('SingleCell.panel.PoolImportPanel', {
linkCls: 'labkey-text-link',
href: LABKEY.ActionURL.buildURL('query', 'executeQuery', Laboratory.Utils.getQueryContainerPath(), {schemaName: 'singlecell', 'query.queryName': 'stim_types'}),
style: 'margin-top: 10px;'
}, {
xtype: 'ldk-linkbutton',
width: null,
hidden: !LABKEY.Security.currentUser.isAdmin,
text: 'Set Page Defaults',
itemId: 'copyPrevious',
linkCls: 'labkey-text-link',
scope: this,
handler: function (btn) {
Ext4.create('Ext.window.Window', {
title: 'Set Page Defaults',
items: [{
xtype: 'singlecell-tenxsettingspanel',
border: false,
hidePageLoadWarning: false,
hideButtons: true
}],
buttons: SingleCell.panel.TenxSettingsPanel.getButtons().concat([{
text: 'Cancel',
handler: function (btn) {
btn.up('window').close();
}
}])
}).show();
}
},{
xtype: 'textfield',
style: 'margin-top: 20px;',
Expand Down Expand Up @@ -506,6 +559,11 @@ Ext4.define('SingleCell.panel.PoolImportPanel', {
fieldLabel: 'Require Cite-Seq Library',
itemId: 'requireCITE',
checked: false
},{
xtype: 'checkbox',
fieldLabel: 'Require Assay Type',
itemId: 'requireAssayType',
checked: true
},{
xtype: 'checkbox',
fieldLabel: 'Combine Hashing and Cite-Seq Libraries',
Expand Down Expand Up @@ -1049,6 +1107,7 @@ Ext4.define('SingleCell.panel.PoolImportPanel', {
var data = [];
var missingValues = false;
var requireHTO = this.down('#requireHTO').getValue() || (this.down('#requireHashTag') && this.down('#requireHashTag').getValue());
var requireAssayType = this.down('#requireAssayType').getValue()
Ext4.Array.forEach(parsedRows, function(row, rowIdx){
var toAdd = [rowIdx + 1];
Ext4.Array.forEach(colIdxs, function(colIdx){
Expand All @@ -1060,6 +1119,10 @@ Ext4.define('SingleCell.panel.PoolImportPanel', {
allowBlank = false;
}

if (requireAssayType && colDef.name == 'assaytype') {
allowBlank = false;
}

if (allowBlank === false && Ext4.isEmpty(row[propName])){
missingValues = true;
toAdd.push('MISSING');
Expand Down
94 changes: 94 additions & 0 deletions singlecell/resources/web/singlecell/panel/TenxSettingsPanel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Ext4.define('SingleCell.panel.TenxSettingsPanel', {
extend: 'Ext.panel.Panel',
alias: 'widget.singlecell-tenxsettingspanel',

hidePageLoadWarning: true,
hideButtons: false,
maxWidth: 650,

initComponent: function(){
Ext4.applyIf(this, {
bodyStyle: 'padding: 5px;',
items: [{
html: 'Loading...',
border: false
}],
buttons: this.hideButtons ? null : SingleCell.panel.TenxSettingsPanel.getButtons()
});

this.callParent(arguments);

LABKEY.Ajax.request({
method: 'POST',
url: LABKEY.ActionURL.buildURL('singlecell', 'getTenXImportDefaults'),
scope: this,
success: this.onDataLoad,
failure: LDK.Utils.getErrorCallback()
});
},

onDataLoad: function(response){
LDK.Utils.decodeHttpResponseJson(response);
this.removeAll();

if (response.responseJSON){
var configDefaults = response.responseJSON;
var items = [{
html: 'Note: you must reload this page before any change will be applied.',
border: false,
hidden: !!this.hidePageLoadWarning
},{
xtype: 'checkbox',
fieldLabel: 'Require Assay Type',
labelWidth: 300,
itemId: 'requireAssayType',
checked: !!JSON.parse(configDefaults.requireAssayType)
},{
xtype: 'checkbox',
fieldLabel: 'Combine Hashing and Cite-Seq',
labelWidth: 300, itemId: 'combineHashingCite',
checked: !!JSON.parse(configDefaults.combineHashingCite)
}];

this.add(items);
}
else {
this.add({html: 'Something went wrong loading saved data'});
}
},

statics: {
getButtons: function () {
return [{
text: 'Submit',
handler: function (btn) {
var win = btn.up('window');
var panel = win ? win.down('singlecell-tenxsettingspanel') : btn.up('singlecell-tenxsettingspanel');

var params = {};
params['requireAssayType'] = panel.down('#requireAssayType').getValue();
params['combineHashingCite'] = panel.down('#combineHashingCite').getValue();

Ext4.Msg.wait('Saving...');
LABKEY.Ajax.request({
method: 'POST',
url: LABKEY.ActionURL.buildURL('singlecell', 'setTenXImportDefaults'),
jsonData: params,
scope: panel,
success: panel.onSuccess,
failure: LDK.Utils.getErrorCallback()
})
}
}];
}
},

onSuccess: function(){
Ext4.Msg.hide();
Ext4.Msg.alert('Success', 'Settings have been saved');

if (this.up('window')){
this.up('window').close();
}
}
});
27 changes: 26 additions & 1 deletion singlecell/resources/web/singlecell/panel/cDNAImportPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,32 @@ Ext4.define('SingleCell.panel.cDNAImportPanel', {
scope: this,
href: LABKEY.ActionURL.getContextPath() + '/singlecell/exampleData/ImportReadsetTemplate.xlsx'
}]
}, {
},{
xtype: 'ldk-linkbutton',
hidden: !LABKEY.Security.currentUser.isAdmin,
style: 'margin-top: 10px;',
text: 'Set Page Defaults',
itemId: 'copyPrevious',
linkCls: 'labkey-text-link',
scope: this,
handler: function (btn) {
Ext4.create('Ext.window.Window', {
title: 'Set Page Defaults',
items: [{
xtype: 'singlecell-tenxsettingspanel',
border: false,
hidePageLoadWarning: false,
hideButtons: true
}],
buttons: SingleCell.panel.TenxSettingsPanel.getButtons().concat([{
text: 'Cancel',
handler: function (btn) {
btn.up('window').close();
}
}])
}).show();
}
},{
xtype: 'textfield',
style: 'margin-top: 20px;',
fieldLabel: 'Expt Number',
Expand Down
63 changes: 63 additions & 0 deletions singlecell/src/org/labkey/singlecell/SingleCellController.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONArray;
import org.labkey.api.action.ApiResponse;
import org.labkey.api.action.ApiSimpleResponse;
import org.labkey.api.action.ApiUsageException;
import org.labkey.api.action.ExportAction;
Expand All @@ -35,6 +36,7 @@
import org.labkey.api.data.ContainerManager;
import org.labkey.api.data.ContainerType;
import org.labkey.api.data.DbScope;
import org.labkey.api.data.PropertyManager;
import org.labkey.api.data.SimpleFilter;
import org.labkey.api.data.TableInfo;
import org.labkey.api.data.TableSelector;
Expand All @@ -47,6 +49,7 @@
import org.labkey.api.query.UserSchema;
import org.labkey.api.security.RequiresPermission;
import org.labkey.api.security.User;
import org.labkey.api.security.permissions.AdminPermission;
import org.labkey.api.security.permissions.InsertPermission;
import org.labkey.api.security.permissions.ReadPermission;
import org.labkey.api.sequenceanalysis.SequenceOutputFile;
Expand Down Expand Up @@ -494,4 +497,64 @@ public void addNavTrail(NavTree tree)
}
}

public final static String CONFIG_PROPERTY_DOMAIN_IMPORT = "org.labkey.singlecell.importsettings";

@RequiresPermission(ReadPermission.class)
public static class GetTenXImportDefaultsAction extends ReadOnlyApiAction<Object>
{
@Override
public ApiResponse execute(Object form, BindException errors) throws Exception
{
Container target = getContainer().isWorkbook() ? getContainer().getParent() : getContainer();
Map<String, Object> resultProperties = new HashMap<>(PropertyManager.getProperties(target, CONFIG_PROPERTY_DOMAIN_IMPORT));

return new ApiSimpleResponse(resultProperties);
}
}

@RequiresPermission(AdminPermission.class)
public static class SetTenXImportDefaultsAction extends MutatingApiAction<SetSequenceImportDefaultsForm>
{
public static final String REQUIRE_ASSAY_TYPE = "requireAssayType";
public static final String COMBINE_HASHING_CITE = "combineHashingCite";

@Override
public ApiResponse execute(SetSequenceImportDefaultsForm form, BindException errors) throws Exception
{
Container target = getContainer().isWorkbook() ? getContainer().getParent() : getContainer();
PropertyManager.PropertyMap configMap = PropertyManager.getWritableProperties(target, CONFIG_PROPERTY_DOMAIN_IMPORT, true);
configMap.put(REQUIRE_ASSAY_TYPE, Boolean.valueOf(form.isRequireAssayType()).toString());
configMap.put(COMBINE_HASHING_CITE, Boolean.valueOf(form.isCombineHashingCite()).toString());

configMap.save();

return new ApiSimpleResponse("success", true);
}
}

public static class SetSequenceImportDefaultsForm
{
private boolean _requireAssayType = false;
private boolean _combineHashingCite = false;

public boolean isRequireAssayType()
{
return _requireAssayType;
}

public void setRequireAssayType(boolean requireAssayType)
{
_requireAssayType = requireAssayType;
}

public boolean isCombineHashingCite()
{
return _combineHashingCite;
}

public void setCombineHashingCite(boolean combineHashingCite)
{
_combineHashingCite = combineHashingCite;
}
}
}

0 comments on commit c181b87

Please sign in to comment.