When generating paired RNA and ATAC counts datasets based on the df.pair information, the Initial code did not correctly reorder the data according to the cell IDs provided by df.pair, which led to mismatches and disordered pairing.
Initial Code
rna.counts <- LayerData(obj.rna, assay = rna.assay, layer = "counts", cells = df.pair$RNA)
atac.counts <- LayerData(obj.atac, assay = atac.assay, layer = "counts", cells = df.pair$ATAC)
✅ Proposed Fix
To ensure the output matrices are strictly ordered by the pairing information in df.pair, we should reindex the columns after extraction:
rna.counts <- LayerData(obj.rna, assay = rna.assay, layer = "counts", cells = df.pair$RNA)[ , df.pair$RNA]
atac.counts <- LayerData(obj.atac, assay = atac.assay, layer = "counts", cells = df.pair$ATAC)[ , df.pair$ATAC]
@lzj1769