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

Merge Develop Into Master #14

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8284a72
removed dropped module for docs
ChristopherMarais Aug 15, 2023
6e233de
Added 3 functions to extract bouts from boris excels
mcum96 Aug 18, 2023
db8b422
borid functions added to new module
mcum96 Aug 18, 2023
cbded68
Merge branch 'feature/4_feature' into develop
mcum96 Aug 18, 2023
66bf52c
added basic deepnote function
ChristopherMarais Aug 25, 2023
8493923
formatting code
ChristopherMarais Aug 26, 2023
9190fa4
add function to remove zeros
ChristopherMarais Aug 26, 2023
9120359
added functions for medpc data txt parsing
ChristopherMarais Aug 26, 2023
8af7d81
Merge branch 'feature/7_feature' into develop
ChristopherMarais Aug 26, 2023
301f1b0
Elo Score Functions
cpeddireddyy Oct 1, 2023
53b9815
Elo Score Functions
cpeddireddyy Oct 1, 2023
b8958a9
Fix issue import issue in __init__.py
cpeddireddyy Oct 11, 2023
51f645b
Changed File Struct for Rank Dir
cpeddireddyy Nov 13, 2023
7fb1d4e
Merge branch 'develop' into feature/2_feature
cpeddireddyy Nov 13, 2023
6a07165
Merge pull request #11 from padillacoreanolab/feature/2_feature
cpeddireddyy Nov 13, 2023
f8b4d32
Changed rank module structure
cpeddireddyy Dec 20, 2023
5bfea76
Merge pull request #12 from padillacoreanolab/feature/2_feature
cpeddireddyy Dec 20, 2023
786c112
Flake8 for rank dir
cpeddireddyy Dec 30, 2023
8bc4dac
Fixed import error
cpeddireddyy Dec 30, 2023
05e2d1c
Fix Deepsourc py errors
cpeddireddyy Dec 30, 2023
667da74
fix deepsource py suggestions
cpeddireddyy Dec 30, 2023
0469599
Merge pull request #13 from padillacoreanolab/feature/2_feature
cpeddireddyy Dec 30, 2023
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ ENV/
# IDE settings
.vscode/
.idea/

.DS_Store
58 changes: 56 additions & 2 deletions docs/pc_mouseparty.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,58 @@

# pc_mouseparty module

::: pc_mouseparty.pc_mouseparty
::: pc_mouseparty.pc_mouseparty

:::pc_mouseparty.pc_mouseparty.vid_behavior.boris_extraction

function: threshold_bouts(start_stop_array, min_iti, min_bout):
"""
thresholds behavior bouts
by combining behavior bouts with interbout intervals of < min_iti
and then removing remaining bouts of < min_bout

Args (3 total):
start_stop_array: numpy array of dim (# of bouts, 2)
min_iti: float, min interbout interval in seconds
min_bout: float, min bout length in seconds

Returns (1):
start_stop_array: numpy array (ndim=(n bouts, 2))
of start&stop times (ms)
"""

function get_behavior_bouts(boris_df, subject, behavior, min_iti=0, min_bout=0):
"""
extracts behavior bout start and stop times from a boris df
thresholds individually by subject and behavior
returns start_stop_array ordered by start values

Args (5 total, 3 required):
boris_df: pandas dataframe of a boris file (aggregated event table)
subject: list of strings, desired subject(s) (as written in boris_df)
behavior: list of strings, desired behavior(s) (as written in boris_df)
min_iti: float, default=0, bouts w/ itis(s) < min_iti will be combined
min_bout: float, default=0, bouts < min_bout(s) will be deleted

Returns (1):
numpy array (ndim=(n bouts, 2)) of start&stop times (ms)

function save_behavior_bouts(directory, boris_df, subject, behavior, min_bout=0,
min_iti=0, filename=None):
"""
saves a numpy array of start&stop times (ms)
as filename: subject_behavior_bouts.npy

Args (7 total, 4 required):
directory: path to folder where filename.npy will be saved
path format: './folder/folder/'
boris_df: pandas dataframe of a boris file (aggregated event table)
subject: list of strings, desired subjects (as written in boris_df)
behavior: list of strings, desired behaviors (as written in boris_df)
min_iti: float, default=0, bouts w/ itis(s) < min_iti will be combined
min_bout: float, default=0, bouts < min_bouts(s) will be deleted
filename: string, default=None, must end in .npy

Returns:
none
"""
1 change: 0 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,4 @@ nav:
- Examples:
- examples/intro.ipynb
- API Reference:
- pc_mouseparty module: pc_mouseparty.md
- test_functions module: test_functions.md
93 changes: 93 additions & 0 deletions pc_mouseparty/medpc/medpc_extraction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import re
import pandas as pd


def medpc_txt2df(text_file_path):
"""
This function reads a medpc text data file into a pandas dataframe.

Args (1 total, 1 required):
text_file_path : str, a path to a medpc text file as a string.

Return (1):
df : pandas dataframe, a dataframe with the medpc data.
"""
# Open the medpc text file
# with open(text_file_path, "r") as file: # use this for package
with open(text_file_path.name) as file: # use this for gradio app
medpc_txt_file = file.read()

# split the file with each new line an element in a list
medpc_txt_file_lst = medpc_txt_file.split('\n')

# remove all empty elements in the list
medpc_txt_file_lst = list(filter(None, medpc_txt_file_lst))

# add medpc output vectors to lists
result = []
temp = []
for item in medpc_txt_file_lst:
# add values taht comeafter ":" to a list as floats
if re.search(r'^\s*\d+:\s+', item):
temp.append(item)
else:
if temp:
floats = [float(x) for x in re.findall(r'\d+\.\d+',
''.join(temp))]
result.append(floats)
temp = []
result.append(item)
if temp:
floats = [float(x) for x in re.findall(r'\d+\.\d+',
''.join(temp))]
result.append(floats)

# convert the list of lists and strings to
# a dictionary with everything before ":"
# as a key and everything after as the value
result_dict = {}
for item in result:
if ':' in item:
index = item.index(':')
key = item[:index]
value = item[index+1:].strip()
if not value:
value = result[result.index(item)+1]
result_dict[key] = value
elif type(item) == str:
result_dict[item] = []

# convert the dictionary to a dataframe
# values are of unequal length
# convert all values to lists
pd_series_lst = []
for i, j in result_dict.items():
if type(j) != list:
result_dict[i] = [j]
else:
result_dict[i] = j
pd_series_lst.append(pd.Series(j))

# add list to dataframe
df = pd.concat(pd_series_lst, axis=1)
df.columns = result_dict.keys()

return (df)


def cut_zeros(df):
"""
This function removes all trailing zeros of the medpc dataframe.

Args (2 total, 1 required):
df: pandas dataframe, a dataframe with the medpc data.

Return (1):
df : pandas dataframe, a dataframe with the medpc data
with trailing zeros removed.
"""
# find index of last row that does not only ahve 0 and Nan
last_idx = df[df.sum(axis=1).ne(0)].index[-1]
df = df[:last_idx+1]

return (df)
Loading
Loading