Skip to content

Commit 8a9f72a

Browse files
committed
Save metadata table from Seurat objects
1 parent 5676fcc commit 8a9f72a

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

singlecell/resources/chunks/SaveData.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ for (datasetId in names(newSeuratObjects)) {
44

55
fn <- paste0(outputPrefix, '.', datasetId, '.seurat.rds')
66
barcodeFile <- paste0(outputPrefix, '.', datasetId, '.cellBarcodes.csv')
7+
metaFile <- paste0(outputPrefix, '.', datasetId, '.seurat.meta.txt')
78

89
saveRDS(seuratObj, file = fn)
910

@@ -14,7 +15,8 @@ for (datasetId in names(newSeuratObjects)) {
1415

1516
savedFiles <- rbind(savedFiles, data.frame(datasetId = datasetId, datasetName = datasetName, filename = fn, outputFileId = outputFileId))
1617

17-
# WriteCellBarcodes
18+
# Write cell barcodes and metadata:
19+
write.table(seuratObj@meta.data, file = metaFile, quote = F, row.names = F, sep = ',', col.names = F)
1820
write.table(data.frame(CellBarcode = colnames(seuratObj)), file = barcodeFile, quote = F, row.names = F, sep = ',', col.names = F)
1921
}
2022

singlecell/src/org/labkey/singlecell/CellHashingServiceImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,4 +1089,15 @@ public File getCellBarcodesFromSeurat(File seuratObj)
10891089

10901090
return barcodes;
10911091
}
1092+
1093+
public File getMetaTableFromSeurat(File seuratObj)
1094+
{
1095+
File barcodes = new File(seuratObj.getParentFile(), seuratObj.getName().replaceAll("seurat.rds", "seurat.meta.txt"));
1096+
if (!barcodes.exists())
1097+
{
1098+
throw new IllegalArgumentException("Unable to find expected metadata file. This might indicate the seurat object was created with an older version of the pipeline. Expected: " + barcodes.getPath());
1099+
}
1100+
1101+
return barcodes;
1102+
}
10921103
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ else if (step.createsSeuratObjects())
291291
currentFiles = new ArrayList<>(output.getSeuratObjects());
292292
_resumer.getFileManager().addIntermediateFiles(currentFiles.stream().map(SingleCellStep.SeuratObjectWrapper::getFile).collect(Collectors.toSet()));
293293
_resumer.getFileManager().addIntermediateFiles(currentFiles.stream().map(x -> CellHashingServiceImpl.get().getCellBarcodesFromSeurat(x.getFile())).collect(Collectors.toSet()));
294+
_resumer.getFileManager().addIntermediateFiles(currentFiles.stream().map(x -> CellHashingServiceImpl.get().getMetaTableFromSeurat(x.getFile())).collect(Collectors.toSet()));
294295
}
295296
else if (step.createsSeuratObjects())
296297
{
@@ -316,6 +317,7 @@ else if (step.createsSeuratObjects())
316317
ctx.getFileManager().removeIntermediateFile(seurat.getFile());
317318
_resumer.getFileManager().removeIntermediateFile(seurat.getFile());
318319
_resumer.getFileManager().removeIntermediateFile(CellHashingServiceImpl.get().getCellBarcodesFromSeurat(seurat.getFile()));
320+
_resumer.getFileManager().removeIntermediateFile(CellHashingServiceImpl.get().getMetaTableFromSeurat(seurat.getFile()));
319321
}
320322
}
321323

@@ -471,6 +473,7 @@ private List<SingleCellStep.SeuratObjectWrapper> processRawCounts(JobContext ctx
471473
}
472474
currentFiles.stream().map(SingleCellStep.SeuratObjectWrapper::getFile).forEach(_resumer.getFileManager()::addIntermediateFile);
473475
_resumer.getFileManager().addIntermediateFiles(currentFiles.stream().map(x -> CellHashingServiceImpl.get().getCellBarcodesFromSeurat(x.getFile())).collect(Collectors.toSet()));
476+
_resumer.getFileManager().addIntermediateFiles(currentFiles.stream().map(x -> CellHashingServiceImpl.get().getMetaTableFromSeurat(x.getFile())).collect(Collectors.toSet()));
474477

475478
_resumer.setStepComplete(ctx.getLogger(), prepareRawCounts, 0, action, output0.getSeuratObjects(), output0.getMarkdownFile(), output0.getHtmlFile());
476479
}

0 commit comments

Comments
 (0)