From 0d6061132d94b0358fcf733a2c88d9eaa57afac8 Mon Sep 17 00:00:00 2001 From: asistradition Date: Thu, 10 Mar 2022 13:36:24 -0500 Subject: [PATCH] Check for None values before saving DF --- CHANGELOG.md | 4 ++++ inferelator_prior/network_from_motifs.py | 8 ++++---- setup.py | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c5539e..f4e3eb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### Version 0.3.5 + +* Fix bug when no regulators are found and saving locations is set. + ### Version 0.3.4 * Produce a filtered TF binding table when `--save_filtered_location_data` is set. diff --git a/inferelator_prior/network_from_motifs.py b/inferelator_prior/network_from_motifs.py index c16c241..662a567 100644 --- a/inferelator_prior/network_from_motifs.py +++ b/inferelator_prior/network_from_motifs.py @@ -319,7 +319,7 @@ def network_scan_build_single_tf(tf_mi_df): motif_information = [df for _, df in motif_information.groupby(MOTIF_NAME_COL)] for i, res in enumerate(pool.imap_unordered(network_scan_build_single_tf, motif_information)): - if save_locs: + if save_locs and res[1] is not None: res[1].to_csv(save_locs, sep="\t", mode="w" if i == 0 else "a", header=i == 0) p_m, r_m, p_d = res[0] @@ -347,7 +347,7 @@ def network_scan_build_single_tf(tf_mi_df): print("Writing output file {o}".format(o=output_prefix + "_edge_matrix.tsv.gz")) (prior_matrix != 0).astype(int).to_csv(output_prefix + "_edge_matrix.tsv.gz", sep="\t") - if save_locs_filtered: + if save_locs_filtered and prior_data is not None: prior_data.to_csv(save_locs_filtered, sep="\t") return prior_matrix, raw_matrix, prior_data @@ -412,7 +412,7 @@ def network_scan(motifs, motif_information, genes, genomic_fasta_file, constrain for chromosome, df in motif_peaks[MotifScan.chromosome_col].value_counts().iteritems(): print("Chromosome {c}: {n} motif hits".format(c=chromosome, n=df)) - if save_locs: + if save_locs and motif_peaks is not None: print(f"Writing output file {save_locs}") motif_peaks.to_csv(save_locs, sep="\t") @@ -451,7 +451,7 @@ def network_build(raw_matrix, prior_data, num_cores=1, output_prefix=None, debug pm_melt = prior_matrix.reset_index().melt(id_vars=PRIOR_GENE, var_name=PRIOR_TF, value_name='Filter_Included') prior_data = pd.merge(prior_data, pm_melt) - if save_locs_filtered and output_prefix is not None: + if save_locs_filtered and output_prefix is not None and prior_data is not None: print(f"Writing output file {save_locs_filtered}") prior_data.to_csv(save_locs_filtered, sep="\t") diff --git a/setup.py b/setup.py index 9101215..66c22b5 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ install_requires = ["numpy", "pandas>=1.0", "HTSeq", "pybedtools", "scipy", "pathos", "sklearn", "tqdm"] tests_require = ["coverage", "nose", "pysam"] -version = "0.3.4" +version = "0.3.5" # Description from README.md base_dir = os.path.dirname(os.path.abspath(__file__))