Skip to content

Commit 3b88e25

Browse files
committed
Add natural sorting to file/readset name on import panel
1 parent a877589 commit 3b88e25

File tree

3 files changed

+51
-18
lines changed

3 files changed

+51
-18
lines changed

SequenceAnalysis/resources/web/SequenceAnalysis/Utils.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ SequenceAnalysis.Utils = new function(){
137137
exonPosition = nt_position - startNT + exon[0];
138138
nt_positions.push(exonPosition);
139139
exons.push(idx);
140-
if(nt_positions.length == 3)
140+
if(nt_positions.length === 3)
141141
return false; //jump to next exon
142142

143143
nt_position++;
@@ -152,6 +152,22 @@ SequenceAnalysis.Utils = new function(){
152152
nt_positions: nt_positions,
153153
exons: exons
154154
};
155+
},
156+
157+
// https://github.com/overset/javascript-natural-sort/blob/master/naturalSort.js
158+
naturalSortFn: function(o1, o2){
159+
o1 = SequenceAnalysis.Utils.getNaturalSortValue(o1);
160+
o2 = SequenceAnalysis.Utils.getNaturalSortValue(o2);
161+
162+
if (o1 === o2) {
163+
return 0;
164+
}
165+
166+
return o1 < o2 ? -1 : 1;
167+
},
168+
169+
getNaturalSortValue: function(value) {
170+
return value ? value.replace(/(\d+)/g, "0000000000$1").replace(/0*(\d{10,})/g, "$1") : value;
155171
}
156172
}
157173
}

SequenceAnalysis/resources/web/SequenceAnalysis/panel/SequenceImportPanel.js

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ Ext4.define('SequenceAnalysis.panel.SequenceImportPanel', {
3333
sequenceImportPanel: this,
3434
extend: 'Ext.data.Model',
3535
fields: [
36-
{name: 'fileGroupId', allowBlank: false},
37-
{name: 'readset', allowBlank: false},
36+
{name: 'fileGroupId', allowBlank: false, sortType: SequenceAnalysis.Utils.getNaturalSortValue},
37+
{name: 'readset', allowBlank: false, sortType: SequenceAnalysis.Utils.getNaturalSortValue},
3838
{name: 'readsetname', useNull: true},
3939
{name: 'importType', useNull: true},
4040
{name: 'barcode5', useNull: true},
@@ -128,8 +128,8 @@ Ext4.define('SequenceAnalysis.panel.SequenceImportPanel', {
128128
model: Ext4.define('SequenceAnalysis.model.ReadsetDataModel', {
129129
extend: 'Ext.data.Model',
130130
fields: [
131-
{name: 'id'},
132-
{name: 'fileGroupId', allowBlank: false},
131+
{name: 'id', sortType: SequenceAnalysis.Utils.getNaturalSortValue},
132+
{name: 'fileGroupId', allowBlank: false, sortType: SequenceAnalysis.Utils.getNaturalSortValue},
133133
{name: 'fileRecord1'},
134134
{name: 'fileRecord2'},
135135
{name: 'platformUnit'},
@@ -332,7 +332,7 @@ Ext4.define('SequenceAnalysis.panel.SequenceImportPanel', {
332332
distinctGroups.push(r.get('fileGroupId'));
333333
}
334334
}, this);
335-
distinctGroups = Ext4.unique(distinctGroups);
335+
distinctGroups = Ext4.unique(distinctGroups).sort(SequenceAnalysis.Utils.naturalSortFn);
336336

337337
var found = [];
338338
Ext4.Array.forEach(this.fileGroupStore.getRange(), function(fg){
@@ -424,7 +424,13 @@ Ext4.define('SequenceAnalysis.panel.SequenceImportPanel', {
424424
TENX_REGEX: /^(.+?)(_[0-9]+){0,1}_S(.+)_L(.+)_(R){0,1}([0-9])(_[0-9]+){0,1}(\.f(ast){0,1}q)(\.gz)?$/i,
425425

426426
populateSamples: function(orderType, isPaired){
427-
this.fileNameStore.sort('displayName', 'ASC');
427+
this.fileNameStore.sort([{
428+
sorterFn: function(o1, o2){
429+
o1 = o1.get('displayName');
430+
o2 = o2.get('displayName');
431+
return o1 = SequenceAnalysis.Utils.naturalSortFn(o1, o2);
432+
}
433+
}]);
428434
this.readDataStore.removeAll();
429435
var errorMsgs = [];
430436

@@ -483,9 +489,7 @@ Ext4.define('SequenceAnalysis.panel.SequenceImportPanel', {
483489
}
484490
}, this);
485491

486-
var keys = Ext4.Object.getKeys(map);
487-
keys.sort();
488-
492+
var keys = Ext4.Object.getKeys(map).sort(SequenceAnalysis.Utils.naturalSortFn);
489493
Ext4.Array.forEach(keys, function(key){
490494
if (Ext4.isArray(map[key])){
491495
Ext4.Array.forEach(map[key], function(r){
@@ -563,14 +567,15 @@ Ext4.define('SequenceAnalysis.panel.SequenceImportPanel', {
563567
}
564568
}
565569

570+
this.readDataStore.sort('fileGroupId');
566571
this.down('#readDataGrid').getView().refresh();
567572

568573
//populate readsets
569574
var distinctNames = [];
570575
this.readDataStore.each(function(r){
571576
distinctNames.push(r.get('fileGroupId'));
572577
}, this);
573-
distinctNames = Ext4.unique(distinctNames);
578+
distinctNames = Ext4.unique(distinctNames).sort(SequenceAnalysis.Utils.naturalSortFn);
574579

575580
//update fileGroupIds
576581
Ext4.Array.forEach(distinctNames, function(name){
@@ -947,7 +952,7 @@ Ext4.define('SequenceAnalysis.panel.SequenceImportPanel', {
947952
model: this.fileNameStore.model
948953
});
949954

950-
this.fileNames.sort();
955+
this.fileNames.sort(SequenceAnalysis.Utils.naturalSortFn);
951956
Ext4.Msg.wait('Loading...');
952957
var multi = new LABKEY.MultiRequest();
953958
multi.add(LABKEY.Ajax.request, {
@@ -1073,8 +1078,20 @@ Ext4.define('SequenceAnalysis.panel.SequenceImportPanel', {
10731078
}
10741079
}, this);
10751080

1076-
this.fileNameStore.sort('displayName');
1077-
this.fileNameStoreCopy.sort('displayName');
1081+
this.fileNameStore.sort([{
1082+
sorterFn: function(o1, o2){
1083+
o1 = o1.get('displayName');
1084+
o2 = o2.get('displayName');
1085+
return SequenceAnalysis.Utils.naturalSortFn(o1, o2);
1086+
}
1087+
}]);
1088+
this.fileNameStoreCopy.sort([{
1089+
sorterFn: function(o1, o2){
1090+
o1 = o1.get('displayName');
1091+
o2 = o2.get('displayName');
1092+
return SequenceAnalysis.Utils.naturalSortFn(o1, o2);
1093+
}
1094+
}]);
10781095

10791096
this.down('#fileListView').refresh();
10801097
this.down('#totalFiles').update('Total files: ' + this.fileNameStore.getCount());

singlecell/resources/web/singlecell/panel/LibraryExportPanel.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,17 +874,17 @@ Ext4.define('SingleCell.panel.LibraryExportPanel', {
874874

875875
}
876876
rows.push(data.join(delim));
877-
878-
runMap[r.laneAssignment || 'Not Assigned'] = (runMap[r.laneAssignment || 'Not Assigned'] || 0) + (totalData || 0);
879877
}, this);
878+
879+
runMap[r.laneAssignment || 'Not Assigned'] = (runMap[r.laneAssignment || 'Not Assigned'] || 0) + (totalData || 0);
880880
}
881881
};
882882

883883
var delim = instrument.startsWith('Novogene') ? '\t' : ',';
884884
Ext4.Array.forEach(sortedRows, function (r) {
885885
var totalCells = totalCellsByReadset[r.plateId];
886886
console.log(totalCells);
887-
var gexData = totalCells > 15000 ? 70 : 50;
887+
var gexData = totalCells > 15000 ? 70 : 40;
888888
var tcrData = totalCells > 15000 ? 45 : 25;
889889
processType(readsetIds, rows, r, 'readsetId', 'GEX', 500, 0.01, 'G', null, false, gexData, runMap, totalCells);
890890
processType(readsetIds, rows, r, 'tcrReadsetId', 'TCR', 700, 0.01, 'T', null, false, tcrData, runMap, totalCells);
@@ -919,7 +919,7 @@ Ext4.define('SingleCell.panel.LibraryExportPanel', {
919919

920920
duplicates = Ext4.unique(duplicates);
921921
if (!allowDuplicates && duplicates.length){
922-
Ext4.Msg.alert('Error', 'Duplicate barcodes: ' + duplicates.join(', '));
922+
Ext4.Msg.alert('Error', 'Duplicate barcodes:<br>' + duplicates.join('<br>'));
923923
btn.up('singlecell-libraryexportpanel').down('#outputArea').setValue(null);
924924
btn.up('singlecell-libraryexportpanel').down('#downloadData').setDisabled(true);
925925
}

0 commit comments

Comments
 (0)