process_functions
genie.process_functions
¶
Processing functions that are used in the GENIE pipeline
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
module-attribute
¶
Functions¶
get_clinical_dataframe(filePathList)
¶
Gets the clinical file(s) and reads them in as a dataframe
PARAMETER | DESCRIPTION |
---|---|
filePathList
|
List of clinical files
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
when PATIENT_ID column doesn't exist |
ValueError
|
When PATIENT_IDs in sample file doesn't exist in patient file |
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
pd.DataFrame: clinical file as a dataframe |
Source code in genie/process_functions.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
get_assay_dataframe(filepath_list)
¶
Reads in assay_information.yaml file and outputs it as a dataframe
PARAMETER | DESCRIPTION |
---|---|
filepath_list
|
list of files
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
thrown if read error with file |
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
pd.DataFrame: dataframe version of assay info file |
Source code in genie/process_functions.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
retry_get_url(url)
¶
Implement retry logic when getting urls. Timesout at 3 seconds, retries 5 times.
PARAMETER | DESCRIPTION |
---|---|
url
|
Http or https url
|
RETURNS | DESCRIPTION |
---|---|
requests.get() |
Source code in genie/process_functions.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
checkUrl(url)
¶
Check if URL link is live
PARAMETER | DESCRIPTION |
---|---|
url
|
web URL
|
Source code in genie/process_functions.py
156 157 158 159 160 161 162 163 164 |
|
checkColExist(DF, key)
¶
This function checks if the column(s) exist(s) in a dataframe
PARAMETER | DESCRIPTION |
---|---|
DF
|
pandas dataframe
TYPE:
|
key
|
Expected column header name(s)
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True if column(s) exist(s)
TYPE:
|
Source code in genie/process_functions.py
168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
validate_genie_identifier(identifiers, center, filename, col)
¶
Validate GENIE sample and patient ids.
PARAMETER | DESCRIPTION |
---|---|
identifiers
|
Array of GENIE identifiers
TYPE:
|
center
|
GENIE center name
TYPE:
|
filename
|
name of file
TYPE:
|
col
|
Column with identifiers
TYPE:
|
return
str: Errors
Source code in genie/process_functions.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
lookup_dataframe_value(df, col, query)
¶
Look up dataframe value given query and column
PARAMETER | DESCRIPTION |
---|---|
df
|
dataframe
|
col
|
column with value to return
|
query
|
Query for specific column
|
RETURNS | DESCRIPTION |
---|---|
value |
Source code in genie/process_functions.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
rmFiles(folderPath, recursive=True)
¶
Convenience function to remove all files in dir
PARAMETER | DESCRIPTION |
---|---|
folderPath
|
Path to folder
|
recursive
|
Removes all files recursively
DEFAULT:
|
Source code in genie/process_functions.py
227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
removeStringFloat(string)
¶
remove string float in tsv file
PARAMETER | DESCRIPTION |
---|---|
string
|
tsv file in string format
|
Return
string: string with float removed
Source code in genie/process_functions.py
243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
removePandasDfFloat(df, header=True)
¶
Remove decimal for integers due to pandas
PARAMETER | DESCRIPTION |
---|---|
df
|
Pandas dataframe
|
Return
str: tsv in text
Source code in genie/process_functions.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
removeFloat(df)
¶
Need to remove this function as it calls another function
Source code in genie/process_functions.py
279 280 281 282 283 284 285 286 287 288 |
|
checkGenieId(ID, center)
¶
Checks if GENIE ID is labelled correctly and reformats the GENIE ID
PARAMETER | DESCRIPTION |
---|---|
ID
|
string
|
center
|
GENIE center
|
Return
str: Formatted GENIE ID string
Source code in genie/process_functions.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
seqDateFilter(clinicalDf, processingDate, days)
¶
SEQ_DATE filter SEQ_DATE - Clinical data (6 and 12 as parameters) Jan-2017 , given processing date (today) -> staging release (processing date - Jan-2017 < 6 months) July-2016 , given processing date (today) -> consortium release (processing date - July-2016 between 6 months - 12 months)
Source code in genie/process_functions.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
addClinicalHeaders(clinicalDf, mapping, patientCols, sampleCols, samplePath, patientPath)
¶
Add clinical file headers
PARAMETER | DESCRIPTION |
---|---|
clinicalDf
|
clinical dataframe
|
mapping
|
mapping dataframe, maps clinical columns to labels and descriptions
|
patientCols
|
list of patient columns
|
sampleCols
|
list of sample columns
|
samplePath
|
clinical sample path
|
patientPath
|
clinical patient path
|
Source code in genie/process_functions.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
|
_check_valid_df(df, col)
¶
Checking if variable is a pandas dataframe and column specified exist
PARAMETER | DESCRIPTION |
---|---|
df
|
Pandas dataframe
|
col
|
Column name
|
Source code in genie/process_functions.py
430 431 432 433 434 435 436 437 438 439 440 441 |
|
_get_left_diff_df(left, right, checkby)
¶
Subset the dataframe based on 'checkby' by taking values in the left df that arent in the right df
PARAMETER | DESCRIPTION |
---|---|
left
|
Dataframe
|
right
|
Dataframe
|
checkby
|
Column of values to compare
|
Return
Dataframe: Subset of dataframe from left that don't exist in the right
Source code in genie/process_functions.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
|
_get_left_union_df(left, right, checkby)
¶
Subset the dataframe based on 'checkby' by taking the union of values in the left df with the right df
PARAMETER | DESCRIPTION |
---|---|
left
|
Dataframe
|
right
|
Dataframe
|
checkby
|
Column of values to compare
|
Return
Dataframe: Subset of dataframe from left that also exist in the right
Source code in genie/process_functions.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
|
_append_rows(new_datasetdf, databasedf, checkby)
¶
Compares the dataset from the database and determines which rows to append from the dataset
PARAMETER | DESCRIPTION |
---|---|
new_datasetdf
|
Input data dataframe
|
databasedf
|
Existing data dataframe
|
checkby
|
Column of values to compare
|
Return
Dataframe: Dataframe of rows to append
Source code in genie/process_functions.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
|
_delete_rows(new_datasetdf, databasedf, checkby)
¶
Compares the dataset from the database and determines which rows to delete from the dataset
PARAMETER | DESCRIPTION |
---|---|
new_datasetdf
|
Input data dataframe
|
databasedf
|
Existing data dataframe
|
checkby
|
Column of values to compare
|
Return
Dataframe: Dataframe of rows to delete
Source code in genie/process_functions.py
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
|
_create_update_rowsdf(updating_databasedf, updatesetdf, rowids, differentrows)
¶
Create the update dataset dataframe
PARAMETER | DESCRIPTION |
---|---|
updating_databasedf
|
Update database dataframe
|
updatesetdf
|
Update dataset dataframe
|
rowids
|
rowids of the database (Synapse ROW_ID, ROW_VERSION)
|
differentrows
|
vector of booleans for rows that need to be updated True for update, False for not
|
RETURNS | DESCRIPTION |
---|---|
dataframe
|
Update dataframe |
Source code in genie/process_functions.py
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
|
_update_rows(new_datasetdf, databasedf, checkby)
¶
Compares the dataset from the database and determines which rows to update from the dataset
PARAMETER | DESCRIPTION |
---|---|
new_datasetdf
|
Input data dataframe
|
databasedf
|
Existing data dataframe
|
checkby
|
Column of values to compare
|
Return
Dataframe: Dataframe of rows to update
Source code in genie/process_functions.py
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
|
checkInt(element)
¶
Check if an item can become an integer
PARAMETER | DESCRIPTION |
---|---|
element
|
Any variable and type
|
RETURNS | DESCRIPTION |
---|---|
boolean
|
True/False |
Source code in genie/process_functions.py
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 |
|
check_col_and_values(df, col, possible_values, filename, na_allowed=False, required=False, sep=None)
¶
This function checks if the column exists then checks if the values in the column have the correct values
PARAMETER | DESCRIPTION |
---|---|
df
|
Input dataframe
|
col
|
Expected column name
|
possible_values
|
list of possible values
|
filename
|
Name of file
|
required
|
If the column is required. Default is False
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
warning, error |
Source code in genie/process_functions.py
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 |
|
extract_oncotree_code_mappings_from_oncotree_json(oncotree_json, primary, secondary)
¶
Source code in genie/process_functions.py
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 |
|
get_oncotree_code_mappings(oncotree_tumortype_api_endpoint_url)
¶
CREATE ONCOTREE DICTIONARY MAPPING TO PRIMARY, SECONDARY, CANCER TYPE, AND CANCER DESCRIPTION
Source code in genie/process_functions.py
727 728 729 730 731 732 733 734 735 736 737 738 |
|
getCODE(mapping, key, useDescription=False)
¶
Source code in genie/process_functions.py
742 743 744 745 746 747 748 749 750 |
|
getPrimary(code, oncotreeDict, primary)
¶
Source code in genie/process_functions.py
753 754 755 756 757 758 759 760 761 762 763 |
|
synapse_login(debug=False)
¶
Logs into Synapse if credentials are saved. If not saved, then user is prompted username and auth token.
PARAMETER | DESCRIPTION |
---|---|
debug
|
Synapse debug feature. Defaults to False
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Synapse
|
Synapseclient object |
Source code in genie/process_functions.py
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 |
|
get_gdc_data_dictionary(filetype)
¶
Use the GDC API to get the values allowed for columns of different filetypes (ie. disease_type in the case file)
PARAMETER | DESCRIPTION |
---|---|
filetype
|
GDC file type (ie. case, read_group)
|
Return
json: Dictionary of allowed columns for the filetype and allowed values for those columns
Source code in genie/process_functions.py
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 |
|
_create_schema(syn, table_name, parentid, columns=None, annotations=None)
¶
Creates Table Schema
PARAMETER | DESCRIPTION |
---|---|
syn
|
Synapse object
|
table_name
|
Name of table
|
parentid
|
Project synapse id
|
columns
|
Columns of Table
DEFAULT:
|
annotations
|
Dictionary of annotations to add
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Schema |
Source code in genie/process_functions.py
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 |
|
_update_database_mapping(syn, database_synid_mappingdf, database_mapping_synid, fileformat, new_tableid)
¶
Updates database to synapse id mapping table
PARAMETER | DESCRIPTION |
---|---|
syn
|
Synapse object
|
database_synid_mappingdf
|
Database to synapse id mapping dataframe
|
database_mapping_synid
|
Database to synapse id table id
|
fileformat
|
File format updated
|
new_tableid
|
New file format table id
|
RETURNS | DESCRIPTION |
---|---|
Updated Table object |
Source code in genie/process_functions.py
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 |
|
_move_entity(syn, ent, parentid, name=None)
¶
Moves an entity (works like linux mv)
PARAMETER | DESCRIPTION |
---|---|
syn
|
Synapse object
|
ent
|
Synapse Entity
|
parentid
|
Synapse Project id
|
name
|
New Entity name if a new name is desired
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Moved Entity |
Source code in genie/process_functions.py
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 |
|
get_dbmapping(syn, projectid)
¶
Gets database mapping information
PARAMETER | DESCRIPTION |
---|---|
syn
|
Synapse connection
TYPE:
|
projectid
|
Project id where new data lives
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
{'synid': database mapping syn id, 'df': database mapping pd.DataFrame} |
Source code in genie/process_functions.py
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 |
|
create_new_fileformat_table(syn, file_format, newdb_name, projectid, archive_projectid)
¶
Creates new database table based on old database table and archives old database table
PARAMETER | DESCRIPTION |
---|---|
syn
|
Synapse object
TYPE:
|
file_format
|
File format to update
TYPE:
|
newdb_name
|
Name of new database table
TYPE:
|
projectid
|
Project id where new database should live
TYPE:
|
archive_projectid
|
Project id where old database should be moved
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
{"newdb_ent": New database synapseclient.Table, "newdb_mappingdf": new databse pd.DataFrame, "moved_ent": old database synpaseclient.Table} |
Source code in genie/process_functions.py
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 |
|
create_missing_columns(dataset, schema)
¶
Creates and fills missing columns with the relevant NA value for the given data type. Note that special handling had to occur for allowing NAs in integer based columns in pandas by converting the integer column into the Int64 (pandas nullable integer data type)
PARAMETER | DESCRIPTION |
---|---|
dataset
|
input dataset to fill missing columns for
TYPE:
|
schema
|
the expected schema {column_name(str): data_type(str)} for the input dataset
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Series
|
pd.Series: updated dataset |
Source code in genie/process_functions.py
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 |
|
check_values_in_column(df, col, values)
¶
Check if a column in a dataframe contains specific values Args: df (pd.DataFrame): The clinical dataframe col (str): The column name values (list): Expected values in the column Returns: bool: True if the column contains the specified values
Source code in genie/process_functions.py
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 |
|