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

Kachery fixes #918

Merged
merged 5 commits into from
Apr 11, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Fix errors in config import #882
- Save current spyglass version in analysis nwb files to aid diagnosis #897
- Add pynapple support #898
- Prioritize datajoint filepath entry for defining abs_path of analysis nwbfile #918
- Fix potential duplicate entries in Merge part tables #922

### Pipelines
Expand Down
54 changes: 14 additions & 40 deletions src/spyglass/common/common_nwbfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ def add(self, nwb_file_name, analysis_file_name):
)
self.insert1(key)

@staticmethod
def get_abs_path(analysis_nwb_file_name):
@classmethod
def get_abs_path(cls, analysis_nwb_file_name):
"""Return the absolute path for a stored analysis NWB file given just the file name.

The spyglass config from settings.py must be set.
Expand All @@ -325,6 +325,18 @@ def get_abs_path(analysis_nwb_file_name):
analysis_nwb_file_abspath : str
The absolute path for the given file name.
"""
# If an entry exists in the database get the stored datajoint filepath
file_key = {"analysis_file_name": analysis_nwb_file_name}
if cls & file_key:
try:
# runs if file exists locally
return (cls & file_key).fetch1("analysis_file_abs_path")
except FileNotFoundError as e:
# file exists in database but not locally
# parse the intended path from the error message
return str(e).split(": ")[1].replace("'", "")

# File not in database, define what it should be
# see if the file exists and is stored in the base analysis dir
test_path = f"{analysis_dir}/{analysis_nwb_file_name}"

Expand Down Expand Up @@ -656,41 +668,3 @@ def nightly_cleanup():
AnalysisNwbfile.cleanup(True)

# also check to see whether there are directories in the spikesorting folder with this


@schema
class NwbfileKachery(SpyglassMixin, dj.Computed):
definition = """
-> Nwbfile
---
nwb_file_uri: varchar(200) # the uri the NWB file for kachery
"""

def make(self, key):
import kachery_client as kc

logger.info(f'Linking {key["nwb_file_name"]} and storing in kachery...')
key["nwb_file_uri"] = kc.link_file(
Nwbfile().get_abs_path(key["nwb_file_name"])
)
self.insert1(key)


@schema
class AnalysisNwbfileKachery(SpyglassMixin, dj.Computed):
definition = """
-> AnalysisNwbfile
---
analysis_file_uri: varchar(200) # the uri of the file
"""

def make(self, key):
import kachery_client as kc

logger.info(
f'Linking {key["analysis_file_name"]} and storing in kachery...'
)
key["analysis_file_uri"] = kc.link_file(
AnalysisNwbfile().get_abs_path(key["analysis_file_name"])
)
self.insert1(key)
Loading