ncborcherding / scRepertoire

A toolkit for single-cell immune profiling
https://www.borch.dev/uploads/screpertoire/
MIT License
311 stars 54 forks source link

Re-importing CSV file #385

Closed HRSharpe closed 5 months ago

HRSharpe commented 5 months ago

Hi,

Thanks for creating this great program!

I ran combineBCR from data generated by 10X sequencing, and I then exported this analysis as a CSV file using exportClones:

exportClones(combinedBCR, write.file = TRUE, format = "paired", dir = "~/Documents/CITEseq/GCB_BCR/", file.name = "BCRClones.csv")

I am struggling to re-import this csv file into scRepertoire as the file does not look the same as the original combineBCR data. I re-structure the data like this to change the title of the first column and split the table by sample:

combinedBCR<-read.csv("~/Documents/CITEseq/GCB_BCR/BCRClones.csv", header = TRUE) colnames(combinedBCR)[colnames(combinedBCR) == 'X'] <- 'barcode' combinedBCR<-split(combinedBCR,combinedBCR$group)

This now looks the same as the 'contig_list' example data provided, but when put through the analysis functions I get the error:

Error in [.data.frame(df[[i]], , cloneCall) : undefined columns selected

Is there a specific way to export this data so it can be re-imported again, or to import it so it works in scRepertoire? I expect I am missing something very obvious.

Thanks for your help!

Hannah

ncborcherding commented 5 months ago

Hey Hannah,

I can see how that would be confusing - sorry about that. exportClones() was originally designed to export into specific formats not maintain the output of combineTCR()/combineBCR().

Probably the best way to save is using saveRDS(combinedBCR, "filename.rds") - that will get you a compressed list object.

If you want to export for like an extended table - I'd recommend combining them into a single data frame with dplyr:

library(dplyr)
BCRClones <- combinedBCR %>%
                              bind_rows()
write.csv(BCRClones, "BCRClones.csv")

If you want to import the csv and reuse it, you can then split it the way you were attempting with the output exportClones()

combinedBCR<-read.csv("~/Documents/CITEseq/GCB_BCR/BCRClones.csv", header = TRUE)
colnames(combinedBCR)[colnames(combinedBCR) == 'X'] <- 'barcode'
combinedBCR<-split(combinedBCR,combinedBCR$group)

Hope that helps and let me know if you have any other questions.

Nick

HRSharpe commented 5 months ago

Thank you, That makes a lot of sense!