From 3c59f01c56f2c1331460d006fb9e1d3dadefad7e Mon Sep 17 00:00:00 2001 From: yasinthanvickneswaran Date: Thu, 15 Feb 2024 11:56:59 +0000 Subject: [PATCH 1/2] VarshneyDataReader --- c302/SpreadsheetDataReader.py | 2 +- c302/VarshneyDataReader.py | 78 ++++++++++++++++----------------- c302/W_SpreadsheetDataReader.py | 9 +++- examples/test/Comparison.ipynb | 42 ++++++++++++------ 4 files changed, 77 insertions(+), 54 deletions(-) diff --git a/c302/SpreadsheetDataReader.py b/c302/SpreadsheetDataReader.py index 66dc0fda..9d8a26f2 100644 --- a/c302/SpreadsheetDataReader.py +++ b/c302/SpreadsheetDataReader.py @@ -22,7 +22,7 @@ READER_DESCRIPTION = """Data extracted from CElegansNeuronTables.xls for neuronal connectivity""" -def read_data(include_nonconnected_cells=False, neuron_connect=False): +def read_data(include_nonconnected_cells=False, neuron_connect=True): diff --git a/c302/VarshneyDataReader.py b/c302/VarshneyDataReader.py index c34739f4..3c386717 100644 --- a/c302/VarshneyDataReader.py +++ b/c302/VarshneyDataReader.py @@ -1,68 +1,68 @@ from c302.NeuroMLUtilities import ConnectionInfo from c302.NeuroMLUtilities import analyse_connections +from openpyxl import load_workbook -from xlrd import open_workbook import os spreadsheet_location = os.path.dirname(os.path.abspath(__file__))+"/data/" from c302 import print_ -READER_DESCRIPTION = """Data extracted from NeuronConnectFormatted.xls for neuronal connectivity""" - -def read_data(include_nonconnected_cells=False, neuron_connect=True): +READER_DESCRIPTION = """Data extracted from NeuronConnectFormatted.xlsx for neuronal connectivity""" +def read_data(include_nonconnected_cells=False, neuron_connect=True): -# reading the NeuronConnectFormatted.xls file if neuron_connect = True if neuron_connect: conns = [] cells = [] - filename = "%sNeuronConnectFormatted.xls"%spreadsheet_location - rb = open_workbook(filename) - print_("Opened the Excel file: " + filename) - - for row in range(1,rb.sheet_by_index(0).nrows): - pre = str(rb.sheet_by_index(0).cell(row,0).value) - post = str(rb.sheet_by_index(0).cell(row,1).value) - syntype = rb.sheet_by_index(0).cell(row,2).value - num = int(rb.sheet_by_index(0).cell(row,3).value) + filename = "%sNeuronConnectFormatted.xlsx"%spreadsheet_location + wb = load_workbook(filename) + sheet = wb.worksheets[0] + print_("Opened the Excel file: " + filename) + + for row in sheet.iter_rows(min_row=2, values_only=True): # Assuming data starts from the second row + pre = str(row[0]) + post = str(row[1]) + syntype = str(row[2]) + num = int(row[3]) synclass = 'Generic_GJ' if 'EJ' in syntype else 'Chemical_Synapse' conns.append(ConnectionInfo(pre, post, num, syntype, synclass)) if pre not in cells: - cells.append(pre) + cells.append(pre) if post not in cells: cells.append(post) - + return cells, conns else: conns = [] cells = [] - filename = "%sCElegansNeuronTables.xls"%spreadsheet_location - rb = open_workbook(filename) + filename = "%sNeuronConnectFormatted.xlsx"%spreadsheet_location + wb = load_workbook(filename) + sheet = wb.worksheets[0] - print_("Opened Excel file: " + filename) + print_("Opened Excel file..: " + filename) known_nonconnected_cells = ['CANL', 'CANR', 'VC6'] + + for row in sheet.iter_rows(min_row=2, values_only=True): + pre = str(row[0]) + post = str(row[1]) + syntype = str(row[2]) + num = int(row[3]) + synclass = 'Generic_GJ' if 'EJ' in syntype else 'Chemical_Synapse' - for row in range(1,rb.sheet_by_index(0).nrows): - pre = str(rb.sheet_by_index(0).cell(row,0).value) - post = str(rb.sheet_by_index(0).cell(row,1).value) - syntype = rb.sheet_by_index(0).cell(row,2).value - num = int(rb.sheet_by_index(0).cell(row,3).value) - synclass = rb.sheet_by_index(0).cell(row,4).value - conns.append(ConnectionInfo(pre, post, num, syntype, synclass)) if pre not in cells: - cells.append(pre) + cells.append(pre) if post not in cells: cells.append(post) - if include_nonconnected_cells: - for c in known_nonconnected_cells: cells.append(c) + if include_nonconnected_cells: + for c in known_nonconnected_cells: cells.append(c) return cells, conns @@ -72,24 +72,24 @@ def read_muscle_data(): neurons = [] muscles = [] - filename = "%sNeuronConnectFormatted.xls"%spreadsheet_location - rb = open_workbook(filename) + filename = "%sNeuronConnectFormatted.xlsx"%spreadsheet_location + wb = load_workbook(filename) + sheet = wb.worksheets[0] print_("Opened Excel file: "+ filename) - sheet = rb.sheet_by_index(0) + for row in sheet.iter_rows(min_row=2, values_only=True): # Assuming data starts from the second row + pre = str(row[0]) + post = str(row[1]) + syntype = str(row[2]) + num = int(row[3]) + synclass = 'Generic_GJ' if 'EJ' in syntype else 'Chemical_Synapse' - for row in range(1,sheet.nrows): - pre = str(sheet.cell(row,0).value) - post = str(sheet.cell(row,1).value) - num = int(sheet.cell(row,3).value) - syntype = 'Send' - synclass = sheet.cell(row,2).value.replace(',', 'plus').replace(' ', '_') conns.append(ConnectionInfo(pre, post, num, syntype, synclass)) if pre not in neurons: neurons.append(pre) - if post not in muscles: + if syntype == "NMJ": muscles.append(post) diff --git a/c302/W_SpreadsheetDataReader.py b/c302/W_SpreadsheetDataReader.py index e7f8097e..316c2c44 100644 --- a/c302/W_SpreadsheetDataReader.py +++ b/c302/W_SpreadsheetDataReader.py @@ -3,11 +3,15 @@ from openpyxl import load_workbook import os +from c302 import print_ + spreadsheet_location = os.path.dirname(os.path.abspath(__file__))+"/data/" -from c302 import print_ + + + class WitvlietDataReader1: @@ -83,6 +87,9 @@ def read_muscle_data(): print_("Opened Excel file: "+ filename) for row in sheet.iter_rows(min_row=2, values_only=True): + if not (is_neuron(pre) or is_body_wall_muscle(pre)) or not is_body_wall_muscle(post): + continue + pre = str(row[0]) post = str(row[1]) syntype = str(row[2]) diff --git a/examples/test/Comparison.ipynb b/examples/test/Comparison.ipynb index 1298eea7..c302b64b 100644 --- a/examples/test/Comparison.ipynb +++ b/examples/test/Comparison.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 23, + "execution_count": 1, "id": "481d3c70-313a-4979-8475-d4a0089a8a0b", "metadata": { "tags": [] @@ -33,6 +33,22 @@ "c302 >>> Total connections found 926 \n", "\n", "****** Importing dataset WormNeuroAtlas using c302.WormNeuroAtlasReader ******\n", + "*This version of the NeuroAtlas does not include the CAN neurons. This will be fixed soon.\n", + "*In loading the anatomical connectome, the following conventions are used to allow for its comparison with the other datasets: AWCL->AWCOFF and AWCR->AWCON\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "c:\\Users\\vyasi\\anaconda3\\envs\\ProWorm\\lib\\site-packages\\wormneuroatlas\\WormBase.py:52: UserWarning: Wormbase.org updated its database to a new version (WS291). The version of Worm Neuro Atlas that you are using has been built for the wormbase database version WS287. To ensure reproducible results, upgrade Worm Neuro Atlas with `python -m pip install --upgrade wormneuroatlas` If this warning persists after upgrading, let the developers know by opening an issue here: https://github.com/francescorandi/wormneuroatlas/issues. NOTE: You can still use Worm Neuro Atlas in the meantime. The metadata accessible via wormneuroatlas.WormBase.get_metadata() and wormneuroatlas.NeuroAtlas.get_metadata() contain the version of wormbase that you are currently using, so make sure you save the metadata alongside your results. \n", + " warnings.warn(w)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ "c302 >>> Initialising WormNeuroAtlasReader\n", "\n", "****** Importing dataset Varshney using c302.VarshneyDataReader ******\n", @@ -40,12 +56,12 @@ "c302 >>> Opened Excel file: c:\\Users\\vyasi\\anaconda3\\envs\\ProWorm\\lib\\site-packages\\c302/data/NeuronConnectFormatted.xls\n", "\n", "****** Importing dataset Witvliet(1) using c302.W_SpreadsheetDataReader ******\n", - "c302 >>> Opened Excel file..: c:\\Users\\vyasi\\anaconda3\\envs\\ProWorm\\lib\\site-packages\\c302/data/witvliet_2020_1.xlsx\n", - "c302 >>> Opened Excel file: c:\\Users\\vyasi\\anaconda3\\envs\\ProWorm\\lib\\site-packages\\c302/data/witvliet_2020_1.xlsx\n", + "c302 >>> Opened Excel file..: c:\\Users\\vyasi\\anaconda3\\envs\\ProWorm\\lib\\site-packages\\c302/data/witvliet_2020_7.xlsx\n", + "c302 >>> Opened Excel file: c:\\Users\\vyasi\\anaconda3\\envs\\ProWorm\\lib\\site-packages\\c302/data/witvliet_2020_7.xlsx\n", "\n", "****** Importing dataset Witvliet(2) using c302.W_SpreadsheetDataReader ******\n", - "c302 >>> Opened Excel file..: c:\\Users\\vyasi\\anaconda3\\envs\\ProWorm\\lib\\site-packages\\c302/data/witvliet_2020_2.xlsx\n", - "c302 >>> Opened Excel file: c:\\Users\\vyasi\\anaconda3\\envs\\ProWorm\\lib\\site-packages\\c302/data/witvliet_2020_2.xlsx\n" + "c302 >>> Opened Excel file..: c:\\Users\\vyasi\\anaconda3\\envs\\ProWorm\\lib\\site-packages\\c302/data/witvliet_2020_8.xlsx\n", + "c302 >>> Opened Excel file: c:\\Users\\vyasi\\anaconda3\\envs\\ProWorm\\lib\\site-packages\\c302/data/witvliet_2020_8.xlsx\n" ] } ], @@ -140,7 +156,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 2, "id": "2308051a-0a24-44db-a481-fc0d0f2af4fb", "metadata": { "tags": [] @@ -172,8 +188,8 @@ " 302\n", " 300\n", " 281\n", - " 190\n", - " 197\n", + " 225\n", + " 222\n", " \n", " \n", " Num Muscles\n", @@ -194,8 +210,8 @@ " 5805\n", " 1650\n", " 6417\n", - " 858\n", - " 1110\n", + " 2493\n", + " 2496\n", " \n", " \n", " Num N with ->M\n", @@ -227,8 +243,8 @@ " Acetylcholine (2008)
Acetylcholine_GJ (222)
Acetylcholine_Tyramine (29)
Acetylcholine_Tyramine_GJ (13)
Dopamine (98)
Dopamine_GJ (13)
FMRFamide (170)
FMRFamide_GJ (90)
FRMFemide (45)
FRMFemide_GJ (33)
GABA (182)
GABA_GJ (76)
Generic_GJ (1356)
Glutamate (824)
Glutamate_GJ (324)
Octapamine (19)
Octapamine_GJ (4)
Serotonin (163)
Serotonin_Acetylcholine (91)
Serotonin_Acetylcholine_GJ (13)
Serotonin_GJ (20)
Serotonin_Glutamate (11)
Serotonin_Glutamate_GJ (1)
\n", " Generic_GJ (1650)
\n", " Chemical_Synapse (5386)
Generic_GJ (1031)
\n", - " Chemical_Synapse (775)
Generic_GJ (83)
\n", - " Chemical_Synapse (986)
Generic_GJ (124)
\n", + " Chemical_Synapse (2202)
Generic_GJ (291)
\n", + " Chemical_Synapse (2186)
Generic_GJ (310)
\n", " \n", " \n", " M neurotransmitters\n", @@ -248,7 +264,7 @@ "" ] }, - "execution_count": 24, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } From 11123dc51608b700a0d4740dc8951c37da593076 Mon Sep 17 00:00:00 2001 From: yasinthanvickneswaran Date: Thu, 15 Feb 2024 11:59:35 +0000 Subject: [PATCH 2/2] SpreadsheetDataReader --- c302/SpreadsheetDataReader.py | 2 +- c302/W_SpreadsheetDataReader.py | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/c302/SpreadsheetDataReader.py b/c302/SpreadsheetDataReader.py index 9d8a26f2..66dc0fda 100644 --- a/c302/SpreadsheetDataReader.py +++ b/c302/SpreadsheetDataReader.py @@ -22,7 +22,7 @@ READER_DESCRIPTION = """Data extracted from CElegansNeuronTables.xls for neuronal connectivity""" -def read_data(include_nonconnected_cells=False, neuron_connect=True): +def read_data(include_nonconnected_cells=False, neuron_connect=False): diff --git a/c302/W_SpreadsheetDataReader.py b/c302/W_SpreadsheetDataReader.py index 316c2c44..acf1541e 100644 --- a/c302/W_SpreadsheetDataReader.py +++ b/c302/W_SpreadsheetDataReader.py @@ -8,12 +8,6 @@ spreadsheet_location = os.path.dirname(os.path.abspath(__file__))+"/data/" - - - - - - class WitvlietDataReader1: def read_data(include_nonconnected_cells=False, neuron_connect=False):