Skip to content

Commit

Permalink
Merge branch 'master' into wildcards
Browse files Browse the repository at this point in the history
  • Loading branch information
anilbey authored Dec 12, 2023
2 parents 4e6514b + 1d898c8 commit f7425b8
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 568 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="docs/source/logo/eFELBanner.png"/>
<img src="https://raw.githubusercontent.com/BlueBrain/eFEL/master/docs/source/logo/eFELBanner.png" alt="eFEL banner" />

<table>
<tr>
Expand Down Expand Up @@ -73,7 +73,7 @@ the values to the user.

The core of the library is written in C++, and a Python wrapper is included.
At the moment we provide a way to automatically compile and install the library
as a Python module. Instructions on how to compile the eFEL as a standalone C++
as a Python module. Instructions on how to compile the eFEL as a standalone C++
library can be found [here](http://efel.readthedocs.io/en/latest/installation.html#installing-the-c-standalone-library).


Expand All @@ -83,12 +83,12 @@ Citation
When you use this eFEL software for your research, we ask you to cite the following publications (this includes poster presentations):

```
@article{efel,
title={eFEL},
@article{efel,
title={eFEL},
DOI={10.5281/zenodo.593869},
url={https://doi.org/10.5281/zenodo.593869}
abstractNote={The Electrophys Feature Extraction Library (eFEL) allows neuroscientists to automatically extract features from time series data recorded from neurons (both in vitro and in silico). Examples are the action potential width and amplitude in voltage traces recorded during whole-cell patch clamp experiments. The user of the library provides a set of traces and selects the features to be calculated. The library will then extract the requested features and return the values to the user.},
publisher={Zenodo},
url={https://doi.org/10.5281/zenodo.593869}
abstractNote={The Electrophys Feature Extraction Library (eFEL) allows neuroscientists to automatically extract features from time series data recorded from neurons (both in vitro and in silico). Examples are the action potential width and amplitude in voltage traces recorded during whole-cell patch clamp experiments. The user of the library provides a set of traces and selects the features to be calculated. The library will then extract the requested features and return the values to the user.},
publisher={Zenodo},
author={Ranjan, Rajnish and
Van Geit, Werner and
Moor, Ruben and
Expand All @@ -97,8 +97,8 @@ When you use this eFEL software for your research, we ask you to cite the follow
Damart, Tanguy and
Jaquier, Aurélien and
Tuncel, Anil},
year={2023},
month={Jul}
year={2023},
month={Jul}
}
```

Expand Down Expand Up @@ -235,16 +235,16 @@ Results are in mV.

Full documentation
==================
The full documentation can be found [here](http://efel.readthedocs.io)
The full documentation can be found [here](http://efel.readthedocs.io)

Funding
=======
This work has been partially funded by the European Union Seventh Framework Program (FP7/2007­2013) under grant agreement no. 604102 (HBP),
the European Union’s Horizon 2020 Framework Programme for Research and Innovation under the Specific Grant Agreement No. 720270, 785907
(Human Brain Project SGA1/SGA2) and by the EBRAINS research infrastructure, funded from the European Union’s Horizon 2020 Framework
Programme for Research and Innovation under the Specific Grant Agreement No. 945539 (Human Brain Project SGA3).
This project/research was supported by funding to the Blue Brain Project, a research center of the École polytechnique fédérale de
This work has been partially funded by the European Union Seventh Framework Program (FP7/2007­2013) under grant agreement no. 604102 (HBP),
the European Union’s Horizon 2020 Framework Programme for Research and Innovation under the Specific Grant Agreement No. 720270, 785907
(Human Brain Project SGA1/SGA2) and by the EBRAINS research infrastructure, funded from the European Union’s Horizon 2020 Framework
Programme for Research and Innovation under the Specific Grant Agreement No. 945539 (Human Brain Project SGA3).
This project/research was supported by funding to the Blue Brain Project, a research center of the École polytechnique fédérale de
Lausanne (EPFL), from the Swiss government’s ETH Board of the Swiss Federal Institutes of Technology.

Copyright (c) 2009-2022 Blue Brain Project/EPFL
Copyright (c) 2009-2024 Blue Brain Project/EPFL

121 changes: 24 additions & 97 deletions efel/io.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
"""IO handler for eFEL"""

"""
Expand All @@ -18,89 +19,22 @@
along with this library; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
from pathlib import Path
import neo
import numpy as np

import os

# pylint:disable=E0611, F0401
import urllib.parse as up
import urllib.request as ur
def load_ascii_input(
file_path: Path | str, delimiter: str = " "
) -> tuple[np.ndarray, np.ndarray]:
"""Loads electrophysiology data from an ASCII file.
# pylint:enable=E0611,F0401

import mimetypes


def windows_compatible(func):
"""Decorator allowing to use urlparse with windows."""

def inner(fragment_url):
"""Change windows path part to url."""
# if system is windows
if os.name == "nt":
fragment_url.replace("\\", "/")

parsed_url = func(fragment_url)

return parsed_url

return inner


def load_fragment(fragment_url, mime_type=None):
"""Load fragment
Load a fragment (e.g. time series data) from a given URL
Returns: A tuple containing two numpy arrays, one for time and one for voltage.
"""
parsed_url = windows_compatible(up.urlparse)(fragment_url)

scheme = parsed_url.scheme
server_loc = parsed_url.netloc
path = parsed_url.path
fragment_string = parsed_url.fragment

# reform path for windows files
if scheme == "file" and os.name == "nt":
path = ur.url2pathname(r"\\" + server_loc + path)

if mime_type is None:
mimetypes.init()
mime_type, _ = mimetypes.guess_type(path)
if mime_type is None:
raise TypeError(
'load_fragment: impossible to guess MIME type from url, '
'please specify the type manually as argument: %s' % path)

if scheme == 'file' and os.name == 'nt':
file_handle = open(path, 'r')
elif scheme == 'file':
file_handle = open(os.path.join(server_loc, path), 'r')

if 'text/' in mime_type:
import numpy

if fragment_string == '':
cols = None
else:
import re

match = re.match("col=([0-9]+)", fragment_string)
if match is None or len(match.groups()) != 1:
raise TypeError(
"load_fragment: don't understand url fragment %s" %
fragment_string)
else:
cols = int(match.groups()[0]) - 1

# Unfortunately we need this if statement
# Setting usecols to None throws an error in the loadtxt call
if cols is not None:
fragment_content = numpy.loadtxt(file_handle, usecols=[cols])
else:
fragment_content = numpy.loadtxt(file_handle)

return fragment_content
else:
raise TypeError('load_fragment: unknown mime type %s' % mime_type)
file_path = Path(file_path)
data = np.loadtxt(file_path, delimiter=delimiter)
time, voltage = data[:, 0], data[:, 1]
return time, voltage


def extract_stim_times_from_neo_data(blocks, stim_start, stim_end):
Expand Down Expand Up @@ -242,37 +176,30 @@ def load_neo_file(file_name, stim_start=None, stim_end=None, **kwargs):
returned object : [Segments_1, Segments_2, ..., Segments_n]
Segments_1 = [Traces_1, Traces_2, ..., Traces_n]
"""

import neo

reader = neo.io.get_io(file_name)
blocks = reader.read(**kwargs)

stim_start, stim_end = extract_stim_times_from_neo_data(
blocks, stim_start, stim_end)
if stim_start is None or stim_end is None:
raise ValueError(
'No stim_start or stim_end has been found inside epochs or events.'
' You can directly specify their value as argument "stim_start"'
' and "stim_end"')
'No stim_start or stim_end found in epochs or events. '
'Please specify "stim_start" and "stim_end" arguments.')

# this part of the code transforms the data format.
# Convert data for eFEL
efel_blocks = []
for bl in blocks:
efel_segments = []
for seg in bl.segments:
traces = []
count_traces = 0
analogsignals = seg.analogsignals

for sig in analogsignals:
traces.append({})
traces[count_traces]['T'] = sig.times.rescale('ms').magnitude
traces[count_traces]['V'] = sig.rescale('mV').magnitude
traces[count_traces]['stim_start'] = [stim_start]
traces[count_traces]['stim_end'] = [stim_end]
count_traces += 1

for sig in seg.analogsignals:
trace = {
'T': sig.times.rescale('ms').magnitude,
'V': sig.rescale('mV').magnitude,
'stim_start': [stim_start],
'stim_end': [stim_end]
}
traces.append(trace)
efel_segments.append(traces)
efel_blocks.append(efel_segments)

Expand Down
16 changes: 6 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,21 @@
extra_compile_args=coverage_flags + ['-std=c++17'],
extra_link_args=coverage_flags)

with open("README.md", encoding="utf-8") as f:
README = f.read()

setup(
name="efel",
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
install_requires=['numpy>=1.6'],
extras_require={'neo': ['neo[neomatlabio]>=0.5.1']},
install_requires=['numpy>=1.6', 'neo>=0.5.2'],
packages=['efel', 'efel.pyfeatures', 'efel.units'],
author="BlueBrain Project, EPFL",
maintainer="Werner Van Geit",
maintainer_email="[email protected]",
description="Electrophys Feature Extract Library (eFEL)",
long_description="The Electrophys Feature Extract Library (eFEL) allows "
"neuroscientists to automatically extract features from time series data "
"recorded from neurons (both in vitro and in silico). "
"Examples are the action potential width and amplitude in "
"voltage traces recorded during whole-cell patch clamp experiments. "
"The user of the library provides a set of traces and selects the "
"features to be calculated. The library will then extract the requested "
"features and return the values to the user.",
long_description=README,
long_description_content_type="text/markdown",
license="LGPLv3",
keywords=[
'feature',
Expand Down
Loading

0 comments on commit f7425b8

Please sign in to comment.