Skip to content

Commit

Permalink
Merge pull request #232 from vathes/master
Browse files Browse the repository at this point in the history
handling new directory structure for histology ingestion
  • Loading branch information
susuchen66 authored Oct 6, 2021
2 parents 8672ee1 + 6b12f98 commit 249aea5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
37 changes: 19 additions & 18 deletions pipeline/ingest/histology.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pipeline import get_schema_name, dict_to_hash

from pipeline.ingest import behavior as behavior_ingest
from pipeline.ingest import ephys as ephys_ingest

schema = dj.schema(get_schema_name('ingest_histology'))

Expand Down Expand Up @@ -78,7 +79,9 @@ def make(self, key):
log.info('\n======================================================')
log.info('HistologyIngest().make(): key: {}'.format(key))

self.session = (experiment.Session * lab.WaterRestriction.proj('water_restriction_number') & key).fetch1()
self.session = (experiment.Session
* lab.WaterRestriction.proj('water_restriction_number')
& key).fetch1()

rigpaths = get_histology_paths()

Expand All @@ -97,7 +100,10 @@ def make(self, key):
log.warning('Missing BehaviorFile for session: {}. Skipping...'.format(self.session))
return

self.q_behavior_file = ((behavior_ingest.BehaviorIngest.BehaviorFile + behavior_ingest.BehaviorBpodIngest.BehaviorFile) & key)
self.q_behavior_file = ((behavior_ingest.BehaviorIngest.BehaviorFile
+ behavior_ingest.BehaviorBpodIngest.BehaviorFile) & key)
self.q_ephys_file = (ephys_ingest.EphysIngest.EphysFile.proj(
insertion_number='probe_insertion_number') & key)

for rigpath in rigpaths:
if self.rig == 'RRig-MTL':
Expand All @@ -113,8 +119,15 @@ def make(self, key):
if directory.exists():
self.directory = directory
break

directory = (pathlib.Path(rigpath) / self.q_ephys_file.fetch1('ephys_file')).parent
try:
self.directory = next(directory.rglob('channel_locations*.json')).parent
break
except StopIteration:
pass
else:
log.warning('Histology folder for animal: {} not found. Skipping...'.format(self.water))
log.warning('Histology folder not found! Probe Insertion: {}({}). Skipping...'.format(self.water, key))
return

# ingest histology
Expand Down Expand Up @@ -447,13 +460,8 @@ def _search_histology_files(self, file_type):
"""

# Detecting format #2 (.json)
if self.rig == 'RRig-MTL':
filename_prefix = ''
else:
filename_prefix = '{}_{}_{}_'.format(
self.water, self.session_date_str, self.probe)

format_number = 2 if len(list(self.directory.glob('{}channel_locations*.json'.format(filename_prefix)))) else 1
channel_locations_files = list(self.directory.glob('*channel_locations*.json'))
format_number = 2 if len(channel_locations_files) else 1

if format_number == 1:
file_format_map = {'landmark_file': '_siteInfo.mat',
Expand Down Expand Up @@ -523,16 +531,9 @@ def _search_histology_files(self, file_type):
elif format_number == 2:
log.debug('format 2 detected..')

channel_locations_files = list(self.directory.glob(
'{}channel_locations*.json'.format(filename_prefix)))
xyz_picks_files = list(self.directory.glob('xyz_picks*.json'))

if len(channel_locations_files) < 1:
raise FileNotFoundError(
'Probe {} histology file {} not found!'.format(
self.probe,
'{}channel_locations*.json'.format(filename_prefix)))
elif len(channel_locations_files) == 1:
if len(channel_locations_files) == 1:
corresponding_shanks = [1]
if len(self.shanks) != 1:
raise HistologyFileError(
Expand Down
6 changes: 6 additions & 0 deletions pipeline/plot/behavior_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ def plot_tracking(session_key, unit_key,
l_trial_trk = trk & 'trial_instruction="left"' & 'early_lick="no early"' & 'outcome="hit"'
r_trial_trk = trk & 'trial_instruction="right"' & 'early_lick="no early"' & 'outcome="hit"'

if not l_trial_trk or not r_trial_trk:
raise Exception('No trial matching the required conditions for this session: {}'.format(session_key))

def get_trial_track(trial_tracks):
if trial_offset < 1 and isinstance(trial_offset, float):
offset = int(len(trial_tracks) * trial_offset)
Expand Down Expand Up @@ -200,6 +203,9 @@ def plot_unit_jaw_phase_dist(session_key, unit_key, bin_counts=20, axs=None):
l_trial_trk = trk & 'trial_instruction="left"' & 'early_lick="no early"' & 'outcome="hit"'
r_trial_trk = trk & 'trial_instruction="right"' & 'early_lick="no early"' & 'outcome="hit"'

if not l_trial_trk or not r_trial_trk:
raise Exception('No trial matching the required conditions for this session: {}'.format(session_key))

def get_trial_track(trial_tracks):
jaws, spike_times, go_times = (ephys.Unit.TrialSpikes * trial_tracks * experiment.TrialEvent
& unit_key & 'trial_event_type="go"').fetch(
Expand Down

0 comments on commit 249aea5

Please sign in to comment.