xtra¶
Module: xtra
¶
Unused functions.
- Authors:
- Arno Klein, 2015 (arno@sagebase.org) http://binarybottle.com
Copyright 2015, Sage Bionetworks (http://sagebase.org), Apache v2.0 License
Functions¶
-
mhealthx.xtra.
arff_to_csv
(arff_file, output_csv_file=None)¶ Convert an arff file to a row.
Column headers include lines that start with '@attribute ‘, include ‘numeric’, and whose intervening string is not exception_string. The function raises an error if the number of resulting columns does not equal the number of numeric values.
Example input: arff output from openSMILE’s SMILExtract command
Adapted some formatting from: http://biggyani.blogspot.com/2014/08/ converting-back-and-forth-between-weka.html
- arff_file : string
- arff file (full path)
- output_csv_file : string or None
- output table file (full path)
- row_data : Pandas Series
- output table data
- output_csv_file : string or None
- output table file (full path)
>>> from mhealthx.xtra import arff_to_csv >>> arff_file = '/Users/arno/csv/test1.csv' >>> output_csv_file = None #'test.csv' >>> row_data, output_csv_file = arff_to_csv(arff_file, output_csv_file)
-
mhealthx.xtra.
concatenate_tables_horizontally
(tables, output_csv_file=None)¶ Horizontally concatenate multiple table files or pandas DataFrames that have the same number of rows and store as a csv table.
If any one of the members of the tables list is itself a list, call concatenate_tables_vertically() on this list.
- tables : list of strings or pandas DataFrames
- each component table has the same number of rows
- output_csv_file : string or None
- output table file (full path)
- table_data : Pandas DataFrame
- output table data
- output_csv_file : string or None
- output table file (full path)
>>> import pandas as pd >>> from mhealthx.xtra import concatenate_tables_horizontally >>> df1 = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'], >>> 'B': ['B0', 'B1', 'B2', 'B3'], >>> 'C': ['C0', 'C1', 'C2', 'C3']}, >>> index=[0, 1, 2, 3]) >>> df2 = pd.DataFrame({'A': ['A4', 'A5', 'A6', 'A7'], >>> 'B': ['B4', 'B5', 'B6', 'B7'], >>> 'C': ['C4', 'C5', 'C6', 'C7']}, >>> index=[0, 1, 2, 3]) >>> tables = [df1, df2] >>> output_csv_file = None #'./test.csv' >>> table_data, output_csv_file = concatenate_tables_horizontally(tables, output_csv_file)
-
mhealthx.xtra.
concatenate_tables_vertically
(tables, output_csv_file=None)¶ Vertically concatenate multiple table files or pandas DataFrames with the same column names and store as a csv table.
- tables : list of table files or pandas DataFrames
- each table or dataframe has the same column names
- output_csv_file : string or None
- output table file (full path)
- table_data : Pandas DataFrame
- output table data
- output_csv_file : string or None
- output table file (full path)
>>> import pandas as pd >>> from mhealthx.xtra import concatenate_tables_vertically >>> df1 = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'], >>> 'B': ['B0', 'B1', 'B2', 'B3'], >>> 'C': ['C0', 'C1', 'C2', 'C3']}, >>> index=[0, 1, 2, 3]) >>> df2 = pd.DataFrame({'A': ['A4', 'A5', 'A6', 'A7'], >>> 'B': ['B4', 'B5', 'B6', 'B7'], >>> 'C': ['C4', 'C5', 'C6', 'C7']}, >>> index=[0, 1, 2, 3]) >>> tables = [df1, df2] >>> tables = ['/Users/arno/csv/table1.csv', '/Users/arno/csv/table2.csv'] >>> output_csv_file = None #'./test.csv' >>> table_data, output_csv_file = concatenate_tables_vertically(tables, output_csv_file)
-
mhealthx.xtra.
concatenate_two_tables_horizontally
(table1, table2, output_csv_file=None)¶ Horizontally concatenate two table files or pandas DataFrames that have the same number of rows and store as a csv table.
If either of the tables is itself a list, concatenate_two_tables_horizontally() will call concatenate_tables_vertically() on this list.
table1 : string or pandas DataFrame table2 : string or pandas DataFrame
same number of rows as table1- output_csv_file : string or None
- output table file (full path)
- table_data : Pandas DataFrame
- output table data
- output_csv_file : string or None
- output table file (full path)
>>> import pandas as pd >>> from mhealthx.xtra import concatenate_two_tables_horizontally >>> table1 = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'], >>> 'B': ['B0', 'B1', 'B2', 'B3'], >>> 'C': ['C0', 'C1', 'C2', 'C3']}, >>> index=[0, 1, 2, 3]) >>> table2 = pd.DataFrame({'A': ['A4', 'A5', 'A6', 'A7'], >>> 'B': ['B4', 'B5', 'B6', 'B7'], >>> 'C': ['C4', 'C5', 'C6', 'C7']}, >>> index=[0, 1, 2, 3]) >>> output_csv_file = None #'./test.csv' >>> table_data, output_csv_file = concatenate_two_tables_horizontally(table1, table2, output_csv_file)
-
mhealthx.xtra.
copy_synapse_table
(synapse_table_id, synapse_project_id, table_name='', remove_columns=[], username='', password='')¶ Copy Synapse table to another Synapse project.
- synapse_table_id : string
- Synapse ID for table to copy
- synapse_project_id : string
- copy table to project with this Synapse ID
- table_name : string
- schema name of table
- remove_columns : list of strings
- column headers for columns to be removed
- username : string
- Synapse username (only needed once on a given machine)
- password : string
- Synapse password (only needed once on a given machine)
- table_data : Pandas DataFrame
- Synapse table contents
- table_name : string
- schema name of table
- synapse_project_id : string
- Synapse ID for project within which table is to be written
>>> from mhealthx.xtra import copy_synapse_table >>> synapse_table_id = 'syn4590865' >>> synapse_project_id = 'syn4899451' >>> table_name = 'Copy of ' + synapse_table_id >>> remove_columns = ['audio_audio.m4a', 'audio_countdown.m4a'] >>> username = '' >>> password = '' >>> table_data, table_name, synapse_project_id = copy_synapse_table(synapse_table_id, synapse_project_id, table_name, remove_columns, username, password)
-
mhealthx.xtra.
feature_file_to_synapse_table
(feature_file, raw_feature_file, source_file_id, provenance_activity_id, command, command_line, synapse_table_id, username='', password='')¶ Upload files and file handle IDs to Synapse.
- feature_file : string
- path to file to upload to Synapse
- raw_feature_file : string
- path to file to upload to Synapse
- source_file_id : string
- Synapse file handle ID to source file used to generate features
- provenance_activity_id : string
- Synapse provenance activity ID
- command : string
- name of command run to generate raw feature file
- command_line : string
- full command line run to generate raw feature file
- synapse_table_id : string
- Synapse table ID for table to store file handle IDs, etc.
- username : string
- Synapse username (only needed once on a given machine)
- password : string
- Synapse password (only needed once on a given machine)
>>> from mhealthx.xtra import feature_file_to_synapse_table >>> feature_file = '/Users/arno/Local/wav/test1.wav' >>> raw_feature_file = '/Users/arno/Local/wav/test1.wav' >>> source_file_id = '' >>> provenance_activity_id = '' >>> command_line = 'SMILExtract -C blah -I blah -O blah' >>> synapse_table_id = 'syn4899451' >>> username = '' >>> password = '' >>> feature_file_to_synapse_table(feature_file, raw_feature_file, source_file_id, provenance_activity_id, command_line, synapse_table_id, username, password)
-
mhealthx.xtra.
rename_file
(old_file, new_filename='', new_path='', file_append='', create_file=False)¶ Rename (and optionally copy) a file / path / file_append.
- old_file : string
- old file name (full path)
- new_filename : string
- new file name (not the full path)
- new_path : string
- replacement path
- file_append : string
- append to file names
- create_file : Boolean
- copy file (or just create a string)?
- new_filepath : string
- new file name (full path, if remove_path not set)
>>> from mhealthx.utils import rename_file >>> old_file = '/homedir/wav/test1.wav' >>> new_filename = '' >>> new_path = '.' >>> file_append = '.csv' >>> create_file = True >>> new_filepath = rename_file(old_file, new_filename, new_path, file_append, create_file)
-
mhealthx.xtra.
write_synapse_table
(table_data, synapse_project_id, table_name='', username='', password='')¶ Write data to a Synapse table.
- table_data : Pandas DataFrame
- Synapse table contents
- synapse_project_id : string
- Synapse ID for project within which table is to be written
- table_name : string
- schema name of table
- username : string
- Synapse username (only needed once on a given machine)
- password : string
- Synapse password (only needed once on a given machine)
>>> from mhealthx.xio import read_files_from_synapse_row >>> from mhealthx.xtra import write_synapse_table >>> synapse_table = 'syn4590865' >>> row = >>> column_name = '' >>> out_path = '.' >>> username = '' >>> password = '' >>> table_data, files = read_files_from_synapse_row(synapse_table, row, column_name, out_path, username, password) >>> synapse_project_id = 'syn4899451' >>> table_name = 'Contents of ' + synapse_table >>> write_synapse_table(table_data, synapse_project_id, table_name, username, password)