using scanpy to merge objects
Entering edit mode
11 months ago
Andy ▴ 120

Good afternoon,

I meet a question to merge my objects by using scanpy.

As you can see in the following figure, each objects has obs * var values. But after I merge them the adata has 0 vars.

The code I used is:

adatas=[sk1, sk2, sk3, b7]
adatas=ad.concat(adatas, merge='same')

I am wondering how to solve the problem. Thanks.

enter image description here

scanpy scRNA-seq single-cell • 4.3k views
Entering edit mode

The way how I input the object, I believe I did them right.

For b7 which is a civ file, I did:

b7=sc.read_text("path/to/file/file.csv", delimiter=',').T


sk1=sc.read_10x_h5('path/to/file/filtered_feature_bc_matrix.h5', genome=None, gex_only=True) sk1.var_names_make_unique()

Entering edit mode

I have an assumption that I may have obtained the 'wrong' CSV file. I obtained this CSV file from an RDS file, and I believe I made a mistake. I double-checked and realized that I lost the, which will cause significant trouble in the subsequent steps. Therefore, my question now is: How can I obtain a matrix with from an RDS file?

Entering edit mode
8 months ago
yl759 ▴ 120

My understanding of your goal is to combine multiple 10x datasets for your downstream analysis. In that case, according to the documentation, you will lose a lot of data that are unique in each object by using the merge option.

”same”: Elements that are the same in each of the objects.

I think you should do:

adatas = [sk1, sk2, sk3, b7]
adatas = ad.concat(adatas,  join="outer")

To better label your objects for the downstream analysis, you could try to do:

adatas = {"sk1": sk1, "sk2": sk2, "sk3": sk3, "b7": b7}
adatas = ad.concat(adatas, label="dataset_name",  join="outer")

By giving a dictionary and setting the label argument, the concatenated AnnData object will have an additional column called dataset_name, indicating the original object name. You can add index_unique="a_string" to make your index unique, otherwise, the default option will keep the original index. Also, because you are using the "outer" option, you should set a default value for the missing cells by adding fill_value=Optional[Any].


Login before adding your answer.

Traffic: 1130 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6