Skip to content

Commit 33ade29

Browse files
authored
Merge branch 'develop' into master
2 parents d69db16 + 61ca482 commit 33ade29

11 files changed

Lines changed: 203 additions & 44 deletions

File tree

gimmemotifs/c_metrics.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ double matrix_ed_mean(double matrix1[][4], double matrix2[][4], int length) {
211211

212212
double distance(double col1[], double col2[]) {
213213
// Return the distance between two motifs (Harbison et al.)
214+
// https://www.nature.com/articles/nature02800#Sec2
214215
int n;
215216
double d = 0;
216217

gimmemotifs/commands/motifs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import numpy as np
1616
import pandas as pd
17+
from tqdm.auto import tqdm
1718

1819
from gimmemotifs.background import create_background_file
1920
from gimmemotifs.comparison import MotifComparer, select_nonredundant_motifs
@@ -255,7 +256,8 @@ def motifs(args):
255256
# At the moment this is not ideal, as scanning is now performed twice
256257
# for this set of non-redundant motifs.
257258
motif_dict = dict([(m.id, m) for m in motifs])
258-
for motif in nr_motifs:
259+
logger.info("creating BED files with scan results")
260+
for motif in tqdm(nr_motifs):
259261
with NamedTemporaryFile(mode="w") as f:
260262
print(motif_dict[motif].to_ppm(), file=f)
261263
f.flush()
@@ -270,6 +272,7 @@ def motifs(args):
270272
zscore=args.zscore,
271273
gcnorm=args.gc,
272274
bgfile=bgfile,
275+
progress=False,
273276
)
274277

275278
if args.report:

gimmemotifs/comparison.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from gimmemotifs.config import MotifConfig
2727
from gimmemotifs.c_metrics import pfmscan, score
2828
from gimmemotifs.motif import parse_motifs, read_motifs
29-
from gimmemotifs.utils import pfmfile_location, make_equal_length
29+
from gimmemotifs.utils import pfmfile_location, make_equal_length, ppm_pseudocount
3030

3131
# pool import is at the bottom
3232

@@ -204,6 +204,7 @@ def chisq(p1, p2):
204204
-------
205205
score : float
206206
"""
207+
207208
return chi2_contingency([p1, p2])[1]
208209

209210

@@ -440,8 +441,13 @@ def compare_motifs(
440441
combine,
441442
self.max_partial(m1.pwm, m2.pwm, metric, combine),
442443
)
443-
elif metric in ["pcc", "ed", "distance", "wic", "chisq", "ssd"]:
444-
return self.max_partial(m1.pwm, m2.pwm, metric, combine)
444+
elif metric in ["pcc", "ed", "distance", "wic", "chisq", "ssd", "akl"]:
445+
return self.max_partial(
446+
ppm_pseudocount(m1.pwm),
447+
ppm_pseudocount(m2.pwm),
448+
metric,
449+
combine,
450+
)
445451
else:
446452
return self.max_partial(m1.pfm, m2.pfm, metric, combine)
447453

@@ -455,19 +461,33 @@ def compare_motifs(
455461
combine,
456462
self.max_total(m1.pwm, m2.pwm, metric, combine),
457463
)
458-
elif metric in ["pcc", "akl"]:
459-
# Slightly randomize the weight matrix
464+
elif metric in [
465+
"ed",
466+
"distance",
467+
"wic",
468+
"chisq",
469+
"pcc",
470+
"ssd",
471+
"akl",
472+
"pcc",
473+
]:
460474
return self.max_total(
461-
m1.wiggle_pwm(), m2.wiggle_pwm(), metric, combine
475+
ppm_pseudocount(m1.pwm),
476+
ppm_pseudocount(m2.pwm),
477+
metric,
478+
combine,
462479
)
463-
elif metric in ["ed", "distance", "wic", "chisq", "pcc", "ssd"]:
464-
return self.max_total(m1.pwm, m2.pwm, metric, combine)
465480
else:
466481
return self.max_total(m1.pfm, m2.pfm, metric, combine)
467482

468483
elif match == "subtotal":
469484
if metric in ["pcc", "ed", "distance", "wic", "chisq", "ssd"]:
470-
return self.max_subtotal(m1.pwm, m2.pwm, metric, combine)
485+
return self.max_subtotal(
486+
ppm_pseudocount(m1.pwm),
487+
ppm_pseudocount(m2.pwm),
488+
metric,
489+
combine,
490+
)
471491
else:
472492
return self.max_subtotal(m1.pfm, m2.pfm, metric, combine)
473493
else:

gimmemotifs/moap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ def moap(
691691
motif_names = [m.id for m in read_motifs(pfmfile)]
692692
scores = []
693693
if method == "classic" or scoring == "count":
694-
logger.info("motif scanning (scores)")
694+
logger.info("motif scanning (counts)")
695695
scores = scan_regionfile_to_table(
696696
inputfile,
697697
genome,

gimmemotifs/motif/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(self, pfm=None, ppm=None, places=4):
9797
else:
9898
self.pfm = []
9999
else:
100-
if np.all(np.isclose(np.sum(pfm, 1), 1)) and ppm is None:
100+
if np.all(np.isclose(np.sum(pfm, 1), 1, atol=1e-3)) and ppm is None:
101101
# PFM is specified actually a PPM. We don't mind.
102102
self.ppm = pfm
103103
else:

gimmemotifs/motif/_comparison.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ def pcc(self, ppm1, ppm2, pos):
5454
ppm1, ppm2 = make_equal_length(ppm1, ppm2, pos, truncate="both")
5555

5656
# Compute pearson correlation between aligned parts of the motif
57-
r = np.array([pearsonr(x, y)[0] for x, y in zip(ppm1, ppm2)])
57+
r = np.array(
58+
[
59+
pearsonr(x, y)[0]
60+
if not (np.all(x == 0.25)) or not (np.all(y == 0.25))
61+
else 0
62+
for x, y in zip(ppm1, ppm2)
63+
]
64+
)
5865
r[np.isnan(r)] = 0
5966

6067
return r.sum()

gimmemotifs/orthologs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ def load_orthogroups_in_db(db, genomes, orthofinder_result):
431431
for gene in genes.split(", "):
432432
# for each gene we store its gene_name (if present,
433433
# otherwise .) and gene_id. We load them both in the database.
434+
gene = gene.replace("'", "")
434435
gene_name, gene_id = gene.split("|")
435436
if gene_name != ".":
436437
conn.execute(
@@ -449,6 +450,7 @@ def load_orthogroups_in_db(db, genomes, orthofinder_result):
449450

450451
# for each gene we store its gene_name (if present,
451452
# otherwise .) and gene_id. We load them both in the database.
453+
gene = gene.replace("'", "")
452454
gene_name, gene_id = gene.split("|")
453455
if gene_name != ".":
454456
conn.execute(

gimmemotifs/report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ def _current_index(self, subset):
141141
]
142142
return idx_slice
143143

144-
def _translate(self):
144+
def _translate(self, *args, **kwargs):
145145
self._compute_data()
146-
d = super()._translate()
146+
d = super()._translate(*args, **kwargs)
147147
circle_styles = self.circle_styles or []
148148
palette_styles = self.palette_styles or []
149149
col_heading_style = self.col_heading_style or []

0 commit comments

Comments
 (0)