Coder Social home page Coder Social logo

Comments (2)

cbravo93 avatar cbravo93 commented on July 19, 2024 1

Hi @cartal !

You can take a look to cellranger-atac aggr to aggregate runs. Directly from cisTopic, you can create independent objects per run and then create a combined object:

# Create object for the first run
pathTo10X <- '/Run_1/'
fragments <- paste0(pathTo10X, 'fragments.tsv.gz')
regions <-  paste0(pathTo10X, 'peaks.bed')
metrics <- paste0(pathTo10X, 'singlecell.csv')
cisTopicObject1 <- createcisTopicObjectFrom10X(fragments, regions, metrics, project.name='Run_1', min.cells=0)
# We set min.cells=0 to keep all rows (regions). When combined, regions that are not accessible in any cell in any 
# of the runs will be taken out.

# Add _1 to cell names from run 1
cell.names <- cisTopicObject1@cell.names
new.cell.names <- paste0(cell.names, '_1')
cisTopicObject1 <- renameCells(cisTopicObject1, new.cell.names)

# Create object for the second run
pathTo10X <- '/Run_2/'
fragments <- paste0(pathTo10X, 'fragments.tsv.gz')
regions <-  paste0(pathTo10X, 'peaks.bed')
metrics <- paste0(pathTo10X, 'singlecell.csv')
cisTopicObject2 <- createcisTopicObjectFrom10X(fragments, regions, metrics, project.name='Run_2', min.cells=0)

# Add _2 to cell names from run 2
cell.names <- cisTopicObject2@cell.names
new.cell.names <- paste0(cell.names, '_2')
cisTopicObject2 <- renameCells(cisTopicObject2, new.cell.names)

# Combine data 

count.matrix <- cbind(cisTopicObject1@count.matrix, cisTopicObject2@count.matrix)
cell.data <- rbind(cisTopicObject1@cell.data, cisTopicObject2@cell.data)
region.data <- cbind(cisTopicObject1@region.data, cisTopicObject2@region.data) 

# Create combined cisTopicObject
cisTopicObjectCombined <- createcisTopicObject(count.matrix, project.name='Combined')
cisTopicObjectCombined <- addCellMetadata(cisTopicObjectCombined, cell.data)
cisTopicObjectCombined <- addRegionMetadata(cisTopicObjectCombined, region.data)

I hope this is useful, let me know if you have further questions :)

Cheers,

C

from cistopic.

ktpolanski avatar ktpolanski commented on July 19, 2024 1

Here's that same code snippet, but generalised into a for loop for easy loading of multiple samples. Needs to have samples set, and pathTo10X depend on the within-loop sample. Just leaving it here for posterity. Some sort of merging function would be nice eventually.

library(rlist)

count.matrix = list()
cell.data = list()
region.data = list()

samples = 
for (sample in samples)
{
	pathTo10X = 
	fragments = paste0(pathTo10X, 'fragments.tsv.gz')
	regions =  paste0(pathTo10X, 'peaks.bed')
	metrics = paste0(pathTo10X, 'singlecell.csv')
	cisTopicObject = createcisTopicObjectFrom10X(fragments, regions, metrics, project.name=sample, min.cells=0)

	# Add sample name to cell names
	cell.names = [email protected]
	new.cell.names = paste0(sample, '_', cell.names)
	cisTopicObject = renameCells(cisTopicObject, new.cell.names)

	# Store parts of object for collapsing later
	count.matrix[[sample]] = [email protected]
	cell.data[[sample]] = [email protected]
	region.data[[sample]] = [email protected]
}

# Combine data 
count.matrix = list.cbind(count.matrix)
cell.data = list.rbind(cell.data)
region.data = list.cbind(region.data) 

# Create combined cisTopicObject
cisTopicObjectCombined = createcisTopicObject(count.matrix, project.name='Combined')
cisTopicObjectCombined = addCellMetadata(cisTopicObjectCombined, cell.data)
cisTopicObjectCombined = addRegionMetadata(cisTopicObjectCombined, region.data)

from cistopic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.