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

Annotating licks into bouts #16

Merged
merged 35 commits into from
Sep 6, 2024
Merged

Annotating licks into bouts #16

merged 35 commits into from
Sep 6, 2024

Conversation

alexpiet
Copy link
Collaborator

@alexpiet alexpiet commented Sep 3, 2024

Add lick annotations to session scroller

from aind_dynamic_foraging_data_utils import nwb_utils as nu
from aind_dynamic_foraging_basic_analysis.plot import plot_foraging_session as pfs

nwb = nu.load_nwb_from_filename(<filepath>)
nwb.fip_df = nu.create_fib_df(nwb, tidy=True)
pfs.plot_session_scroller(nwb, plot_bouts=True)

Screenshot 2024-09-03 at 12 50 11 PM

Compute FIP PSTH aligned to rewarded and unrewarded goCues

from aind_dynamic_foraging_data_utils import nwb_utils as nu
from aind_dynamic_foraging_basic_analysis.plot import plot_fip as pf

nwb = nu.load_nwb_from_filename(<filepath>)
nwb.df_trials = nu.create_df_trials(nwb)
rewarded_go_cues = nwb.df_trials.query('reward == 1')['goCue_start_time_absolute'].values
unrewarded_go_cues = nwb.df_trials.query('reward == 0')['goCue_start_time_absolute'].values
pf.plot_fip_psth_compare_alignments(nwb, {'rewarded goCue':rewarded_go_cues,'unrewarded goCue':unrewarded_go_cues}, 'G_1_preprocessed', censor=True)

Screenshot 2024-09-03 at 12 37 30 PM

Compute FIP PSTH aligned to rewarded and unrewarded lick bout starts

from aind_dynamic_foraging_data_utils import nwb_utils as nu
from aind_dynamic_foraging_basic_analysis.licks import annotation as a
from aind_dynamic_foraging_basic_analysis.plot import plot_fip as pf

nwb = nu.load_nwb_from_filename(<filepath>)
nwb.df_licks = a.annotate_rewards(nwb)
rewarded_bout_start = nwb.df_licks.query('bout_start & bout_rewarded').timestamps.values
unrewarded_bout_start = nwb.df_licks.query('bout_start & (not bout_rewarded)').timestamps.values
pf.plot_fip_psth_compare_alignments(nwb, {'rewarded bout start':rewarded_bout_start,'unrewarded bout start':unrewarded_bout_start}, 'G_1_preprocessed', censor=True)

Screenshot 2024-09-03 at 12 37 38 PM

@alexpiet alexpiet marked this pull request as draft September 5, 2024 02:13
@alexpiet alexpiet marked this pull request as ready for review September 5, 2024 17:40
@alexpiet
Copy link
Collaborator Author

alexpiet commented Sep 5, 2024

@rachelstephlee @hanhou This is ready for review

@hanhou
Copy link
Collaborator

hanhou commented Sep 6, 2024

Compute FIP PSTH aligned to rewarded and unrewarded lick bout starts

Haven't checked the code, but a quick question: are bouts independent of trials? In other words, if there are more than one bouts in a trial, all bouts from the second on are considered as "unrewarded bouts" (red circles below)?

image

We may also need to align PSTH to the first bout after the go cue (essentially the "choice lick").

@alexpiet
Copy link
Collaborator Author

alexpiet commented Sep 6, 2024

Compute FIP PSTH aligned to rewarded and unrewarded lick bout starts

Haven't checked the code, but a quick question: are bouts independent of trials? In other words, if there are more than one bouts in a trial, all bouts from the second on are considered as "unrewarded bouts" (red circles below)?

image

We may also need to align PSTH to the first bout after the go cue (essentially the "choice lick").

The concept of a bout here is not connected to a trial. In the example snippet you highlighted the light green bout is rewarded, and all the other bouts are unrewarded.

We could add another annotation of bouts as "first after a go cue" (or whatever we want to call it).

@alexpiet
Copy link
Collaborator Author

alexpiet commented Sep 6, 2024

@hanhou I went ahead and added a function annotate_cue_response that annotates licks and bouts whether they were the first lick/bout after a go cue

@alexpiet
Copy link
Collaborator Author

alexpiet commented Sep 6, 2024

@hanhou This does what you suggested

from aind_dynamic_foraging_data_utils import nwb_utils as nu
from aind_dynamic_foraging_basic_analysis.licks import annotation as a
from aind_dynamic_foraging_basic_analysis.plot import plot_fip as pf

nwb = nu.load_nwb_from_filename(<filepath>)
nwb.df_events = nu.create_events_df(nwb)
nwb.df_licks = a.annotate_rewards(nwb)
nwb.df_licks = a.annotate_cue_response(nwb)
rewarded_response_bout_start = nwb.df_licks.query('bout_start & bout_rewarded & bout_cue_response').timestamps.values
unrewarded_response_bout_start = nwb.df_licks.query('bout_start & (not bout_rewarded) & bout_cue_response').timestamps.values
pf.plot_fip_psth_compare_alignments(nwb, {'rewarded response bout start':rewarded_response_bout_start,'unrewarded response bout start':unrewarded_response_bout_start}, 'G_1_preprocessed', censor=True)
Screenshot 2024-09-05 at 6 22 23 PM

@alexpiet alexpiet merged commit 9d36f96 into main Sep 6, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants