<jupyter_start><jupyter_text>Load<jupyter_code>barcodes = pd.read_csv(
    os.path.join(path_data, "peak_counts/cells.csv.gz"),
    skiprows=[0], header=None
)[1]
barcodes
peaks = pd.read_csv(
    os.path.join(path_data, "peak_counts/peaks.csv.gz"),
    index_col=0
)
peaks
counts = scipy.io.mmread(
    os.path.join(path_data, "peak_counts/counts.mtx.gz")
)<jupyter_output><empty_output><jupyter_text>Construct AnnData<jupyter_code>adata = sc.AnnData(counts.T)
adata
adata.obs_names = barcodes
adata.var_names = peaks.index
for col in ['distToGeneStart', 'nearestGene', 'peakType', 'distToTSS', 'nearestTSS','replicateScoreQuantile']:
    adata.var[col] = peaks[col]
adata<jupyter_output><empty_output><jupyter_text>SVD<jupyter_code>pd.read_csv(
    os.path.join(path_data, "svd.csv"),
    index_col=0
).loc[adata.obs_names, : ].values
adata.obsm["X_svd"] = pd.read_csv(
    os.path.join(path_data, "svd.csv"),
    index_col=0
).values<jupyter_output><empty_output><jupyter_text>UMAP<jupyter_code>pd.read_csv(
    os.path.join(path_data, "umap.csv"),
    index_col=0
).values
adata.obsm["umap"] = pd.read_csv(
    os.path.join(path_data, "umap.csv"),
    index_col=0
).values<jupyter_output><empty_output><jupyter_text>Metadata<jupyter_code>df_meta = pd.read_csv(
    os.path.join(path_data, "cell_metadata.csv"),
    index_col=0
)
df_meta
for col in df_meta.columns:
    adata.obs[col] = df_meta[col].values<jupyter_output><empty_output><jupyter_text>Gene Scores<jupyter_code>df_gene_scores = pd.read_csv(
    os.path.join(path_data, "gene_scores.csv.gz"),
    index_col=0
).T
df_gene_scores
adata.obsm['GeneScores'] = df_gene_scores.values
adata.uns['GeneScoresColumns'] = df_gene_scores.columns.values
adata
sc.pl.umap(adata)
# a writer for type <class 'scipy.sparse.coo.coo_matrix'> has not been implemented yet.
from scipy.sparse import csr_matrix

adata.X = csr_matrix(adata.X)
adata.write(
    os.path.join(path_data, "preprocessed.h5ad")
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15015166835187058, 'fraction_numerical': 0.005055611729019211, 'mean_word_length': 5.992932862190813, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '329488', 'license': 'MIT', 'n_tokens_mistral': 854, 'n_tokens_neox': 825, 'n_words': 103, 'path': 'scripts/archr2adata.ipynb', 'repo_name': 'hisplan/archr2adata', 'size': '1978'}