Skip to content

Commit 5f9b0b4

Browse files
committed
Allow cellranger rows lacking a consensus clonotype call
1 parent b95dc65 commit 5f9b0b4

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

singlecell/src/org/labkey/singlecell/run/CellRangerVDJWrapper.java

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,64 @@ public AlignmentStep.AlignmentOutput performAlignment(Readset rs, List<File> inp
427427
try (PrintWriter writer = PrintWriters.getPrintWriter(csv2); BufferedReader reader = Readers.getReader(csv))
428428
{
429429
String line;
430+
int totalD = 0;
431+
int totalG = 0;
430432
while ((line = reader.readLine()) != null)
431433
{
432-
line = line.replaceAll("TRATRG", "TRG");
433-
line = line.replaceAll("TRBTRD", "TRD");
434+
if (line.contains("TRATRG") || line.contains("TRBTRD"))
435+
{
436+
//Infer correct chain from the V, J and C genes
437+
String[] tokens = line.split(",");
438+
List<String> chains = new ArrayList<>();
439+
for (int idx : new Integer[]{6,8,9}) {
440+
String val = StringUtils.trimToNull(tokens[idx]) == null ? null : tokens[idx].substring(0,3);
441+
if (val != null)
442+
{
443+
chains.add(val);
444+
}
445+
}
446+
447+
Set<String> uniqueChains = new HashSet<>(chains);
448+
String originalChain = StringUtils.trimToNull(tokens[5]);
449+
if (uniqueChains.size() == 1)
450+
{
451+
String chain = uniqueChains.iterator().next();
452+
if (chain.equals("TRG"))
453+
{
454+
if (!originalChain.equals("TRA"))
455+
{
456+
getPipelineCtx().getLogger().error("Unexpected chain: from " + originalChain + " to " + chain);
457+
}
458+
459+
totalG++;
460+
}
461+
else if (chain.equals("TRD"))
462+
{
463+
if (!originalChain.equals("TRB"))
464+
{
465+
getPipelineCtx().getLogger().error("Unexpected chain: from " + originalChain + " to " + chain);
466+
}
467+
468+
totalD++;
469+
}
470+
471+
tokens[5] = chain;
472+
}
473+
else
474+
{
475+
getPipelineCtx().getLogger().warn("Multiple chains detected, leaving original call alone: " + originalChain);
476+
}
477+
478+
line = StringUtils.join(tokens, ",");
479+
line = line.replaceAll("TRATRG", "TRG");
480+
line = line.replaceAll("TRBTRD", "TRD");
481+
}
482+
434483
writer.println(line);
435484
}
485+
486+
getPipelineCtx().getLogger().info("\tTotal TRA->TRG changes: " + totalG);
487+
getPipelineCtx().getLogger().info("\tTotal TRB->TRD changes: " + totalD);
436488
}
437489

438490
csv.delete();

0 commit comments

Comments
 (0)