Skip to content

Commit

Permalink
Check for None values before saving DF
Browse files Browse the repository at this point in the history
  • Loading branch information
asistradition committed Mar 10, 2022
1 parent 105170f commit 0d60611
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 4 additions & 4 deletions inferelator_prior/network_from_motifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down

0 comments on commit 0d60611

Please sign in to comment.