Skip to content

Commit 7372d4a

Browse files
committed
Improve 10x import to allow iterative import of readset without duplicating
1 parent cf44a60 commit 7372d4a

File tree

2 files changed

+119
-71
lines changed

2 files changed

+119
-71
lines changed

singlecell/resources/web/singlecell/panel/PoolImportPanel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ Ext4.define('SingleCell.panel.PoolImportPanel', {
946946

947947
readsetRows.push({
948948
name: poolName + '-' + (nameSuffix || type),
949+
plateId: poolName,
949950
barcode5: isDualIndex ? idxValues[0] + '_F' : idxValues[0],
950951
barcode3: isDualIndex ? idxValues[0] + '_R' : null,
951952
concentration: conc[0],

singlecell/resources/web/singlecell/panel/cDNAImportPanel.js

Lines changed: 118 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ Ext4.define('SingleCell.panel.cDNAImportPanel', {
281281
containerPath: Laboratory.Utils.getQueryContainerPath(),
282282
schemaName: 'singlecell',
283283
queryName: 'cdna_libraries',
284-
columns: 'rowid,plateid',
284+
columns: 'rowid,plateid,readsetId,tcrReadsetId,hashingReadsetId,citeseqReadsetId',
285285
filterArray: [LABKEY.Filter.create('plateId', plateIDs.join(';'), LABKEY.Filter.Types.IN)],
286286
scope: this,
287287
success: function(results) {
@@ -295,7 +295,7 @@ Ext4.define('SingleCell.panel.cDNAImportPanel', {
295295
var plateToCDNAMap = {};
296296
Ext4.Array.forEach(results.rows, function(row) {
297297
plateToCDNAMap[row.plateId] = plateToCDNAMap[row.plateId] || [];
298-
plateToCDNAMap[row.plateId].push(row.rowid);
298+
plateToCDNAMap[row.plateId].push(row);
299299
}, this);
300300

301301
var missing = [];
@@ -310,8 +310,38 @@ Ext4.define('SingleCell.panel.cDNAImportPanel', {
310310
return;
311311
}
312312

313+
function getUnique(value, index, self) {
314+
return self.indexOf(value) === index;
315+
}
316+
313317
Ext4.Array.forEach(groupedRows.cDNARows, function(r){
314-
r.rowIds = plateToCDNAMap[r.plateId];
318+
r.rowIds = plateToCDNAMap[r.plateId] ? plateToCDNAMap[r.plateId].map(r => r.rowid) : null;
319+
r.readsetId = plateToCDNAMap[r.plateId] ? plateToCDNAMap[r.plateId].map(r => r.readsetId).filter(r => !!r).filter(getUnique).join('') : null;
320+
r.tcrReadsetId = plateToCDNAMap[r.plateId] ? plateToCDNAMap[r.plateId].map(r => r.tcrReadsetId).filter(r => !!r).filter(getUnique).join('') : null;
321+
r.hashingReadsetId = plateToCDNAMap[r.plateId] ? plateToCDNAMap[r.plateId].map(r => r.hashingReadsetId).filter(r => !!r).filter(getUnique).join('') : null;
322+
r.citeseqReadsetId = plateToCDNAMap[r.plateId] ? plateToCDNAMap[r.plateId].map(r => r.citeseqReadsetId).filter(r => !!r).filter(getUnique).join('') : null;
323+
}, this);
324+
325+
Ext4.Array.forEach(groupedRows.readsetRows, function(r){
326+
var fieldName;
327+
if (r.application === 'CITE-Seq') {
328+
fieldName = 'citeseqReadsetId';
329+
}
330+
else if (r.application === 'Cell Hashing') {
331+
fieldName = 'hashingReadsetId';
332+
}
333+
else if (r.librarytype === '10x 5\' GEX') {
334+
fieldName = 'readsetId';
335+
}
336+
else if (r.librarytype === '10x 5\' VDJ (Rhesus A/B/D/G)') {
337+
fieldName = 'tcrReadsetId';
338+
}
339+
else {
340+
console.error('Unknown row type')
341+
console.error(row)
342+
}
343+
344+
r.doInsert = !(plateToCDNAMap[r.plateId] ? plateToCDNAMap[r.plateId].map(r => r[fieldName]).filter(r => !!r).filter(getUnique).join('') : null);
315345
}, this);
316346

317347
this.renderPreview(colArray, parsedRows, groupedRows);
@@ -324,74 +354,91 @@ Ext4.define('SingleCell.panel.cDNAImportPanel', {
324354
Ext4.Msg.wait('Saving...');
325355

326356
var data = config.rowData.groupedRows;
327-
328-
LABKEY.Query.insertRows({
329-
containerPath: Laboratory.Utils.getQueryContainerPath(),
330-
schemaName: 'sequenceanalysis',
331-
queryName: 'sequence_readsets',
332-
rows: data.readsetRows,
333-
success: function(results){
334-
var readsetMap = {};
335-
Ext4.Array.forEach(results.rows, function(row){
336-
readsetMap[row.name] = row.rowId;
337-
}, this);
338-
339-
var toUpdate = [];
340-
Ext4.Array.forEach(data.cDNARows, function(row){
341-
var baseRow = {};
342-
343-
var gexReadsetId = readsetMap[row.plateId + '-GEX'];
344-
if (gexReadsetId) {
345-
baseRow.readsetId = gexReadsetId;
346-
}
347-
348-
var tcrReadsetId = readsetMap[row.plateId + '-TCR'];
349-
if (tcrReadsetId) {
350-
baseRow.tcrReadsetId = tcrReadsetId;
351-
}
352-
353-
var htoReadsetId = readsetMap[row.plateId + '-HTO'];
354-
if (htoReadsetId) {
355-
baseRow.hashingReadsetId = htoReadsetId;
356-
}
357-
358-
var citeseqReadsetId = readsetMap[row.plateId + '-CITE'];
359-
if (citeseqReadsetId) {
360-
baseRow.citeseqReadsetId = citeseqReadsetId;
361-
}
362-
363-
baseRow.container = row.container;
364-
365-
if (row.rowIds) {
366-
Ext4.Array.forEach(row.rowIds, function(r){
367-
var toAdd = Ext4.apply({
368-
rowId: r
369-
}, baseRow);
370-
371-
toUpdate.push(toAdd);
372-
}, this);
373-
}
374-
}, this);
375-
376-
if (toUpdate.length) {
377-
LABKEY.Query.updateRows({
378-
containerPath: Laboratory.Utils.getQueryContainerPath(),
379-
schemaName: 'singlecell',
380-
queryName: 'cdna_libraries',
381-
rows: toUpdate,
382-
success: function (results) {
383-
Ext4.Msg.hide();
384-
Ext4.Msg.alert('Success', 'Data Saved', function(){
385-
window.location = LABKEY.ActionURL.buildURL('query', 'executeQuery.view', Laboratory.Utils.getQueryContainerPath(), {'query.queryName': 'cdna_libraries', schemaName: 'singlecell', 'query.sort': '-created'});
357+
var toInsert = data.readsetRows.filter(r => r.doInsert)
358+
if (!toInsert.length) {
359+
Ext4.Msg.hide();
360+
Ext4.Msg.alert('Success', 'Data Saved', function(){
361+
window.location = LABKEY.ActionURL.buildURL('query', 'executeQuery.view', Laboratory.Utils.getQueryContainerPath(), {'query.queryName': 'cdna_libraries', schemaName: 'singlecell', 'query.sort': '-created'});
362+
}, this);
363+
}
364+
else {
365+
LABKEY.Query.insertRows({
366+
containerPath: Laboratory.Utils.getQueryContainerPath(),
367+
schemaName: 'sequenceanalysis',
368+
queryName: 'sequence_readsets',
369+
rows: toInsert,
370+
success: function (results) {
371+
var readsetMap = {};
372+
Ext4.Array.forEach(results.rows, function (row) {
373+
readsetMap[row.name] = row.rowId;
374+
}, this);
375+
376+
var toUpdate = [];
377+
Ext4.Array.forEach(data.cDNARows, function (row) {
378+
var baseRow = {
379+
readsetId: row.readsetId,
380+
tcrReadsetId: row.tcrReadsetId,
381+
hashingReadsetId: row.hashingReadsetId,
382+
citeseqReadsetId: row.citeseqReadsetId
383+
};
384+
385+
var gexReadsetId = readsetMap[row.plateId + '-GEX'];
386+
if (gexReadsetId) {
387+
baseRow.readsetId = gexReadsetId;
388+
}
389+
390+
var tcrReadsetId = readsetMap[row.plateId + '-TCR'];
391+
if (tcrReadsetId) {
392+
baseRow.tcrReadsetId = tcrReadsetId;
393+
}
394+
395+
var htoReadsetId = readsetMap[row.plateId + '-HTO'];
396+
if (htoReadsetId) {
397+
baseRow.hashingReadsetId = htoReadsetId;
398+
}
399+
400+
var citeseqReadsetId = readsetMap[row.plateId + '-CITE'];
401+
if (citeseqReadsetId) {
402+
baseRow.citeseqReadsetId = citeseqReadsetId;
403+
}
404+
405+
baseRow.container = row.container;
406+
407+
if (row.rowIds) {
408+
Ext4.Array.forEach(row.rowIds, function (r) {
409+
var toAdd = Ext4.apply({
410+
rowId: r
411+
}, baseRow);
412+
413+
toUpdate.push(toAdd);
386414
}, this);
387-
},
388-
failure: LDK.Utils.getErrorCallback(),
389-
scope: this
390-
});
391-
}
392-
},
393-
failure: LDK.Utils.getErrorCallback(),
394-
scope: this
395-
});
415+
}
416+
}, this);
417+
418+
if (toUpdate.length) {
419+
LABKEY.Query.updateRows({
420+
containerPath: Laboratory.Utils.getQueryContainerPath(),
421+
schemaName: 'singlecell',
422+
queryName: 'cdna_libraries',
423+
rows: toUpdate,
424+
success: function (results) {
425+
Ext4.Msg.hide();
426+
Ext4.Msg.alert('Success', 'Data Saved', function () {
427+
window.location = LABKEY.ActionURL.buildURL('query', 'executeQuery.view', Laboratory.Utils.getQueryContainerPath(), {
428+
'query.queryName': 'cdna_libraries',
429+
schemaName: 'singlecell',
430+
'query.sort': '-created'
431+
});
432+
}, this);
433+
},
434+
failure: LDK.Utils.getErrorCallback(),
435+
scope: this
436+
});
437+
}
438+
},
439+
failure: LDK.Utils.getErrorCallback(),
440+
scope: this
441+
});
442+
}
396443
}
397444
});

0 commit comments

Comments
 (0)