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

select nwb traces according to v_file field #174

Merged
merged 6 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion bluepyefe/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def reader(self, config_data, recording_reader=None):

if "v_file" in config_data:
filename = config_data["v_file"]
elif "filepath" in config_data:
# if both present: use filepath. e.g. for some nwb that 'contain' igor files
if "filepath" in config_data:
filename = config_data["filepath"]

if recording_reader:
Expand Down
30 changes: 27 additions & 3 deletions bluepyefe/nwbreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@


class NWBReader:
def __init__(self, content, target_protocols, repetition=None):
def __init__(self, content, target_protocols, repetition=None, v_file=None):
""" Init

Args:
content (h5.File): NWB file
target_protocols (list of str): list of the protocols to be read and returned
repetition (list of int): id of the repetition(s) to be read and returned
v_file (str): name of original file that can be retrieved in sweep's description
"""

self.content = content
self.target_protocols = target_protocols
self.repetition = repetition
self.v_file = v_file

def read(self):
""" Read the content of the NWB file
Expand Down Expand Up @@ -162,8 +164,21 @@ def read(self):
for ecode in self.target_protocols:
for cell_id in self.content["data_organization"].keys():
if ecode not in self.content["data_organization"][cell_id]:
logger.debug(f"No eCode {ecode} in nwb.")
continue
new_ecode = next(
iter(
ec
for ec in self.content["data_organization"][cell_id]
if ec.lower() == ecode.lower()
darshanmandge marked this conversation as resolved.
Show resolved Hide resolved
)
)
if new_ecode:
logger.debug(
f"Could not find {ecode} in nwb file, will use {new_ecode} instead"
)
ecode = new_ecode
else:
logger.debug(f"No eCode {ecode} in nwb.")
continue

ecode_content = self.content["data_organization"][cell_id][ecode]

Expand All @@ -185,11 +200,20 @@ def read(self):
logger.debug(f"Ignoring {key_current} not"
" present in the stimulus presentation")
continue

if trace_name not in self.content["acquisition"]:
logger.debug(f"Ignoring {trace_name} not"
" present in the acquisition")
continue

# if we have v_file, check that trace comes from this original file
if self.v_file is not None:
attrs = self.content["acquisition"][trace_name].attrs
v_file_end = self.v_file.split("/")[-1]
if v_file_end != attrs.get("description", "").split("/")[-1]:
logger.debug(f"Ignoring {trace_name} not matching v_file")
continue

data.append(self._format_nwb_trace(
voltage=self.content["acquisition"][trace_name]["data"],
current=self.content["stimulus"]["presentation"][key_current][
Expand Down
7 changes: 6 additions & 1 deletion bluepyefe/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,12 @@ def nwb_reader(in_data):

with h5py.File(in_data["filepath"], "r") as content:
if "data_organization" in content:
reader = BBPNWBReader(content, target_protocols, in_data.get("repetition", None))
reader = BBPNWBReader(
content,
target_protocols,
in_data.get("repetition", None),
in_data.get("v_file", None)
)
elif "timeseries" in content["acquisition"].keys():
reader = AIBSNWBReader(content, target_protocols)
else:
Expand Down
Loading