-
Notifications
You must be signed in to change notification settings - Fork 4
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
Descriptor files #89
base: main
Are you sure you want to change the base?
Descriptor files #89
Changes from 4 commits
83ae0ed
0619d4c
5d72e84
372c6b5
6f593e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.2 | ||
0.0.3-a.1 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from redcap_bridge.utils import compress_record | ||
from redcap_bridge.utils import compress_record, conversion_to_odml_table_descriptor | ||
from diglab_utils.test_utils import test_directory, initialize_test_dir | ||
|
||
|
||
|
@@ -13,3 +13,9 @@ def test_compressedCSV(initialize_test_dir): | |
exp = exp_file.read() | ||
assert res == exp | ||
|
||
|
||
def test_conversion_to_odml_table_descriptor(initialize_test_dir): | ||
test_dir = test_directory / 'testfiles_redcap' / 'descriptors' | ||
|
||
conversion_to_odml_table_descriptor(test_dir / 'Vision4Action_DATA_2023-04-13_1110.csv', session_number=5) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test is only checking if the code runs into an error so far. Could you extend this and also test the content of the converted file? Maybe you will need to add an odmltables reference test file to compare against. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, will change the test in priority |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,3 +81,27 @@ def remove_columns(csv_file, compressed_file=None): | |
def exportCSVtoXLS(csv_file, compressed_file=None): | ||
read_file = pd.read_csv(csv_file, na_filter=False, dtype='str') | ||
read_file.to_excel(r'Path', index=None, header=True) | ||
|
||
def conversion_to_odml_table_descriptor(full_elabbook_csv, session_number): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a keyword argument to automatically save this to a csv file if a filename is provided? |
||
""" | ||
Create odml descriptor file base on the full elabbook csv file | ||
Args: | ||
full_elabbook_csv: path to the full csv file | ||
session_number: number of the session you want to create descriptor csv file | ||
Returns: | ||
descriptor_elabbook_csv: csv descriptor file of the specific session given | ||
""" | ||
|
||
df = pd.read_csv(full_elabbook_csv) | ||
|
||
df_ses = df.loc[df['ses_number'] == session_number] | ||
|
||
cols_to_melt = df_ses.columns[df_ses.columns.get_loc('ethical_protocol_id'):] | ||
|
||
print(cols_to_melt) | ||
|
||
df_melted = df_ses.melt(id_vars='record_id', value_vars=cols_to_melt) | ||
|
||
df_melted = df_melted.rename(columns={'variable': 'Property name'}) | ||
|
||
print(df_melted.to_string()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a set of mandatory columns for odmltables csv files. Can you check that all of them are present after the conversion and have values that are accepted by odmltables? E.g. the data type colum can only contain specific values that are understood by odmltables... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this change should not be part of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating from the latest master should fix this.