Closed ACAIDI closed 11 months ago
@ACAIDI Hello Aziza, thanks for use ArchRtoSignac. Could you please provide more information related to how you run the function as well as an example of what you provide for the fragments_dir
, and samplelist
.
It's a bit difficult to guess what went wrong with our further information.
For example:
fragments_dir <- ".../myproject_folder/outs/" # the directory before "/outs/" for all samples
seurat_atac <- ArchR2Signac(
ArchRProject = proj,
refversion = "hg38",
#samples = samplelist,
fragments_dir = fragments_dir,
pm = pkm,
fragments_fromcellranger = "Yes",
fragments_file_extension = NULL,
annotation = annotations
)
Thank you for you reply, I reorganized data :
There are my command lines :
library(ArchRtoSignac)
library(parallel)
library(ArchR)
library("Cairo")
proj=loadArchRProject("ArchROutput") getAvailableMatrices(proj) pkm=getMatrixFromProject(proj, useMatrix='PeakMatrix')
library(EnsDb.Hsapiens.v86) # Ensembl database to convert to human hg38. Install what is appropriate for your analysis annotations <- getAnnotation(reference = EnsDb.Hsapiens.v86, refversion = "hg38") # "UCSC" is the default style to change to but can be changed with argument seqStyle
fragments_dirs <- list("/home/a_caidi/Bureau/a_caidi_igr/a_caidi_2022/multiome_data_analysis/P33_STCO_2/cellranger/C1/outs","/home/a_caidi/Bureau/a_caidi_igr/a_caidi_2022/multiome_data_analysis/P33_STCO_2/cellranger/C2/outs/","/home/a_caidi/Bureau/a_caidi_igr/a_caidi_2022/multiome_data_analysis/P33_STCO_2/cellranger/C3/outs","/home/a_caidi/Bureau/a_caidi_igr/a_caidi_2022/multiome_data_analysis/P33_STCO_2/cellranger/C4/outs")
library(stringr)
seurat_atac <- ArchR2Signac( ArchRProject = proj, refversion = "hg38", samples = c("C1","C2","C3","C4"), fragments_dir = fragments_dirs, pm = pkm, fragments_fromcellranger = "Yes", fragments_file_extension = '.tsv.gz' , annotation = annotations )
But I got another erreur : 'x' must be an array of at least two dimensions.
'x' must be an array of at least two dimensions.
Hello @ACAIDI
Without having the means to replicate what you have, I cannot really guess what went wrong. So let's walk through this together.
Since you're using Cellranger output, please simplify this code by using option 1a, which I suggested to use the following code with a couple of things to confirm:
fragments.tsv.gz
for each sample before running above code. ## Option 1a: Set one directory containing the cellranger output for each sample
fragments_dir <- "/home/a_caidi/Bureau/a_caidi_igr/a_caidi_2022/multiome_data_analysis/P33_STCO_2/cellranger/"
seurat_atac <- ArchR2Signac(
ArchRProject = proj,
refversion = "hg38",
fragments_dir = fragments_dir,
pm = pkm, # peak matrix from getPeakMatrix()
fragments_fromcellranger = "Yes",
annotation = annotations
)
Please let me know if this works or not. Thank you!
Dear author, Thanks for developing ArchR2Signac! But I have the same problem when using it. Could you please help me check it? Here is the part code: fragments_dirs <- list( "/Users/wli5/16_snATAC/fragments_dir/Run_01_24h/cellranger/output/Run_01_24h.fragments.tsv.gz", "/Users/wli5/16_snATAC/fragments_dir/Run_01_8h/cellranger/output/Run_01_8h.fragments.tsv.gz", "/Users/wli5/16_snATAC/fragments_dir/Run_01_post/cellranger/output/Run_01_post.fragments.tsv.gz", "/Users/wli5/16_snATAC/fragments_dir/Run_01_pre/cellranger/output/Run_01_pre.fragments.tsv.gz", "/Users/wli5/16_snATAC/fragments_dir/Run_03_08h/cellranger/output/Run_03_08h.fragments.tsv.gz", "/Users/wli5/16_snATAC/fragments_dir/Run_03_24h/cellranger/output/Run_03_24h.fragments.tsv.gz", "/Users/wli5/16_snATAC/fragments_dir/Run_03_post/cellranger/output/Run_03_post.fragments.tsv.gz", "/Users/wli5/16_snATAC/fragments_dir/Run_03_pre/cellranger/output/Run_03_pre.fragments.tsv.gz", "/Users/wli5/16_snATAC/fragments_dir/Run_04_08h/cellranger/output/Run_04_08h.fragments.tsv.gz", "/Users/wli5/16_snATAC/fragments_dir/Run_04_24h/cellranger/output/Run_04_24h.fragments.tsv.gz", "/Users/wli5/16_snATAC/fragments_dir/Run_04_post/cellranger/output/Run_04_post.fragments.tsv.gz", "/Users/wli5/16_snATAC/fragments_dir/Run_04_pre/cellranger/output/Run_04_pre.fragments.tsv.gz" ) SeuratObject <- ArchR2Signac( ArchRProject = proj, refversion = "hg38",
fragments_dir = fragments_dirs, pm = pkm, fragments_fromcellranger = "YES", annotation = annotations ) Thanks,
Weiming
@Weiming113 Thanks for using the ArchRtoSignac package. I realized I didn't make the function as flexible as possible to read in fragment files when I made this package. So maybe using fragments_fromcellranger = "NO",
it is not saying that the fragments are not from cellranger, but rather making reading fragment files a bit flexible. Please let me know if this works or not. I hope this works. My main focus is making new tools to help downstairs analysis aside from what Siganc can do. But I am here to help and will make this package more flexible once I have time.
# NOTE please keep the order fragment list the same as the ArchRProject sample order to avoid further complexity
fragments_dirs <- list(
"/Users/wli5/16_snATAC/fragments_dir/Run_01_24h/cellranger/output/Run_01_24h.fragments.tsv.gz",
"/Users/wli5/16_snATAC/fragments_dir/Run_01_8h/cellranger/output/Run_01_8h.fragments.tsv.gz",
"/Users/wli5/16_snATAC/fragments_dir/Run_01_post/cellranger/output/Run_01_post.fragments.tsv.gz",
"/Users/wli5/16_snATAC/fragments_dir/Run_01_pre/cellranger/output/Run_01_pre.fragments.tsv.gz",
"/Users/wli5/16_snATAC/fragments_dir/Run_03_08h/cellranger/output/Run_03_08h.fragments.tsv.gz",
"/Users/wli5/16_snATAC/fragments_dir/Run_03_24h/cellranger/output/Run_03_24h.fragments.tsv.gz",
"/Users/wli5/16_snATAC/fragments_dir/Run_03_post/cellranger/output/Run_03_post.fragments.tsv.gz",
"/Users/wli5/16_snATAC/fragments_dir/Run_03_pre/cellranger/output/Run_03_pre.fragments.tsv.gz",
"/Users/wli5/16_snATAC/fragments_dir/Run_04_08h/cellranger/output/Run_04_08h.fragments.tsv.gz",
"/Users/wli5/16_snATAC/fragments_dir/Run_04_24h/cellranger/output/Run_04_24h.fragments.tsv.gz",
"/Users/wli5/16_snATAC/fragments_dir/Run_04_post/cellranger/output/Run_04_post.fragments.tsv.gz",
"/Users/wli5/16_snATAC/fragments_dir/Run_04_pre/cellranger/output/Run_04_pre.fragments.tsv.gz"
)
# Conversion function
# Call the ArchR2Signac function with the provided arguments
SeuratObject <- ArchR2Signac(
ArchRProject = proj,
refversion = "hg38",
# samples = samples,
fragments_dir = fragments_dirs,
pm = pkm,
fragments_fromcellranger = "NO",
fragments_file_extension = '.fragments.tsv.gz',
annotation = annotations
)
It doesn't work! Can you send me the codes that works in your testing pipeline. I was a little bit confused how you put the fragments in the directory.
fragments_dir <- ".../myproject_folder/outs/" # the directory before "/outs/" for all samples Thanks
@Weiming113 my testing PATH from cellranger atac always looks like /Project/cellranger_atac_output/Sample-43/outs/fragments.tsv.gz
I guess I put extra .fragments.tsv.gz
in your fragments_dirs
in the last reply
But here is an example for using fragments' format different than cellranger standard.
## OR providing a fragments list but leave the fragments file extension out (use the 'fragments_file_extension' for the fragments extension)
fragments_dirs <- list(
"/ArchR/HemeFragments/scATAC_BMMC_R1",
"/ArchR/HemeFragments/scATAC_CD34_BMMC_R1",
"/ArchR/HemeFragments/scATAC_PBMC_R1"
)
# Call the ArchR2Signac function with the provided arguments
SeuratObject <- ArchR2Signac(
ArchRProject = proj,
refversion = "hg19", # or hg38
# samples = samples,
fragments_dir = fragments_dirs,
pm = pm,
fragments_fromcellranger = "NO",
fragments_file_extension = '.fragments.tsv.gz',
annotation = annotations
)
A part of the source code to assemble fragments dir:
cur_fragments <- ifelse(is.list(fragments_dir),
paste0(fragments_dir[[which(samples == cur_sample)]], fragments_file_extension),
paste0(fragments_dir, cur_sample, fragments_file_extension))
I would suggest you to make like this:
fragments_dirs <- list(
"/Users/wli5/16_snATAC/fragments_dir/Run_01_24h/cellranger/output/Run_01_24h",
"/Users/wli5/16_snATAC/fragments_dir/Run_01_8h/cellranger/output/Run_01_8h",
...
)
I do hope this work. Please let me know!
Unfortunately, it reported "Fragment file is not indexed." How did you put the index ?
@Weiming113 If I understand this error correctly, your error message should be something that looks like this, right?
Error in CreateFragmentObject(path = fragments, cells = cells,
validate.fragments = validate.fragments,
:Fragment file is not indexed.
This is more an error message from Signac; please check out this: https://stackoverflow.com/questions/72524686/fragment-file-is-not-indexed-in-signac-r
I am sure there are .tbi files in the directories. But it still doesn't work.
Run_01_24h/fragments.tsv.gz Run_01_24h/fragments.tsv.gz.tbi Run_01_8h/fragments.tsv.gz Run_01_8h/fragments.tsv.gz.tbi Run_01_post/fragments.tsv.gz Run_01_post/fragments.tsv.gz.tbi Run_01_pre/fragments.tsv.gz Run_01_pre/fragments.tsv.gz.tbi Run_03_08h/fragments.tsv.gz Run_03_08h/fragments.tsv.gz.tbi Run_03_24h/fragments.tsv.gz Run_03_24h/fragments.tsv.gz.tbi Run_03_post/fragments.tsv.gz Run_03_post/fragments.tsv.gz.tbi Run_03_pre/fragments.tsv.gz Run_03_pre/fragments.tsv.gz.tbi Run_04_08h/fragments.tsv.gz Run_04_08h/fragments.tsv.gz.tbi Run_04_24h/fragments.tsv.gz Run_04_24h/fragments.tsv.gz.tbi Run_04_post/fragments.tsv.gz Run_04_post/fragments.tsv.gz.tbi Run_04_pre/fragments.tsv.gz Run_04_pre/fragments.tsv.gz.tbi
I am sure there are .tbi files in the directories. But it still doesn't work.
Run_01_24h/fragments.tsv.gz Run_01_24h/fragments.tsv.gz.tbi
@Weiming113 I'm really confused now. What does your fragments file actually look like? They were like this before:
fragments_dirs <- list( "/Users/wli5/16_snATAC/fragments_dir/Run_01_24h/cellranger/output/Run_01_24h.fragments.tsv.gz", "/Users/wli5/16_snATAC/fragments_dir/Run_01_8h/cellranger/output/Run_01_8h.fragments.tsv.gz",
But now they are like this
Run_01_24h/fragments.tsv.gz
Run_01_8h/fragments.tsv.gz
Which is your fragments file, Run_01_24h.fragments.tsv.gz
or fragments.tsv.gz
?
Please make sure you are reading your fragment files from the path you think you are reading.
"/Users/wli5/16_snATAC/03_ArchR_to_Signac/fragments_dir/Run_01_24h/fragments.tsv.gz", "/Users/wli5/16_snATAC/03_ArchR_to_Signac/fragments_dir/Run_01_8h/fragments.tsv.gz", "/Users/wli5/16_snATAC/03_ArchR_to_Signac/fragments_dir/Run_01_post/fragments.tsv.gz", "/Users/wli5/16_snATAC/03_ArchR_to_Signac/fragments_dir/Run_01_pre/fragments.tsv.gz", "/Users/wli5/16_snATAC/03_ArchR_to_Signac/fragments_dir/Run_03_08h/fragments.tsv.gz", "/Users/wli5/16_snATAC/03_ArchR_to_Signac/fragments_dir/Run_03_24h/fragments.tsv.gz", "/Users/wli5/16_snATAC/03_ArchR_to_Signac/fragments_dir/Run_03_post/fragments.tsv.gz", "/Users/wli5/16_snATAC/03_ArchR_to_Signac/fragments_dir/Run_03_pre/fragments.tsv.gz", "/Users/wli5/16_snATAC/03_ArchR_to_Signac/fragments_dir/Run_04_08h/fragments.tsv.gz", "/Users/wli5/16_snATAC/03_ArchR_to_Signac/fragments_dir/Run_04_24h/fragments.tsv.gz", "/Users/wli5/16_snATAC/03_ArchR_to_Signac/fragments_dir/Run_04_post/fragments.tsv.gz", "/Users/wli5/16_snATAC/03_ArchR_to_Signac/fragments_dir/Run_04_pre/fragments.tsv.gz" It works now. The fragment files should be listed like this. Thanks for your help.
@Weiming113 Great! Glad to know that worked! I will close this issue. If you have any other questions, please open another issue.
Hi, I tried @Weiming113 solution and it works for me too. Thank you for your reply
Hello, I am having a similar issue to Weiming113 but I am still getting the fragment file does not exist I only have one sample so I tried it as a string and as a list. Both options result in the same error. Here is my code:
fragments_dir <- "/Users/ehoreth/Desktop/100323_HuSMG_Multiome/scATAC/frags/fragments.tsv.gz" fragments_dirs <- list("/Users/ehoreth/Desktop/100323_HuSMG_Multiome/scATAC/frags/fragments.tsv.gz")
seurat_atac <- ArchR2Signac(ArchRProject = proj, samples = samples, fragments_dir = fragments_dirs, fragments_fromcellranger = "NO", fragments_file_extension = '.tsv.gz', pm = pm, refversion = 'hg38', annotation = annotation)
I have tried it with the fragment files in the directory as shown and as: "/Users/ehoreth/Desktop/100323_HuSMG_Multiome/scATAC/frags"
Can you please help me figure this out?
Thank you. Erich
Hello @kamsolari, Thanks for using the ArchRtoSignac
package. Firstly, are your fragments files coming from 10x Genomics or not? And even from 10x Genomics, but your fragment files' style to match exact like the output from cellranger-atac count
, please let me know.
Also, I am unsure what you supply for the samples
. Additionally, please provide an example of the PATH to your fragment files. For example (Using some examples shown above):
"/Users/wli5/16_snATAC/fragments_dir/Run_01_24h/cellranger/output/Run_01_24h.fragments.tsv.gz"
"/Users/wli5/16_snATAC/fragments_dir/Run_01_8h/cellranger/output/Run_01_8h.fragments.tsv.gz"
If your fragment files are not from cellranger, for example like this:
/ArchR/HemeFragments/
├── scATAC_BMMC_R1.fragments.tsv.gz
├── scATAC_CD34_BMMC_R1.fragments.tsv.gz
(more)
Then Your code should be:
fragments_dirs <- list(
"/ArchR/HemeFragments/scATAC_BMMC_R1",
"/ArchR/HemeFragments/scATAC_CD34_BMMC_R1",
"/ArchR/HemeFragments/scATAC_PBMC_R1"
)
# Call the ArchR2Signac function with the provided arguments
SeuratObject <- ArchR2Signac(
ArchRProject = proj,
refversion = "hg19",
# samples = samples,
fragments_dir = fragments_dirs,
pm = pm,
fragments_fromcellranger = "NO",
fragments_file_extension = '.fragments.tsv.gz',
annotation = annotations
)
Well, once again, please let me know. Ideally, this is an easy fix; it is a matter of style matching the reading in the code and also fitting into the style for SeuratObject. Thank you!
Hello Ze,
Thank you for the fast reply and thank you for developing this tool.
They are coming from 10x genomics but I was not the one who ran cellranger on them so they are not in the traditional output folder so I ran it with the fragments_fromcellranger set to "NO".
My samples object is:
samples [1] "Human_SMG"
I named the sample when creating the ArrowFiles as thus: ArrowFiles <- createArrowFiles( inputFiles = "../input_files/frags/fragments.tsv.gz", sampleNames = "Human_SMG", minTSS = 1, # Dont set this too high because you can always increase later minFrags = 500, addTileMat = TRUE, addGeneScoreMat = TRUE )
Do you think it is a sample name matching issue?
this is the path to my fragment file: "/Users/ehoreth/Desktop/100323_HuSMG_Multiome/scATAC/frags/fragments.tsv.gz"
Thank you!
They are coming from 10x genomics but I was not the one who ran cellranger on them so they are not in the traditional output folder so I ran it with the fragments_fromcellranger set to "NO".
My samples object is:
samples [1] "Human_SMG"
I see, before moving forward on this. Please confirm that you have only one sample. If that's true, then please use the following code similar to the Option 2c:
that I listed in README
. It's a bit tricky. But you can give a try for the following code I provided, made some changes.
I made some changes to fit your PATH.
fragments_dirs <- list(
"/Users/ehoreth/Desktop/100323_HuSMG_Multiome/scATAC/frags/"
)
Also, please adjust the name of supplied object in the following code to match the way you named them
# Call the ArchR2Signac function with the provided arguments
SeuratObject <- ArchR2Signac(
ArchRProject = proj,
refversion = "hg38",
# samples = samples,
fragments_dir = fragments_dirs,
pm = pm,
fragments_fromcellranger = "NO",
fragments_file_extension = 'fragments.tsv.gz', # instead of using fragments_file_extension (.tsv.gz), here just use the whole name fragments.tsv.gz',
annotation = annotations
)
Please let me know if it works or not. Thank you!
That worked to get ArchRtoSignac to recognize the fragment files. However it is now telling me to provide a cell identifier in order to merge. This is what I ran:
seurat_atac <- ArchR2Signac(ArchRProject = proj,
- samples = samples,
- fragments_dir = fragments_dirs,
- fragments_fromcellranger = "NO",
- fragments_file_extension = 'fragments.tsv.gz',
- pm = pm,
- refversion = 'hg38',
- annotation = annotation) [1] "IF selecting NO, please make sure to provide fragments_file_extension" [1] "In Progress:" [1] "Prepare Seurat list for each sample" [1] "HumanSMG" [1] 119635 9597 Computing hash Checking for 9597 cell barcodes Warning: Keys should be one or more alphanumeric characters followed by an underscore, setting key from peaks to peaks [1] "In Progress:" [1] "Merge Seurat list" Error in merge.Seurat(x = seurat_list[[1]], y = seurat_list[2:length(seurat_list)], : Please provide a cell identifier for each object provided to merge
So looking at your code, it seems that the problem is I only have 1 object because the use of the Seurat merge function you call towards the end. In order to circumvent that error, I edited the function as follows:
ArchR2Signac_single <- function( ArchRProject, refversion, # write the EnsDb version samples = NULL, # Provide a list of unique sample fragments_dir = NULL, # directory of the cellranger output, the folder that contains all samples pm, # geting peak martix fragments_fromcellranger = NULL, # "NO" | "N" | "No" or "YES" | "Y" | "Yes" fragments_file_extension = NULL, # '.tsv.gz' or '.fragments.tsv.gz'
annotation # annotation from getAnnotation()
){ if (is.null(samples)){ samples <- unique(ArchRProject@cellColData$Sample) }
if(fragments_fromcellranger == "YES" | fragments_fromcellranger == "Y" | fragments_fromcellranger == "Yes") { print("In Progress:") print("Prepare Seurat list for each sample")
output_dir = '/outs/'
seurat_list <- lapply(samples, function(cur_sample){
print(cur_sample)
#print out the sample name in progress
cur_fragments <- ifelse(is.list(fragments_dir),
paste0(fragments_dir[[which(samples == cur_sample)]], output_dir, 'fragments.tsv.gz'),
paste0(fragments_dir, cur_sample, output_dir, 'fragments.tsv.gz'))
# seeking the pattern matched in colnames(pm); metadata of the corresponding sample
cur_pm <- pm[,grepl(paste0(cur_sample, '#'), colnames(pm))]
cur_meta <- ArchRProject@cellColData %>% as.data.frame %>% subset(Sample == cur_sample)
# change colnames and rowname format:
colnames(cur_pm) <- do.call(rbind, str_split(colnames(cur_pm), '#'))[,2]
rownames(cur_meta) <- do.call(rbind, str_split(rownames(cur_meta), '#'))[,2]
print(dim(cur_pm))
# create chromatin assay
cur_chromatin <- Signac::CreateChromatinAssay(
counts=cur_pm, # should we add data instead counts
sep = c('-', '-'),
fragments=cur_fragments, # do we need this?
ranges=ArchRProject@peakSet,
genome=refversion,
annotation = annotation
)
# create a new Seurat obj with only the archR peaks:
cur_atac <- Seurat::CreateSeuratObject(
cur_chromatin,
assay='peaks',
meta.data = cur_meta,
)
})
}
if(fragments_fromcellranger == "NO" | fragments_fromcellranger == "N" | fragments_fromcellranger == "No") {
print("IF selecting NO, please make sure to provide fragments_file_extension")
print("In Progress:")
print("Prepare Seurat list for each sample")
seurat_list <- lapply(samples, function(cur_sample){
print(cur_sample)
#print out the sample name in progress
cur_fragments <- ifelse(is.list(fragments_dir),
paste0(fragments_dir[[which(samples == cur_sample)]], fragments_file_extension),
paste0(fragments_dir, cur_sample, fragments_file_extension))
# seeking the pattern matched in colnames(pm); metadata of the corresponding sample
cur_pm <- pm[,grepl(paste0(cur_sample, '#'), colnames(pm))]
cur_meta <- ArchRProject@cellColData %>% as.data.frame %>% subset(Sample == cur_sample)
# change colnames and rowname format:
colnames(cur_pm) <- do.call(rbind, str_split(colnames(cur_pm), '#'))[,2]
rownames(cur_meta) <- do.call(rbind, str_split(rownames(cur_meta), '#'))[,2]
print(dim(cur_pm))
# create chromatin assay
cur_chromatin <- Signac::CreateChromatinAssay(
counts=cur_pm, # should we add data instead counts
sep = c('-', '-'),
fragments=cur_fragments, # do we need this?
ranges=ArchRProject@peakSet,
genome=refversion,
annotation = annotation
)
# create a new Seurat obj with only the archR peaks:
cur_atac <- Seurat::CreateSeuratObject(
cur_chromatin,
assay='peaks',
meta.data = cur_meta,
)
})
} SeuratObject <- seurat_list[[1]] print("Return SeuratObject") SeuratObject
}
Obviously I hard coded it for it to work on a single data set. I imagine including an if loop would be a more universal solution. So as of now, everything is working fine. Thank you so much for the help. I will make sure whenever I present the data I will give a shout out to ArchRtoSignac. Of course, when I go to publish you will be cited. I really appreciate your effort to help me.
Erich
@kamsolari Erich. Thanks for letting me know about the error
Error in merge.Seurat(x = seurat_list[[1]], y = seurat_list[2:length(seurat_list)], :
Please provide a cell identifier for each object provided to merge
In the following updates, I will add an if loop to make it work. Thank you! I will add an enhancement later to reminder myself. For now I will close this issue. Thank you for using ArchRtoSignac again
Hello, i'm trying to use your package, but the conversion ArchR2Signac does'nt work. The error message is : Erreur dans CreateFragmentObject(path = fpath, cells = cells, verbose = FALSE, : Fragment file does not exist. The problem is that the path is correct. The files fragments.tsv.gz and fragments.tsv.gz.tbi are in the correct path. When i use this passe for Signac it works without problems but it doesn't work for ArchR2Signac. I tried to rename files in different ways but it doesn't work. Can you help me with this issue? Many thanks for you help.
Aziza