<jupyter_start><jupyter_text>QC filtering<jupyter_code># Filter cells and genes
print(adata)
print(f'\n# remove genes expressed in less than 5 cells')
sc.pp.filter_genes(adata, min_cells=5)
print(f'# remove cell expressing less than 500 genes')
sc.pp.filter_cells(adata, min_genes=500)
print(adata)
print('\n# remove cells whose \n\t1. Tissue annotation is nan'
      + '\n\t2. n_counts is smaller than 5000')
adata.obs['n_counts'] = np.sum(adata.X, axis=1).A1
ind_select = (adata.obs['tissue']!='nan') & (adata.obs['age']!='nan') & \
            (adata.obs['n_counts']>=5000)
adata = adata[ind_select,]
print(adata)<jupyter_output>AnnData object with n_obs × n_vars = 164311 × 23341 
    obs: 'FACS.selection', 'age', 'batch', 'cell', 'cell_ontology_class', 'cell_ontology_id', 'cellid', 'free_annotation', 'method', 'mouse.id', 'plate', 'sex', 'subtissue', 'tissue', 'well', 'cell_ontology_class_reannotated', 'free_annotation_reannotated', 'cell_ontology_class_old', 'free_annotation_old', 'n_gene'

# remove genes expressed in less than 5 cells
# remove cell expressing less than 500 genes
AnnData object with n_obs × n_vars = 116690 × 22940 
    obs: 'FACS.selection', 'age', 'batch', 'cell', 'cell_ontology_class', 'cell_ontology_id', 'cellid', 'free_annotation', 'method', 'mouse.id', 'plate', 'sex', 'subtissue', 'tissue', 'well', 'cell_ontology_class_reannotated', 'free_annotation_reannotated', 'cell_ontology_class_old', 'free_annotation_old', 'n_gene', 'n_genes'
    var: 'n_cells'

# remove cells whose 
	1. Tissue annotation is nan
	2. n_counts is smaller than 5000
View of AnnData object with n_obs × n_vars = 115563 [...]<jupyter_text>Write the data<jupyter_code>adata.write(f'{data_path}/facs_filtered.h5ad')<jupyter_output>Trying to set attribute `.obs` of view, making a copy.
... storing 'FACS.selection' as categorical
Trying to set attribute `.obs` of view, making a copy.
... storing 'age' as categorical
Trying to set attribute `.obs` of view, making a copy.
... storing 'cell' as categorical
Trying to set attribute `.obs` of view, making a copy.
... storing 'cell_ontology_class' as categorical
Trying to set attribute `.obs` of view, making a copy.
... storing 'cell_ontology_id' as categorical
Trying to set attribute `.obs` of view, making a copy.
... storing 'cellid' as categorical
Trying to set attribute `.obs` of view, making a copy.
... storing 'free_annotation' as categorical
Trying to set attribute `.obs` of view, making a copy.
... storing 'method' as categorical
Trying to set attribute `.obs` of view, making a copy.
... storing 'mouse.id' as categorical
Trying to set attribute `.obs` of view, making a copy.
... storing 'plate' as categorical
Trying to set attribute `.obs` of view, making a copy.[...]<jupyter_text>Sequencing depth for different ages (Supp Figure 1C)<jupyter_code>adata.obs['n_counts_mil'] = adata.obs['n_counts']/1e6

plt.figure(figsize=[6,4])

plt.subplot(121)
sns.pointplot(x='age', y='n_counts_mil', data=adata.obs, order=['3m', '18m', '24m'])
plt.ylabel('Average reads per cell (million, 95 CI)')
plt.xlabel('Age')
plt.grid(linestyle='--')

plt.subplot(122)
sns.pointplot(x='age', y='n_gene', data=adata.obs, order=['3m', '18m', '24m'])
plt.ylabel('Average expressed genes per cell (95 CI)')
plt.xlabel('Age')
plt.grid(linestyle='--')
plt.tight_layout()
plt.savefig('/home/martin/maca/results/tms_gene_figure'
            + '/qc_depth.pdf', transparent=True)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15262550490478938, 'fraction_numerical': 0.024235429890363532, 'mean_word_length': 5.326642335766423, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '659180', 'license': 'MIT', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1198, 'n_words': 352, 'path': '2_aging_signature/archive_initial_submission/filter_FACS.ipynb', 'repo_name': 'gmstanle/msc_aging', 'size': '3466'}