我是一名神经学家,因此不是很熟练,但我设法想出了一个代码,它使用API access从特定的网站(neuromorpho.org)下载特定的神经元。我希望这篇文章是公开的,这样其他不熟悉Python的人就可以很容易地得到他们需要的东西(计划将它发布到GitHub上,并制作其他类似的东西)。
所以我想基本上创建一个可执行文件,在这个文件中,人们可以选择他们想要的东西,并在最后得到一个带有神经元的.csv文件。这可以在JupyterNotebook内部完美地工作。但是,当我使用Auto Py to EXE来创建和执行它时,它不起作用。它工作很长一段时间,创建数千个文件(超过1 1GB的数据),当你启动可执行文件时什么也不会发生。
我假设它与我用来为初始查询创建选择的ipywidget有关。
以下是代码的第一部分,我尝试根据小部件选择来查询神经元:
widg1 = widget.Dropdown(options=['abdominal ganglion', 'accessory lobe', 'accessory olfactory bulb', 'adult subesophageal zone', 'amygdala'
'antenna', 'antennal lobe', 'anterior olfactory nucleus', 'basal forbrain', 'basal ganglia',
'brainstem', 'Central complex', 'Central nervous system', 'cerebellum', 'cerebral ganglion',
'Cochlea', 'corpus callosum', 'cortex', 'electrosensory lobe', 'endocrine system', 'enthorinal cortex',
'eye circuit', 'forebrain', 'fornix', 'ganglion', 'hippocampus', 'hypothalamus', 'lateral complex',
'lateral horn', 'lateral line organ', 'left', 'Left Adult Central Complex', 'Left Mushroom Body', 'main olfactory bulb'
'meninges', 'mesencephalon', 'myelencephalon', 'neocortex', 'nuchal organs', 'olfactory cortex', 'olfactory pit', 'optic lobe',
'pallium', 'parasubiculum', ' peptidergic circuit', 'peripheral nervous system', 'pharyngeal nervous system', 'pons', 'Pro-subiculum',
'protocerebrum', 'retina', 'retinorecipient mesencephalon and diencephalon', 'Right Adult Central Complex',
'Right Mushroom Body', 'somatic nervous system', 'spinal cord', 'stomatogastric ganglion', 'subesophageal ganglion',
'subesophageal zone-(SEZ)', 'subiculum', 'subpallium', 'Subventricular zone', 'thalamus', 'ventral nerve cord',
'ventral striatum', 'ventral thalamus', 'ventrolateral neuropils', 'Not reported'],
value= 'cerebellum', description='Brain Region:')
display(widg1)
widg2 = widget.Dropdown(options=['African wild dog', 'agouti', 'Apis mellifera', 'Aplysia', 'Axolotl', 'Baboon',
'Blind mole-rat', 'blowfly', 'Blue wildebeest', 'Bonobo', 'bottlenose dolphin', 'C. elegans',
'Calango lizard', 'capuchin monkey', 'Caracal', 'cat', 'cheetah', 'chicken', 'chimpanzee', 'Clam worm', 'clouded leopard', 'Crab', 'cricket',
'Crisia eburnea', 'Domestic dog', 'domestic pig', 'dragonfly', 'drosophila melanogaster', 'drosophila sechellia',
'elephant', 'ferret', 'giraffe', 'goldfish', 'grasshopper', 'Greater kudu', 'guinea pig', 'Hamster', 'human', 'humpback whale',
'Lemur', 'leopard', 'Lion', 'locust', 'manatee', 'minke whale', 'Mongoose', 'monkey', 'Mormyrid fish', 'moth',
'mouse', 'pouched lamprey', 'Praying mantis (Hierodula membranacea)', 'Praying mantis (Hierodula membranacea)',
'proechimys', 'rabbit', 'Rana esculenta', 'Ranitomeya imitator', 'rat', 'Rhinella arenarum', 'Ruddy turnstone', 'salamander',
'Scinax granulatus', 'Sea lamprey', 'Semipalmated plover', 'Semipalmated sandpiper', 'sheep', 'Silkmoth', 'spiny lobster', 'Stellers Sculpin',
'Tiger', 'Toadfish', 'Treeshrew', 'turtle', 'Wallaby', 'Xenopus laevis', 'Xenopus tropicalis', 'Zebra', 'zebra finch', 'zebrafish', 'Not reported'],
value= 'mouse', description='Animal:')
display(widg2)
widg3 = widget.Dropdown(options=['Glia', 'interneuron', 'principal cell', 'sensory', 'Not reported'],
value= 'principal cell', description='Cell Type:')
display(widg3)
str1 = widg1.value
str2 = widg2.value
str3 = widg3.value
query = (
"http://neuromorpho.org/api/neuron/select?q=brain_region:%s&fq=species:%s&fq=cell_type:%s" % (str1, str2, str3))
print(query)
response = requests.get(query)
json_data = response.json()
rat_data = json_data
rat_data
url = 'http://neuromorpho.org/api/neuron/select'
params = {
'page' : 0,
'q' : 'brain_region:' + widg1.value,
'fq' : [
'cell_type:' + widg3.value,
'species:' + widg2.value,
]
}
first_page_response = requests.get(url, params)
if first_page_response.status_code == 404 or first_page_response.status_code == 500:
exit (1)
print (first_page_response.json())
totalPages = first_page_response.json()['page']['totalPages']
df_dict = {
'NeuronID' : list(),
'Neuron Name' : list(),
'Archive' : list(),
'Note' : list(),
'Age Scale' : list(),
'Gender' : list(),
'Age Classification' : list(),
'Brain Region' : list(),
'Cell Type' : list(),
'Species' : list(),
'Strain' : list(),
'Scientific Name' : list(),
'Stain' : list(),
'Experiment Condition' : list(),
'Protocol' : list(),
'Slicing Direction' : list(),
'Reconstruction Software' : list(),
'Objective Type' : list(),
'Original Format' : list(),
'Domain' : list(),
'Attributes' : list(),
'Magnification' : list(),
'Upload Date' : list(),
'Deposition Date' : list(),
'Shrinkage Reported' : list(),
'Shrinkage Corrected' : list(),
'Reported Value' : list(),
'Reported XY' : list(),
'Reported Z' : list(),
'Corrected Value' : list(),
'Corrected XY' : list(),
'Corrected Z' : list(),
'Slicing Thickness' : list(),
'Min Age' : list(),
'Max Age' : list(),
'Min Weight' : list(),
'Max Weight' : list(),
'Png URL' : list(),
'Reference PMID' : list(),
'Reference DOI' : list(),
'Physical Integrity' : list() }
for pageNum in range(totalPages):
params['page'] = pageNum
response = requests.get(url, params)
print('Querying page {} -> status code: {}'.format(
pageNum, response.status_code))
if (response.status_code == 200): #only parse successful requests
data = response.json()
for row in data['_embedded']['neuronResources']:
df_dict['NeuronID'].append(str(row['neuron_id']))
df_dict['Neuron Name'].append(str(row['neuron_name']))
df_dict['Archive'].append(str(row['archive']))
df_dict['Note'].append(str(row['note']))
df_dict['Age Scale'].append(str(row['age_scale']))
df_dict['Gender'].append(str(row['gender']))
df_dict['Age Classification'].append(str(row['age_classification']))
df_dict['Brain Region'].append(str(row['brain_region']))
df_dict['Cell Type'].append(str(row['cell_type']))
df_dict['Species'].append(str(row['species']))
df_dict['Strain'].append(str(row['strain']))
df_dict['Scientific Name'].append(str(row['scientific_name']))
df_dict['Stain'].append(str(row['stain']))
df_dict['Experiment Condition'].append(str(row['experiment_condition']))
df_dict['Protocol'].append(str(row['protocol']))
df_dict['Slicing Direction'].append(str(row['slicing_direction']))
df_dict['Reconstruction Software'].append(str(row['reconstruction_software']))
df_dict['Objective Type'].append(str(row['objective_type']))
df_dict['Original Format'].append(str(row['original_format']))
df_dict['Domain'].append(str(row['domain']))
df_dict['Attributes'].append(str(row['attributes']))
df_dict['Magnification'].append(str(row['magnification']))
df_dict['Upload Date'].append(str(row['upload_date']))
df_dict['Deposition Date'].append(str(row['deposition_date']))
df_dict['Shrinkage Reported'].append(str(row['shrinkage_reported']))
df_dict['Shrinkage Corrected'].append(str(row['shrinkage_corrected']))
df_dict['Reported Value'].append(str(row['reported_value']))
df_dict['Reported XY'].append(str(row['reported_xy']))
df_dict['Reported Z'].append(str(row['reported_z']))
df_dict['Corrected Value'].append(str(row['corrected_value']))
df_dict['Corrected XY'].append(str(row['corrected_xy']))
df_dict['Corrected Z'].append(str(row['corrected_z']))
df_dict['Slicing Thickness'].append(str(row['slicing_thickness']))
df_dict['Min Age'].append(str(row['min_age']))
df_dict['Max Age'].append(str(row['max_age']))
df_dict['Min Weight'].append(str(row['min_weight']))
df_dict['Max Weight'].append(str(row['max_weight']))
df_dict['Png URL'].append(str(row['png_url']))
df_dict['Reference PMID'].append(str(row['reference_pmid']))
df_dict['Reference DOI'].append(str(row['reference_doi']))
df_dict['Physical Integrity'].append(str(row['physical_Integrity']))
neurons_df = pd.DataFrame(df_dict)我知道这可能会让不熟悉这一点的人感到困惑,但我在笔记本中放置了一些标记,以详细解释问题所在。
发布于 2021-12-01 17:40:44
我建议你在PyInstaller和Nuitka上看看。它们可以生成独立的可执行文件。
使用nuitka的示例
(linux) python -m nuitka --onefile --output-dir=./nuitka --standalone --follow-imports --plugin-enable=qt-plugins ./../updater.py
(windows) python -m nuitka --onefile --windows-uac-admin --windows-disable-console --windows-icon-from-ico=.\updater\resources\ico\au.ico --output-dir=.\nuitka --standalone --follow-imports --plugin-enable=qt-plugins --windows-company-name=Name --windows-product-name=Name --windows-product-version=1.0.0 --windows-file-description=Name .\..\updater.py使用pyinstaller的示例
pyinstaller --onefile --windowed --icon=./updater/resources/ico/au.ico updater.pyhttps://stackoverflow.com/questions/70188662
复制相似问题