|
9 | 9 | import seaborn as sns
|
10 | 10 | #file imports
|
11 | 11 | from io import BytesIO
|
| 12 | +from datetime import datetime |
12 | 13 | import base64
|
13 | 14 | from pathlib import Path
|
14 | 15 | import os
|
|
51 | 52 |
|
52 | 53 | ######################################################################################################################################################
|
53 | 54 | # assign software version
|
54 |
| -software_version = '5.0.0' |
| 55 | +software_version = '5.1.0' |
55 | 56 |
|
56 | 57 | ######################################################################################################################################################
|
57 | 58 | # data loading
|
|
102 | 103 | file_like_object.seek(0)
|
103 | 104 |
|
104 | 105 | # Extract dataframes from each CSV file
|
105 |
| - read_dataframes = reader.extract_dataframes_from_csv(file_like_object, phrases_to_find) |
| 106 | + read_dataframes, date = reader.extract_dataframes_from_csv(file_like_object, phrases_to_find) |
106 | 107 |
|
107 | 108 | # at this point, we have loaded the assignment sheet and have sorted through the loaded data file to create a dict of dataframes
|
108 | 109 |
|
|
831 | 832 | fail_nocrRNA_check_df.to_csv(fail_nocrRNA_check_df_file_path, index=True)
|
832 | 833 | print(f"CSV created with data at {fail_nocrRNA_check_df_file_path}")
|
833 | 834 |
|
| 835 | +""" |
| 836 | +flagged_file = t13_hit_output.copy() |
| 837 | +processed_samples = set() |
| 838 | +for _, row in high_raw_ntc_signal_df.iterrows(): |
| 839 | + for col in high_raw_ntc_signal_df.columns: # cols are Sample, Assay, t13 |
| 840 | + cont_ntc_sample = row['Sample'] # NEG NTC sample |
| 841 | + cont_ntc_assay = row['Assay'] # NTC assay |
| 842 | + # now iterate over the flagged file |
| 843 | + for idx, sample_row in flagged_file.iterrows(): |
| 844 | + if cont_ntc_sample == idx: |
| 845 | + # add † to each cell value |
| 846 | + for assay_col in flagged_file.columns: |
| 847 | + if assay_col.upper() == cont_ntc_assay.upper(): |
| 848 | + # check that the sample-assay pair has alr been processed |
| 849 | + if (cont_ntc_sample, cont_ntc_assay) not in processed_samples: |
| 850 | + processed_samples.add((cont_ntc_sample, cont_ntc_assay)) |
| 851 | + # check if the value is NA (NaN) |
| 852 | + if pd.isna(sample_row[assay_col]) or sample_row[assay_col] == '': |
| 853 | + flagged_file.loc[idx, assay_col] = '†' # only dagger if value is NA |
| 854 | + else: |
| 855 | + flagged_file[assay_col] = flagged_file[assay_col].astype(str) |
| 856 | + #flagged_file.at[idx, assay_col] = str(flagged_file.at[idx, assay_col]) |
| 857 | + flagged_file.at[idx, assay_col] = f"{sample_row[assay_col]}†" # add dagger to the value |
| 858 | + |
834 | 859 |
|
835 | 860 |
|
| 861 | +""" |
836 | 862 | ######################################################################################################################################################
|
837 | 863 | # instantiate Flagger from flags.py
|
838 | 864 | flagger = Flagger()
|
839 | 865 |
|
840 |
| -invalid_assays, invalid_samples, flagged_files = flagger.assign_flags(fail_nocrRNA_check_df, high_raw_ntc_signal_df, rnasep_df_heatmap, QC_score_per_assay_df, t13_hit_output, rounded_t13_quant_norm, summary_samples_df, rounded_ntc_thresholds_output, t13_hit_binary_output) |
| 866 | +invalid_assays, invalid_samples, flagged_files, processed_samples, cont_ntc_sample, cont_ntc_assay = flagger.assign_flags(fail_nocrRNA_check_df, high_raw_ntc_signal_df, rnasep_df_heatmap, QC_score_per_assay_df, t13_hit_output, rounded_t13_quant_norm, summary_samples_df, rounded_ntc_thresholds_output, t13_hit_binary_output) |
841 | 867 |
|
842 | 868 | fl_t13_hit_output = flagged_files[0] # Results_Summary
|
843 | 869 | fl_rounded_t13_quant_norm = flagged_files[1] # NTC_Normalized_Quantitative_Results_Summary
|
|
1000 | 1026 | fig = heatmap_t13_quant_norm.savefig(heatmap_t13_quant_norm_filename, bbox_inches = 'tight', dpi=80)
|
1001 | 1027 | plt.close(fig)
|
1002 | 1028 |
|
1003 |
| -print("Operation complete.") |
1004 |
| - |
1005 | 1029 |
|
1006 | 1030 | ######################################################################################################################################################
|
1007 | 1031 | # RedCap Integration
|
1008 |
| -# set it as you have to enter a CLI for Redcap to run this code |
| 1032 | +# set it as you have to enter a CLI arg for Redcap to run this code |
1009 | 1033 |
|
1010 |
| -# if CLI[1] |
| 1034 | +if len(CLI_arg) > 2 and CLI_arg[2] == 'REDCAP': |
| 1035 | + # instantiate RedCapper from flags.py |
| 1036 | + redcapper = RedCapper() |
1011 | 1037 |
|
| 1038 | + # make copy of binary output file from RESULTS Excel sheet |
| 1039 | + fl_t13_hit_binary_output_2 = fl_t13_hit_binary_output.copy() |
1012 | 1040 |
|
1013 |
| -# instantiate RedCapper from flags.py |
1014 |
| -redcapper = RedCapper() |
| 1041 | + redcap_t13_hit_binary_output = redcapper.build_redcap(fl_t13_hit_binary_output_2, date, barcode_assignment) |
1015 | 1042 |
|
1016 |
| -# make copy of binary output file from RESULTS Excel sheet |
1017 |
| -fl_t13_hit_binary_output_2 = fl_t13_hit_binary_output.copy() |
| 1043 | + redcap_t13_hit_binary_output_file_path = os.path.join(res_subfolder, f'REDCAP_{barcode_assignment}.csv') |
| 1044 | + redcap_t13_hit_binary_output.to_csv(redcap_t13_hit_binary_output_file_path, index=True) |
| 1045 | + print("REDCAP file generated.") |
| 1046 | + print("Operation complete.") |
1018 | 1047 |
|
1019 |
| -redcap_t13_hit_binary_output = redcapper.build_redcap(fl_t13_hit_binary_output_2) |
1020 |
| - |
1021 |
| -redcap_t13_hit_binary_output_file_path = os.path.join(res_subfolder, f'REDCAP_{barcode_assignment}.csv') |
1022 |
| -redcap_t13_hit_binary_output.to_csv(redcap_t13_hit_binary_output_file_path, index=True) |
| 1048 | +else: |
| 1049 | + print("User did not specify REDCAP as a command line argument, and it follows that the REDCAP file was not generated.") |
| 1050 | + print("Operation complete.") |
1023 | 1051 |
|
1024 | 1052 |
|
0 commit comments