Skip to content

Commit 842ead8

Browse files
committed
Augment seurat prototype description field
1 parent e6fb9d9 commit 842ead8

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import java.io.File;
8080
import java.io.FileInputStream;
8181
import java.io.IOException;
82+
import java.sql.SQLException;
8283
import java.util.ArrayList;
8384
import java.util.Arrays;
8485
import java.util.Collections;
@@ -592,6 +593,7 @@ public ModelAndView getConfirmView(Object form, BindException errors) throws Exc
592593
public boolean handlePost(Object form, BindException errors) throws Exception
593594
{
594595
UserSchema sa = QueryService.get().getUserSchema(getUser(), getContainer(), SingleCellSchema.SEQUENCE_SCHEMA_NAME);
596+
List<Map<String, Object>> toUpdate = new ArrayList<>();
595597
new TableSelector(sa.getTable("outputfiles"), PageFlowUtil.set("rowid"), new SimpleFilter(FieldKey.fromString("category"), "Seurat Object Prototype"), null).forEach(Integer.class, rowId -> {
596598
SequenceOutputFile so = SequenceOutputFile.getForId(rowId);
597599
if (so == null)
@@ -642,17 +644,34 @@ public boolean handlePost(Object form, BindException errors) throws Exception
642644
}
643645

644646
String description = AbstractSingleCellHandler.getOutputDescription(params, _log, so.getFile(), null);
645-
so.setDescription(description);
646-
647-
_log.info(rowId);
648-
_log.info(description);
647+
toUpdate.add(new CaseInsensitiveHashMap<>(Map.of("rowid", so.getRowid(), "description", description)));
649648
}
650649
catch (PipelineJobException e)
651650
{
652651
_log.error("Error generating description for: " + rowId, e);
653652
}
654653
});
655654

655+
if (!toUpdate.isEmpty())
656+
{
657+
try
658+
{
659+
BatchValidationException bve = new BatchValidationException();
660+
List<Map<String, Object>> oldKeys = toUpdate.stream().map(row -> Map.of("rowid", row.get("rowid"))).toList();
661+
sa.getTable("outputfiles").getUpdateService().updateRows(getUser(), getContainer(), toUpdate, oldKeys, bve, null, null);
662+
663+
if (bve.hasErrors())
664+
{
665+
throw bve;
666+
}
667+
}
668+
catch (SQLException | BatchValidationException e)
669+
{
670+
_log.error("Unable to update outputfiles", e);
671+
return false;
672+
}
673+
}
674+
656675
return true;
657676
}
658677
}

singlecell/src/org/labkey/singlecell/analysis/AbstractSingleCellHandler.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,7 @@ public static String getOutputDescription(JSONObject jsonParams, Logger log, Fil
10261026
int cellsWithTRB = 0;
10271027
int cellsWithTRD = 0;
10281028
int cellsWithTRG = 0;
1029+
int cellsLackingCDR3 = 0;
10291030
while ((line = reader.readNext()) != null)
10301031
{
10311032
// This will test whether this is the first line or not
@@ -1084,13 +1085,15 @@ else if ("NotUsed".equals(val))
10841085
{
10851086
if ("T_NK".equals(line[riraIdx]))
10861087
{
1088+
boolean hasCDR3 = false;
10871089
totalTNK++;
10881090
if (traIdx >= 0)
10891091
{
10901092
String tra = StringUtils.trimToNull(line[traIdx]);
10911093
if (tra != null && !"NA".equals(tra))
10921094
{
10931095
cellsWithTRA++;
1096+
hasCDR3 = true;
10941097
}
10951098
}
10961099

@@ -1100,6 +1103,7 @@ else if ("NotUsed".equals(val))
11001103
if (trb != null && !"NA".equals(trb))
11011104
{
11021105
cellsWithTRB++;
1106+
hasCDR3 = true;
11031107
}
11041108
}
11051109

@@ -1109,6 +1113,7 @@ else if ("NotUsed".equals(val))
11091113
if (trd != null && !"NA".equals(trd))
11101114
{
11111115
cellsWithTRD++;
1116+
hasCDR3 = true;
11121117
}
11131118
}
11141119

@@ -1118,8 +1123,14 @@ else if ("NotUsed".equals(val))
11181123
if (trg != null && !"NA".equals(trg))
11191124
{
11201125
cellsWithTRG++;
1126+
hasCDR3 = true;
11211127
}
11221128
}
1129+
1130+
if (!hasCDR3)
1131+
{
1132+
cellsLackingCDR3++;
1133+
}
11231134
}
11241135
}
11251136
}
@@ -1157,6 +1168,7 @@ else if ("NotUsed".equals(val))
11571168
descriptions.add("% T/NK Cells with TRB: " + pf.format(cellsWithTRB / (double)totalTNK));
11581169
descriptions.add("% T/NK Cells with TRD: " + pf.format(cellsWithTRD / (double)totalTNK));
11591170
descriptions.add("% T/NK Cells with TRG: " + pf.format(cellsWithTRG / (double)totalTNK));
1171+
descriptions.add("% T/NK Cells without TCR: " + pf.format(cellsLackingCDR3 / (double)totalTNK));
11601172
}
11611173
else if (riraIdx == -1 || traIdx == -1)
11621174
{

0 commit comments

Comments
 (0)