I have a large concatenated anndata object (15 samples) where I want to add columns of metadata. I have so far done it in a very long-written way as I show below:
# list of all sample id's sampleid_list = ['A', 'B', 'C', 'D', 'E', 'F'] # categorize each individually ctrl = ['A', 'B', 'C'] disease = ['D', 'E', 'F'] # ctrl vs disease adata.obs['sample_type'] = 'disease' adata.obs.loc[adata.obs['sampleid_list'].isin(ctrl),'sample_type'] = 'ctrl'
I have a lot of metadata and the code gets very long with this approach. I would prefer if there was a way to make a csv-file where I add all the information necessary, import the dataframe, and add to the anndata object.
I tried this approach, but got an error that the length was not matching the anndata object:
metadata = pd.read_csv('/Users/xx/csv-files/metadata.csv', delimiter = ';', header=0) metadata=metadata.set_index('sampleid') adata.obs = metadata
So, my question is - is there a way to add metadata from a csv file to concatenated data? If not, is there a way to do this from a file before concatenation?
I am a beginner in both bioinformatics and single cell analysis without so many people to ask, so any help would be highly appreciated!
Thank you in advance!