Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions src/modules/Load_file&preprocessing_DEMO.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "787e38a9-14a5-41f1-9186-e68008bc80c3",
"metadata": {},
"outputs": [],
"source": [
"import scanpy as sc\n",
"\n",
"def load_file_demo(file_path):\n",
" adata = sc.read_h5ad(file_path) # load h5ad file\n",
" adata.write(\"adata_demo.h5ad\") # save a new demo file\n",
" print(\"Data saved as adata_demo.h5ad\")\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "32cc9e28-f9df-4a12-bcab-4a152fc18855",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data saved as adata_demo.h5ad\n"
]
}
],
"source": [
"#run\n",
"file_path = \"/Users/azratuncay/Desktop/IEEE/untitled folder/Hw3covid_Data_AllCells.h5ad\"\n",
"load_file_demo(file_path)\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "aa346737-f100-4684-88b8-d971b013624b",
"metadata": {},
"outputs": [],
"source": [
"import scanpy as sc\n",
"\n",
"def preprocess_demo(adata_path):\n",
" adata = sc.read_h5ad(adata_path) # download the saved demo file \n",
" print(\"Data loaded successfully for preprocessing demo.\")\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "8b0be686-d27d-46fa-8142-6ac196f49fcd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data loaded successfully for preprocessing demo.\n"
]
}
],
"source": [
"#run\n",
"adata_path = \"adata_demo.h5ad\"\n",
"preprocess_demo(adata_path)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "06a5bd7f-f9d5-42c3-b46a-aeda392a4664",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
5 changes: 5 additions & 0 deletions src/modules/load_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import scanpy as sc

def load_file(file_path):
adata = sc.read_10x_mtx(file_path, var_names='gene_symbols', cache=True)
return adata
11 changes: 11 additions & 0 deletions src/modules/preprocessing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import scanpy as sc

def preprocess(adata, target_sum = 1e4, max_value = 10):
data_normalization(adata, target_sum, max_value)
#other preprocessing methods here

def data_normalization(adata, target_sum, max_value):
sc.pp.normalize_total(adata, target_sum)
sc.pp.log1p(adata)
sc.pp.regress_out(adata, ['total_counts', 'pct_counts_mt'])
sc.pp.scale(adata, max_value)