Skip to content

Commit 5a03686

Browse files
committed
Better cDNA import validation
1 parent 9c8b91d commit 5a03686

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

singlecell/resources/queries/singlecell/sorts.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,24 @@ function beforeUpsert(row, oldRow, errors){
3535
else if (['perLN', 'PerLN'].indexOf(row.population) !== -1){
3636
row.population = 'pLN';
3737
}
38+
else if (['mesLN'].indexOf(row.population) !== -1){
39+
row.population = 'MesLN';
40+
}
41+
else if (['Bone Marrow', 'BoneMarrow'].indexOf(row.population) !== -1){
42+
row.population = 'Bone marrow';
43+
}
44+
3845

46+
//Tissue:
3947
if (['perLN', 'PerLN'].indexOf(row.tissue) !== -1){
4048
row.tissue = 'pLN';
4149
}
50+
else if (['mesLN'].indexOf(row.tissue) !== -1){
51+
row.tissue = 'MesLN';
52+
}
53+
else if (['Bone Marrow', 'BoneMarrow'].indexOf(row.tissue) !== -1){
54+
row.tissue = 'Bone marrow';
55+
}
4256

4357
//Naive cells
4458
if (row.population && row.population.match(/ï/)){

singlecell/src/org/labkey/singlecell/SingleCellController.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.labkey.api.query.QueryService;
4747
import org.labkey.api.query.UserSchema;
4848
import org.labkey.api.security.RequiresPermission;
49+
import org.labkey.api.security.User;
4950
import org.labkey.api.security.permissions.InsertPermission;
5051
import org.labkey.api.security.permissions.ReadPermission;
5152
import org.labkey.api.sequenceanalysis.SequenceOutputFile;
@@ -200,6 +201,7 @@ public Object execute(SimpleApiJsonForm form, BindException errors) throws Excep
200201
try (DbScope.Transaction transaction = DbScope.getLabKeyScope().ensureTransaction())
201202
{
202203
BatchValidationException bve = new BatchValidationException();
204+
validateBarcodes(readsetRows, getContainer(), getUser());
203205

204206
Map<String, Integer> sampleMap = new HashMap<>();
205207
final List<Map<String, Object>> sampleRowsToInsert = new ArrayList<>();
@@ -308,12 +310,36 @@ public Object execute(SimpleApiJsonForm form, BindException errors) throws Excep
308310
{
309311
_log.error(e);
310312

313+
errors.reject(ERROR_MSG, e.getMessage());
314+
return null;
311315
}
312316

313317
return new ApiSimpleResponse("success", true);
314318
}
315319
}
316320

321+
private static void validateBarcodes(List<Map<String, Object>> readsetRows, Container c, User u)
322+
{
323+
Set<String> uniqueBarcodeNames = new HashSet<>();
324+
readsetRows.forEach(rs -> {
325+
if (rs.get("barcode5") != null) {
326+
uniqueBarcodeNames.add((String.valueOf(rs.get("barcode5"))));
327+
}
328+
});
329+
330+
if (!uniqueBarcodeNames.isEmpty())
331+
{
332+
TableInfo barcodes = QueryService.get().getUserSchema(u, c, SingleCellSchema.SEQUENCE_SCHEMA_NAME).getTable("barcodes");
333+
Set<String> foundTags = new HashSet<>(new TableSelector(barcodes, PageFlowUtil.set("tag_name"), new SimpleFilter(FieldKey.fromString("tag_name"), uniqueBarcodeNames, CompareType.IN), null).getArrayList(String.class));
334+
if (foundTags.size() != uniqueBarcodeNames.size())
335+
{
336+
uniqueBarcodeNames.removeAll(foundTags);
337+
338+
throw new ApiUsageException("The following barcodes were not found: " + StringUtils.join(uniqueBarcodeNames, ","));
339+
}
340+
}
341+
}
342+
317343
private static List<Map<String, Object>> parseRows(SimpleApiJsonForm form, String propName, Container container) throws ApiUsageException
318344
{
319345
if (!form.getJsonObject().containsKey(propName))

0 commit comments

Comments
 (0)