Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for neuromorpho interface #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions navis/interfaces/neuromorpho.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,50 @@

import pandas as pd
import numpy as np
import pycurl
import urllib.parse


from typing import List, Dict, Union, Optional
from concurrent.futures import ThreadPoolExecutor, as_completed
from io import BytesIO

from ..core import TreeNeuron, NeuronList
from ..io import read_swc
from .. import utils, config


baseurl = 'http://neuromorpho.org'
baseurl = 'http://cng.gmu.edu:8080/'
baseurl_swc = 'https://neuromorpho.org/'


def get_neuromorpho_swc(
url: str,
encode: bool = False,
) -> str:

if encode:
url = urllib.parse.quote(url, safe="/:")
try:
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, url)
c.setopt(c.WRITEDATA, buffer)
c.setopt(c.SSL_VERIFYPEER, 0) # This disables SSL peer verification
c.setopt(c.SSL_VERIFYHOST, 0) # This disables SSL host verification
c.perform()
c.close()

return buffer.getvalue().decode("utf-8")
except pycurl.error as e:
print(f"Error fetching data: {e}")
return None


def find_neurons(page_limit: Optional[int] = None,
parallel: bool = True,
max_threads: int = 4,
**filters) -> pd.DataFrame:
parallel: bool = True,
max_threads: int = 4,
**filters) -> pd.DataFrame:
"""Find neurons matching by given criteria.

Parameters
Expand Down Expand Up @@ -225,9 +253,10 @@ def get_neuron(x: Union[str, int, Dict[str, str]],
archive: str = info['archive']
name: str = info['neuron_name']

url = utils.make_url(baseurl, 'dableFiles', archive.lower(), 'CNG version', name + '.CNG.swc')
url = utils.make_url(baseurl_swc, 'dableFiles', archive.lower(), 'CNG version', name + '.CNG.swc')
swc = get_neuromorpho_swc(url, encode=True)

n = read_swc(url, **kwargs)
n = read_swc(swc, **kwargs)

n.id = info.get('neuron_id', n.id)
n.name = info.get('neuron_name', getattr(n, 'name'))
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ molesq>=0.2.0
rdata>=0.5
igraph!=0.10.0,!=0.10.1
skeletor>=1.0.0
pycurl>=7.45.3

pathos>=0.2.7 #extra: pathos

Expand Down