scidash / neuronunit

A package for data-driven validation of neuron and ion channel models using SciUnit
http://neuronunit.scidash.org
38 stars 24 forks source link

Solution to use NE python API for bimodality tests fails, due to NeuroElectro query syntax #206

Open russelljjarvis opened 5 years ago

russelljjarvis commented 5 years ago
import matplotlib
matplotlib.use('Agg')
import seaborn as sns
import urllib.request, json

import matplotlib.pyplot as plt

purkinje ={"id": 18, "name": "Cerebellum Purkinje cell", "neuron_db_id": 271, "nlex_id": "sao471801888"}
fi_basket = {"id": 65, "name": "Dentate gyrus basket cell", "neuron_db_id": None, "nlex_id": "nlx_cell_100201"}
pvis_cortex = {"id": 111, "name": "Neocortex pyramidal cell layer 5-6", "neuron_db_id": 265, "nlex_id": "nifext_50"}
#does not have rheobase
olf_mitral = {"id": 129, "name": "Olfactory bulb (main) mitral cell", "neuron_db_id": 267, "nlex_id": "nlx_anat_100201"}
ca1_pyr = {"id": 85, "name": "Hippocampus CA1 pyramidal cell", "neuron_db_id": 258, "nlex_id": "sao830368389"}
pipe = [ fi_basket, ca1_pyr, purkinje,  pvis_cortex,olf_mitral]

def properties(pipe):
    neuron_values = {}
    for val in range(1,10):
        for p in pipe:
            url_to_get = str('https://neuroelectro.org/api/1/nedm/?nlex=')+str(p["nlex_id"])+str('&e=')+str(val)+str('&limit=100')
            with urllib.request.urlopen(url_to_get) as url:
                data = json.loads(url.read().decode())
            for objects in data['objects']:
                last_label = objects['ecm']['ref_text']

            values = [ objects['val'] for objects in data['objects'] ]
            neuron_values[str(p["nlex_id"])] = {}
            neuron_values[str(p["nlex_id"])][val] = values
            if len(values):
                print(values)
                plt.clf()
                try:
                    sns.distplot(sorted(values), color="skyblue", label=str(last_label)+str(p["nlex_id"])+str(val))
                    plt.legend(loc="upper left")
                except:
                    plt.hist(sorted(values))      #use this to draw histogram of your data
                plt.savefig(str(last_label)+str(p["nlex_id"])+str(val)+str('.png'))
    return neuron_values
neuron_values = properties(pipe)
rgerkin commented 5 years ago

@russelljjarvis I don't know if __name filtering (or any filtering) was every implemented for nedm searches (i.e. for individual values taken from the literature. Also recall that if no results are found for one of the search restrictions, in some cases it just ignores that search restriction, which is obviously dumb but it hasn't risen to the top of anyone's list to fix it in NeuroElectro. Your safest bet is to do something like:

https://www.neuroelectro.org/api/1/nedm/?limit=999&n=18&e=2

Which should successfully return all 30 input resistance reports for Purkinje cells. You can check the output to make sure that the json for each entry in the returned list has ecm['e']['id']==2 and ncm['n']['id']==18 to make sure there are no bogus entries slipping in there due to API bugs.

russelljjarvis commented 5 years ago

TODO:

Use 'R's diptest to test for bimodal. Update number of samples to reflect an entire number of experiments (possibly including multiple trials in the same organism).

Link to OSF: https://osf.io/97xuj/

Sometimes unimodalism seems justified, other times not.

Here are some interesting distributions that might violate unimodalism, relevant to the optimization work being done. I will upload to the OSF, with metadata.

image image image image image image image image image image image image image

russelljjarvis commented 5 years ago

The dip-test is better supported in R. I am moving this code to the test directory, as I think stat-data-model tests, need to be included as tests if data driven optimization needs to be done. I also think that these distributions should be stored in a variable, that moves through the optimization pipeline, and gives context to solution quality.