19.1 Exporting fragment-level data

Before we start exporting data, lets save projHeme5 to its own directory.

projHeme5 <- saveArchRProject(ArchRProj = projHeme5, outputDirectory = "Save-ProjHeme5", load = TRUE)
## Copying ArchRProject to new outputDirectory : /corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme5
## Copying Arrow Files...
## Copying Arrow Files (1 of 3)
## Copying Arrow Files (2 of 3)
## Copying Arrow Files (3 of 3)
## Getting ImputeWeights
## Dropping ImputeWeights...
## Copying Other Files...
## Copying Other Files (1 of 11): Annotations
## Copying Other Files (2 of 11): Background-Peaks.rds
## Copying Other Files (3 of 11): Embeddings
## Copying Other Files (4 of 11): GroupCoverages
## Copying Other Files (5 of 11): IterativeLSI
## Copying Other Files (6 of 11): IterativeLSI2
## Copying Other Files (7 of 11): Monocole3
## Copying Other Files (8 of 11): Peak2GeneLinks
## Copying Other Files (9 of 11): PeakCalls
## Copying Other Files (10 of 11): Plots
## Copying Other Files (11 of 11): RNAIntegration
## Saving ArchRProject...
## Loading ArchRProject...
## Successfully loaded ArchRProject!
## 
##                                                    / |
##                                                  /    \
##             .                                  /      |.
##             \\\                              /        |.
##               \\\                          /           `|.
##                 \\\                      /              |.
##                   \                    /                |\
##                   \\#####\           /                  ||
##                 ==###########>      /                   ||
##                  \\##==......\    /                     ||
##             ______ =       =|__ /__                     ||      \\\
##         ,--' ,----`-,__ ___/'  --,-`-===================##========>
##        \               '        ##_______ _____ ,--,__,=##,__   ///
##         ,    __==    ___,-,__,--'#'  ==='      `-'    | ##,-/
##         -,____,---'       \\####\\________________,--\\_##,/
##            ___      .______        ______  __    __  .______      
##           /   \     |   _  \      /      ||  |  |  | |   _  \     
##          /  ^  \    |  |_)  |    |  ,----'|  |__|  | |  |_)  |    
##         /  /_\  \   |      /     |  |     |   __   | |      /     
##        /  _____  \  |  |\  \\___ |  `----.|  |  |  | |  |\  \\___.
##       /__/     \__\ | _| `._____| \______||__|  |__| | _| `._____|
## 

To enable optimal flexibility, ArchR allows you to export fragments from your ArchRProject or ArrowFiles at any time using the getFragmentsFromArrow(), getFragmentsFromProject(), and getGroupFragments() functions. For the getFragmentsFromArrow() and getFragmentsFromProject() functions, you must provide the cellNames for the cells you wish to extract. For example, you might extract the fragments from a particular cluster from your entire project like this:

frags <- getFragmentsFromProject(
  ArchRProj = projHeme5,
  cellNames = getCellNames(ArchRProj = projHeme5)[which(projHeme5@cellColData$Clusters2 == "Mono")]
  )
## ArchR logging to : ArchRLogs/ArchR-getFragmentsFromProject-371b0731e4aa7-Date-2022-12-23_Time-09-18-18.log
## If there is an issue, please report to github with logFile!
## Reading ArrowFile 1 of 3
## Reading ArrowFile 2 of 3
## Reading ArrowFile 3 of 3

Inspecting the frags object here, shows it to be a list and each of the elements of frags is a GRanges object corresponding to one of the original Arrow Files:

frags
## List of length 3
## names(3): scATAC_BMMC_R1 scATAC_CD34_BMMC_R1 scATAC_PBMC_R1

We can just unlist this object to get a GRanges object where each entry represents an individual fragment:

unlist(frags)
## GRanges object with 9487632 ranges and 1 metadata column:
##                  seqnames            ranges strand |                     RG
##                     <Rle>         <IRanges>  <Rle> |                  <Rle>
##   scATAC_BMMC_R1     chr1     713020-713186      * | scATAC_BMMC_R1#CCGTA..
##   scATAC_BMMC_R1     chr1     876537-876755      * | scATAC_BMMC_R1#CCGTA..
##   scATAC_BMMC_R1     chr1     911371-911637      * | scATAC_BMMC_R1#CCGTA..
##   scATAC_BMMC_R1     chr1     954927-954966      * | scATAC_BMMC_R1#CCGTA..
##   scATAC_BMMC_R1     chr1   1052090-1052416      * | scATAC_BMMC_R1#CCGTA..
##              ...      ...               ...    ... .                    ...
##   scATAC_PBMC_R1     chrY 22737645-22737827      * | scATAC_PBMC_R1#AATGG..
##   scATAC_PBMC_R1     chrY 15443307-15443509      * | scATAC_PBMC_R1#GGTGC..
##   scATAC_PBMC_R1     chrY 14604751-14604917      * | scATAC_PBMC_R1#CGATG..
##   scATAC_PBMC_R1     chrY   5609640-5609780      * | scATAC_PBMC_R1#TATGT..
##   scATAC_PBMC_R1     chrY 22737684-22737775      * | scATAC_PBMC_R1#TATGT..
##   -------
##   seqinfo: 24 sequences from an unspecified genome; no seqlengths

Similarly, getGroupFragments() provides a shortcut to doing fragment export based on cell groupings defined in cellColData. However, this function creates fragment files on disk, rather than storing them as a GRanges object.

frags <- getGroupFragments(ArchRProj = projHeme5, groupBy = "Clusters2")

Inspecting the frags object returned as the output of getGroupFragments(), we get the file paths to the fragment files on disk.

frags
##  [1] "/corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme5/GroupFragments/Clusters2.B.tsv.gz"         
##  [2] "/corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme5/GroupFragments/Clusters2.CD4.M.tsv.gz"     
##  [3] "/corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme5/GroupFragments/Clusters2.CD4.N.tsv.gz"     
##  [4] "/corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme5/GroupFragments/Clusters2.CLP.tsv.gz"       
##  [5] "/corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme5/GroupFragments/Clusters2.Erythroid.tsv.gz" 
##  [6] "/corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme5/GroupFragments/Clusters2.GMP.tsv.gz"       
##  [7] "/corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme5/GroupFragments/Clusters2.Mono.tsv.gz"      
##  [8] "/corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme5/GroupFragments/Clusters2.NK.tsv.gz"        
##  [9] "/corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme5/GroupFragments/Clusters2.pDC.tsv.gz"       
## [10] "/corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme5/GroupFragments/Clusters2.PreB.tsv.gz"      
## [11] "/corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme5/GroupFragments/Clusters2.Progenitor.tsv.gz"