{"id":14977100,"url":"https://github.com/carsonsgit/mice-neural-decoding-ml","last_synced_at":"2025-10-27T23:31:50.717Z","repository":{"id":254784513,"uuid":"820672689","full_name":"carsonSgit/Mice-Neural-Decoding-ML","owner":"carsonSgit","description":"Decoding mouse navigation decisions by analyzing L2/3 neuron activity in the retrosplenial cortex, following the findings of Tseng et al. (2022) in their Neuron Paper.","archived":false,"fork":false,"pushed_at":"2024-08-26T03:40:28.000Z","size":952,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-11T14:42:20.530Z","etag":null,"topics":["hackathon-project","jupyter","machine-learning","neuroscience","python"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/carsonSgit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-27T00:27:10.000Z","updated_at":"2024-09-17T01:39:03.000Z","dependencies_parsed_at":"2024-08-26T04:52:48.156Z","dependency_job_id":"c43a1c3b-e799-45b3-8550-6aaf0e158c50","html_url":"https://github.com/carsonSgit/Mice-Neural-Decoding-ML","commit_stats":null,"previous_names":["carsonsgit/mice-neural-decoding-ml"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carsonSgit%2FMice-Neural-Decoding-ML","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carsonSgit%2FMice-Neural-Decoding-ML/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carsonSgit%2FMice-Neural-Decoding-ML/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carsonSgit%2FMice-Neural-Decoding-ML/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/carsonSgit","download_url":"https://codeload.github.com/carsonSgit/Mice-Neural-Decoding-ML/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219860467,"owners_count":16556017,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hackathon-project","jupyter","machine-learning","neuroscience","python"],"created_at":"2024-09-24T13:55:03.191Z","updated_at":"2025-10-27T23:31:45.316Z","avatar_url":"https://github.com/carsonSgit.png","language":"Jupyter Notebook","readme":"# 🧬 Neural Decoding - PharmaHacks2024 💊\n\nWelcome to our teams' repository for McGill's PharmaHacks Neural Decoding challenge! If you are interested in viewing our code, you can click [here](./PharmaHacks%202024%20Neural%20Decoding%20Single%20File.ipynb) to open the notebook.\n\n## 🏬 Our Team \n\u003e Hyperlinks lead to LinkedIn profiles*\n-  **[Marcus Lee](https://www.linkedin.com/in/marcus-lee-3b5298264/)** DEC, Computer Science \u0026 Math @ Vanier College 💻\n-  **[Carson Spriggs-Audet](https://www.linkedin.com/in/carson-spriggs-audet-609372217/)** DEC, Computer Science @ John Abbott College 💻\n-  **[Jiwon Kim](https://www.linkedin.com/in/jiwon-kim-32b39a261/)** BS, Life Science | Brain \u0026 Cognivitive Science @ Korea University 🧠\n-  **[Seungyeon Lee](https://www.linkedin.com/in/seungyeon-lee/)** BS, Neuroscience, Minor in Computer Science @ McGill 🧠\n-  **[Amélie Beaudin](https://www.linkedin.com/in/am%C3%A9lie-beaudin-60241b248/)** BS, Computer Science @ McGill 💻\n\n## ⭐ PharmaHacks\n\n[PharmaHacks](https://www.linkedin.com/company/pharmahacks/) is a hackathon organized by students of McGill University. PharmaHacks' mission is to \"provide interested students with bioinformatics/cheminformatics training through extracurricular means to prepare them for future jobs in industry, academia, and government.\"[^1]\n\nWe want to thank the [organizers](https://pharmahacks.com/Team) for putting together such an amazing event, we look forward to future events!\n\n\u003e[!NOTE]\n\u003ePharmaHacks 2024 had two challenges;\n\u003e - **Neural Decoding:** From Calcium Imaging Data, analyze and predict results from neural activity.\n\u003e - **Genomics:** Using scRNA-seq data, predict Covid-19 case severity in patients\n\n\n\n[^1]: [PharmaHacks' LinkedIn](https://www.linkedin.com/company/pharmahacks/)\n\n## :label: Problem Description\n\n**Neuroscientist \u0026 Dr. [Shih-Yi Tseng](https://www.linkedin.com/in/shih-yi-tseng/) et al.** published a [Neuron paper](https://www.cell.com/neuron/fulltext/S0896-6273(22)00453-6?_returnURL=https%3A%2F%2Flinkinghub.elsevier.com%2Fretrieve%2Fpii%2FS0896627322004536%3Fshowall%3Dtrue) documenting their experiments performed on 8 mice. The experiment captures over 200,000 neurons over 6 areas of the mices' posterior cortices; L2/3 and L5, V1, secondary visual areas, Retrosplenial Cortex (RSC), and the Posterior Parietal Cortext (PPC).\n\n![image](https://github.com/GodPuffin/Pharmahacks2024/assets/92652800/544abb7a-615f-4bdb-a226-fa71bf0a38e8)\n###### *Image source: Tseng, Shih-Yi, et al. “Shared and specialized coding across posterior cortical areas for dynamic navigation decisions.” Neuron, vol. 110, no. 15, Aug. 2022, https://doi.org/10.1016/j.neuron.2022.05.012.*\n\u003e The mice are given two possibilities, **black** walls or white walls. The correct choice of turning is according to two rules.\n\u003e\u003e **Rule A:** the mice must turn **left** when the walls are **black** and **right** when the walls are **white**.\n\u003e\u003e \n\u003e\u003e **Rule B:** the mice must turn **right** when the walls are **black** and **left** when the walls are **white**.\n\n\u003cbr /\u003e\n\n![image](https://github.com/GodPuffin/Pharmahacks2024/assets/92652800/4b7fac34-1043-4a85-8155-b0442ff2bd58)\n###### *Image source: Tseng, Shih-Yi, et al. “Shared and specialized coding across posterior cortical areas for dynamic navigation decisions.” Neuron, vol. 110, no. 15, Aug. 2022, https://doi.org/10.1016/j.neuron.2022.05.012.*\n\u003e The maze the mice were trialed in is shown above.\n\u003e\n\u003e It is a Y-shaped maze with two choices, **left** or **right**. After they make their turn, they are looped back to the beginning of the maze \u0026 trialed again (approx. 400 trials per day of experimenting).\n\n\u003cbr /\u003e\n\nThanks to their experiment, we are able to access the mices' neural data and analyze what neuron activation corresponds to navigation decision making. \n\nFrom the [data provided](https://dandiarchive.org/dandiset/000579) by the researchers, we were tasked with creating a Machine Learning model that would be able to predict a mouse's position in the maze.\n\n\n## 🤔 Problem Approach\n\n### 📝 Analysis \n\nOur first mission was to understand the data. after thorough research \u0026 analysis of the neural paper \u0026 use tutorial of the data, we narrowed down our focus to these specific factors:\n- **The RSC:** We chose to isolate our focus on the RSC due to it's functions encompassing navigation and spacial memory. \n- **The L2/3 neurons:** Our data presented us with the L2/3 layers \u0026 the L5 in separate files. We decided on working with the L2/3 due to its relations in processing sensory information. \n- **Multi-plane images:** Having been given the option between Single-Plane \u0026 Multi-Plane imaging, we chose to go with Multi-Plane so that we had more comprehensive data to work with. \n\n### 🔧 Data processing\n\nThe data has 4 deconvoluted planes, each of which are desynchronized from one another \u0026 have many NaN (missing) values. Below was our process to resolve these issues;\n\n- **Unsynchronized data:** \n    - Join all **4 deconvoluted planes** together. \n    - Format the columns to accurately reference to the Timestamp data (Timestamp of neuron activity capture). \n    - Divide unsynchronized data into chunks and align it accordingly.\n\n- **NaN values:** Two methods of resolution\n    - Dropped all NaNs and saved in a new set. \n    - Utilized an IterativeImputer model to impute what the missing data should be according to it's surrounding data values. \n\n### 🤖 Machine Learning Models\n\nOnce it came down to choosing a model, we had to research different categories of models. Through our prior analysis, we knew we wanted to use something of the classification/regression sort which led us to using a **RandomForestRegressor**. \n\n\u003e What is a **RandomForestRegressor**?\n\u003e\u003e To explain this, first we have to look at what a **DecisionTreeRegressor** is. \n\u003e\u003e A DecisionTreeRegressor is a model that recursively splits the training data into partitions. \n\u003e\u003e These splits allow for the model to choose which data best fits the training data \u0026 predicts off of the most accurate splits (leafs). \n\u003e\u003e\u003e So what *is* a **RandomForestRegressor**?\n\u003e\u003e\u003e A RandomForestRegressor creates \u0026 trains multiple *DecisionTreeRegressors* on subsets of the data. It then chooses the DecisionTreeRegressors with the lowest error indicators \u0026 averages them together to create the most accurate possible version. \n\n### 🎉 Result\n\nOur two models had the following **MSEs**:\n- Model using **Dropped NaNs:** *MSE* of **0.047**\n- Model using **Iterative imputer**: *MSE* of **0.046**\n\n#### 📈 Graphs\n\nBelow are the graphs for our model results.\n\n**🏃‍♂️ Overview of forward movement prediction results:**\n\n![image](https://github.com/GodPuffin/Pharmahacks2024/assets/92652800/a9a2a917-5516-4b98-8dd8-5a366f4c0c9e)\n\n**🏃‍♂️ Zoom-in of forward movement prediction results:**\n\n![image](https://github.com/GodPuffin/Pharmahacks2024/assets/92652800/d65cb625-f370-4d8d-b31d-53a9798b6c14)\n\n\u003e Here we have a general view of our models vs. the actual data for the forward movement of the mouse in the maze.\n\u003e\u003e **Blue plotting:** Actual data.\n\u003e\u003e \n\u003e\u003e **Orange:** Dropped NaN model predictions. We can see that the model predicts closely to the actual neural data though there are few inaccuracies in it's predictions (dips \u0026 spikes) though it mostly follows the same trajectory as the actual data.\n\u003e\u003e \n\u003e\u003e **Green:** Iterative Imputer model predictions. In the beginning of the Overview graph, we can see a slight buffer before the graphing begins. This is due to the modeel analyzing the data first and it then begins to predict once it has a grasp on how it should be predicting.\n\n**⤵️ Overview of lateral movement prediction results:**\n\n![image](https://github.com/GodPuffin/Pharmahacks2024/assets/92652800/e6b07a91-1680-44fc-92e4-a2ec423660f8)\n\n**⤵️ Zoom-in of lateral movement prediction results:**\n\n![image](https://github.com/GodPuffin/Pharmahacks2024/assets/92652800/28fd5d65-34b6-4118-a349-0698255f61ec)\n\n\u003e In these charts, we see the difference in predictions of our models vs. the real lateral movement data.\n\u003e\u003e **Blue plotting:** Actual data.\n\u003e\u003e\n\u003e\u003e **Orange:** Dropped NaN model predictions. The dropped NaN model follows the same trend as the actual data with some hiccups.\n\u003e\u003e\n\u003e\u003e **Green:** Iterative Imputer model predictions. We can see that the imputed data model quite accurately follows the actual data.\n\n### 🔍 Result analysis\n\nThrough analyzation of the graphs, we can see that while there are a few hiccups, our **models** are quite **successful** in their **predictions of the neural navigation activation**. Due to the lack of time and computing resources, we were only able to train our models\noff of *one* *.nwb (Neurodata Without Borders file-type) file. Having only been trained on one file, our models still resulted in MSE's of 0.046 \u0026 0.047 which we see as very good results.\n\nIn our **model that dropped all NaNs**, we see that the model closely predicts the actual data though in some instances *overfits* which can be expected when we remove data in a case such as this.\n\nOn the side of our **imputed model**, we see that the model is more *active* in it's predictions, making more movement than both the dropped NaN model \u0026 the actual data. Again, this makes sense as when you impute over missing values, it can lead to more variance in prediction.\n\n# 📖 End\n\nThough we did not win, we ultimately all enjoyed our time at PharmaHacks 2024. Again, thank you to the PharmaHacks team for organizing such a fun and educational event.\n\n\u003e[!IMPORTANT]\n\u003e Here is the link to the [team](https://pharmahacks.com/Team) on their website.\n\u003e\n\u003e Here is the link to their [LinkedIn](https://www.linkedin.com/company/pharmahacks/).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarsonsgit%2Fmice-neural-decoding-ml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcarsonsgit%2Fmice-neural-decoding-ml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarsonsgit%2Fmice-neural-decoding-ml/lists"}