|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "id": "f2b11fab-44ce-4100-b7f4-aa28689364e6", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "import logging\n", |
| 11 | + "logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR)\n", |
| 12 | + "import scanpy as sc\n", |
| 13 | + "import scvelo as scv\n", |
| 14 | + "import scvi\n", |
| 15 | + "import plotly.express as px\n", |
| 16 | + "import numpy as np\n", |
| 17 | + "from dash import Dash, dcc, html, Input, Output\n", |
| 18 | + "\n", |
| 19 | + "import pandas as pd\n", |
| 20 | + "\n", |
| 21 | + "import os\n", |
| 22 | + "import sys\n", |
| 23 | + "import time\n", |
| 24 | + "os.environ['R_HOME'] = sys.exec_prefix+\"/lib/R/\"\n", |
| 25 | + "\n", |
| 26 | + "# Plotting\n", |
| 27 | + "import matplotlib\n", |
| 28 | + "import matplotlib.pyplot as plt\n", |
| 29 | + "import matplotlib as mpl\n", |
| 30 | + "\n", |
| 31 | + "project_directory = '/Cranio_Lab/Louk_Seton/4_species_project'\n", |
| 32 | + "os.chdir(os.path.expanduser(\"~\")+project_directory)" |
| 33 | + ] |
| 34 | + }, |
| 35 | + { |
| 36 | + "cell_type": "code", |
| 37 | + "execution_count": null, |
| 38 | + "id": "cbb1cd63-6fbf-4587-890d-beb22fae5d94", |
| 39 | + "metadata": {}, |
| 40 | + "outputs": [], |
| 41 | + "source": [ |
| 42 | + "######Mouse mm10######\n", |
| 43 | + "start_time=time.strftime(\"%Y_%m_%d-%I_%M_%S_%p\")\n", |
| 44 | + "print('start time:',start_time)\n", |
| 45 | + "\n", |
| 46 | + "sample_names = ['ME8','ME9','ME10','ME11','ME12'] #specify the sample names\n", |
| 47 | + "species = 'mouse' #specify the species\n", |
| 48 | + "genome = 'mm10' #specify the genome\n", |
| 49 | + "output_prefix = 'cellranger_related/cellranger_output/sc_rnaseq/' #specify the location of the cellranger output\n", |
| 50 | + "\n", |
| 51 | + "cellranger_locs = []\n", |
| 52 | + "velocyto_locs = []\n", |
| 53 | + "\n", |
| 54 | + "for sample in sample_names: #simple loop to create a list with the location of the required files\n", |
| 55 | + " cellranger_locs = cellranger_locs + [output_prefix+species+'/'+genome+'/'+sample+'/outs/filtered_feature_bc_matrix/']\n", |
| 56 | + " velocyto_locs = velocyto_locs + [output_prefix+species+'/'+genome+'/'+sample+'/velocyto/'+sample+'.loom']\n", |
| 57 | + "\n", |
| 58 | + "adata_files={}\n", |
| 59 | + "adata_list=[]\n", |
| 60 | + "print(time.strftime(\"%Y_%m_%d-%I_%M_%S_%p\"),'Reading file(s)')\n", |
| 61 | + "for i,j,k in zip(sample_names, cellranger_locs, velocyto_locs):\n", |
| 62 | + " adata_cellr = sc.read_10x_mtx(j)\n", |
| 63 | + " adata_cellr.obs.index = adata_cellr.obs.index.str[:-2]\n", |
| 64 | + " adata_cellr.var['gene_name'] = adata_cellr.var.index\n", |
| 65 | + " adata_cellr.var.index = adata_cellr.var['gene_ids']\n", |
| 66 | + " adata_veloc = sc.read(k)\n", |
| 67 | + " adata_veloc.obs.index = adata_veloc.obs.index.str.split(':').str[1]\n", |
| 68 | + " adata_veloc.obs.index = adata_veloc.obs.index.str[:-1]\n", |
| 69 | + " adata_veloc.var['gene_name'] = adata_veloc.var.index\n", |
| 70 | + " adata_veloc.var.index = adata_veloc.var['Accession']\n", |
| 71 | + " adata_merge = scv.utils.merge(adata_cellr, adata_veloc)\n", |
| 72 | + " adata_files['adata'+i]=adata_merge\n", |
| 73 | + " adata_files['adata'+i].obs['sample']=i\n", |
| 74 | + " adata_files['adata'+i].obs['barcode']=adata_files['adata'+i].obs.index\n", |
| 75 | + " adata_files['adata'+i].obs.index=adata_files['adata'+i].obs['barcode']+'.'+adata_files['adata'+i].obs['sample']\n", |
| 76 | + " adata_list.append('adata'+i)\n", |
| 77 | + " del adata_cellr\n", |
| 78 | + " del adata_veloc\n", |
| 79 | + " del adata_merge\n", |
| 80 | + " gc.collect()\n", |
| 81 | + "print(time.strftime(\"%Y_%m_%d-%I_%M_%S_%p\"),'Finished Reading file(s)')" |
| 82 | + ] |
| 83 | + }, |
| 84 | + { |
| 85 | + "cell_type": "code", |
| 86 | + "execution_count": null, |
| 87 | + "id": "15c33e3e-deb3-4642-9a46-f762db5c7a3f", |
| 88 | + "metadata": {}, |
| 89 | + "outputs": [], |
| 90 | + "source": [] |
| 91 | + } |
| 92 | + ], |
| 93 | + "metadata": { |
| 94 | + "kernelspec": { |
| 95 | + "display_name": "scanpy_2025", |
| 96 | + "language": "python", |
| 97 | + "name": "scanpy_2025" |
| 98 | + }, |
| 99 | + "language_info": { |
| 100 | + "codemirror_mode": { |
| 101 | + "name": "ipython", |
| 102 | + "version": 3 |
| 103 | + }, |
| 104 | + "file_extension": ".py", |
| 105 | + "mimetype": "text/x-python", |
| 106 | + "name": "python", |
| 107 | + "nbconvert_exporter": "python", |
| 108 | + "pygments_lexer": "ipython3", |
| 109 | + "version": "3.11.11" |
| 110 | + } |
| 111 | + }, |
| 112 | + "nbformat": 4, |
| 113 | + "nbformat_minor": 5 |
| 114 | +} |
0 commit comments