Skip to content

Commit

Permalink
Fix parsing error v0.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
asistradition committed Feb 16, 2022
1 parent 5543a31 commit bb6b700
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 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.2

* Corrected a parsing error when reading CisBP PWM files

### Version 0.3.1

* Added `link_atac_bed_to_genes` module to link specific peaks from a BED file to nearby genes
Expand Down
4 changes: 4 additions & 0 deletions inferelator_prior/motifs/meme.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def read(file_descript):
def write(file_descript, motifs, alphabet=None, background=None, mode="w"):

motifs = [motifs] if not isinstance(motifs, (list, tuple, pd.Series)) else motifs

if len(motifs) == 0:
raise RuntimeError("Unable to write motif file with zero motifs")

alphabet = alphabet if alphabet is not None else motifs[0].alphabet
background = np.array([[1 / len(alphabet)] * len(alphabet)]) if background is None else background

Expand Down
13 changes: 7 additions & 6 deletions inferelator_prior/motifs/pwm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ def read(pwm_file_list, info_file, background=None, direct_only=False, pwm_has_i

for pwm_file in pwm_file_list:
pwm_id = os.path.splitext(os.path.basename(pwm_file))[0]
match_id = info_df[MOTIF_COL] == pwm_id

if pwm_id not in info_df[MOTIF_COL]:
if (match_id).sum() == 0:
pwm_not_present.append(pwm_id)
continue

if direct_only:
direct = info_df.loc[info_df[MOTIF_COL] == pwm_id, TF_STATUS_COL].str.contains("D")
direct = info_df.loc[match_id, TF_STATUS_COL].str.contains("D")
if not direct.any():
continue
else:
pwm_names = info_df.loc[(info_df[MOTIF_COL] == pwm_id) & (info_df[TF_STATUS_COL] == "D"), TF_NAME_COL]
pwm_names = info_df.loc[match_id & (info_df[TF_STATUS_COL] == "D"), TF_NAME_COL]
else:
pwm_names = info_df.loc[info_df[MOTIF_COL] == pwm_id, TF_NAME_COL]
pwm_names = info_df.loc[match_id, TF_NAME_COL]

pwm_name = "/".join(pwm_names)

Expand Down Expand Up @@ -63,8 +64,8 @@ def read(pwm_file_list, info_file, background=None, direct_only=False, pwm_has_i
motifs.append(motif)

if len(pwm_not_present) > 0:
print("{pwm} PWM files not found in in {c} of {cf}".format(pwm=len(pwm_not_present), c=MOTIF_COL, cf=info_file))
print(f"{len(pwm_not_present)} PWM files not found in in {MOTIF_COL} of {info_file}")
if len(pwm_malformed) > 0:
print("{pwm} PWM files malformed and improperly parsed".format(pwm=len(pwm_malformed)))
print(f"{len(pwm_malformed)} PWM files malformed and improperly parsed")

return motifs
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
from setuptools import setup, find_packages

install_requires = ["numpy", "pandas>=1.0", "HTSeq", "pybedtools", "scipy", "pathos", "sklearn"]
install_requires = ["numpy", "pandas>=1.0", "HTSeq", "pybedtools", "scipy", "pathos", "sklearn", "tqdm"]
tests_require = ["coverage", "nose", "pysam"]
version = "0.3.1"
version = "0.3.2"

# Description from README.md
base_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down

0 comments on commit bb6b700

Please sign in to comment.