Commit 3108a9c6 authored by fabrice's avatar fabrice
Browse files

Setting position filter mandatory in contactmap section (have to do the same in setup section)

parent 3e7e1ca5
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -72,6 +72,12 @@ class AriaEcContactMap(object):
self.protein, clashlist=fo.clashlist,
outprefix=self.outprefix,
outdir=self.settings.outdir)
else:
# Use only position filter
self.filter(fo.mapdict, fo.filetype, fo.contactlist,
self.protein, clashlist=fo.clashlist,
outprefix=self.outprefix,
outdir=self.settings.outdir, mapfilters="pos")
self.allresmap[fo.filetype] = fo.mapdict
try:
......@@ -84,22 +90,22 @@ class AriaEcContactMap(object):
self.settings.setup.config.get("n_factor"))
plotparams = {k: self.settings.contactmap.config.get(k, None)
for k in ('size_fig', 'plot_ext', 'plot_dpi')}
outdir = self.settings.outdir
if self.settings.contactmap.config.get("save_fig"):
refmap.saveplot(outdir=outdir,
outprefix="_".join((self.outprefix, "pdb")),
**plotparams)
for mapt in self.allresmap.keys():
outdir = self.settings.outdir
prefix = "_".join((self.outprefix, mapt, self.reftype))
if mapt == self.reftype and not \
self.settings.contactmap.args.get("onlyreport", False):
refmap.write_contacts("_".join((self.outprefix, mapt)),
outdir=outdir,
scoremap=self.refmap.get("scoremap",
None))
if self.settings.contactmap.config.get("save_fig"):
refmap.saveplot(outdir=outdir,
outprefix="_".join((self.outprefix, mapt)),
**plotparams)
continue
scoremap = self.allresmap[mapt].get('scoremap', None)
......@@ -107,7 +113,7 @@ class AriaEcContactMap(object):
self.allresmap[mapt].get("scoremap") is not None:
if not self.settings.contactmap.args.get("nofilter"):
# Get filtered contact map/list
# Get top contact map/list
cmpmap = self.allresmap[mapt]["contactmap"].topmap(
self.allresmap[mapt]["scoremap"], nb_c)
cmplist = self.allresmap[mapt]['scoremap'].sortedset(
......
No preview for this file type
No preview for this file type
......@@ -9,6 +9,7 @@ matplotlib.use("Agg", warn=False)
import os
import re
import csv
import logging
import collections
import itertools
......@@ -68,6 +69,12 @@ class Map(pd.DataFrame):
self.sym = sym
self.desc = desc
@staticmethod
def plotflush():
plt.clf()
plt.cla()
plt.close()
def sortedset(self, human_idx=False):
# Remove duplicate in sort_list
n = 1 if human_idx else 0
......@@ -187,6 +194,9 @@ class ProteinMap(Map):
def maplot(self):
# Contact map Plot
if not self._maplot:
# Flush matplot
logger.debug("Build maplot")
self.plotflush()
minticks = tickmin(self, shift=1) # Nb graduations
self._maplot = sns.heatmap(self, square=True, cbar=False,
......@@ -252,6 +262,7 @@ class ProteinMap(Map):
raise NotImplementedError
def compareplot(self, protmap, save_fig=True, alpha=None, **kwargs):
self.plotflush()
# Contact map plot
if getattr(protmap, "shape") and self.shape != protmap.shape:
logging.error("Cant't compare %s map with %s" % (
......@@ -261,7 +272,6 @@ class ProteinMap(Map):
cmplist = protmap.contact_list()
ymax = len(self.sequence) - 1
if protmap.contact_flags:
flags = set(protmap.contact_flags.values())
# Color palette
......@@ -325,35 +335,6 @@ class ProteinMap(Map):
y_true, y_scores)
aver_prec = skm.average_precision_score(y_true, y_scores)
if plotag:
plotpath = os.path.join(plotdir, "%s.roc.%s" % (outprefix,
plot_ext))
plt.figure()
plt.plot(allfpr, alltpr, label='ROC curve (area = %0.2f)' % roc_auc)
plt.plot([0, 1], [0, 1], 'k--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.0])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic %s vs. %s' % (
map1name, map2name))
plt.legend(loc="lower right")
plt.savefig(plotpath)
plotpath = os.path.join(plotdir, "%s.precall.%s" % (outprefix,
plot_ext))
# Precision recall curve
plt.clf()
plt.plot(allrec, allprec, label='Precision-Recall curve')
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.ylim([0.0, 1.0])
plt.xlim([0.0, 1.0])
plt.title('Precision-Recall {1} vs. {2}: AUC={0:0.2f}'.format(
aver_prec, map1name, map2name))
plt.legend(loc="lower left")
plt.savefig(plotpath)
msg = """\
## Report {map1name} vs. {map2name}
##
......@@ -418,6 +399,51 @@ class ProteinMap(Map):
logger.debug("\n" + msg)
reportf.write(msg)
if plotag and scoremap is not None:
csv_roc = os.path.join(plotdir, "%s.roc.csv" % outprefix)
logger.info("Generate roc file (%s)" % csv_roc)
with open(csv_roc, "w") as f:
f.write("TPR,FPR,Treshold\n")
writer = csv.writer(f)
writer.writerows(zip(alltpr, allfpr, rocthresholds))
plotpath = os.path.join(plotdir, "%s.roc.%s" % (outprefix,
plot_ext))
logger.info("Generate roc plot (%s)" % plotpath)
plt.figure()
plt.plot(allfpr, alltpr, label='ROC curve (area = %0.2f)' % roc_auc)
plt.plot([0, 1], [0, 1], 'k--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.0])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic %s vs. %s' % (
map1name, map2name))
plt.legend(loc="lower right")
plt.savefig(plotpath)
csv_precall = os.path.join(plotdir, "%s.roc.csv" % outprefix)
logger.info("Generate precall file (%s)" % csv_precall)
with open(csv_precall, "w") as f:
f.write("Precision,Recall,Treshold\n")
writer = csv.writer(f)
writer.writerows(zip(allprec, allrec, prthresholds))
plotpath = os.path.join(plotdir, "%s.precall.%s" % (outprefix,
plot_ext))
logger.info("Generate precall plot (%s)" % plotpath)
# Precision recall curve
plt.clf()
plt.plot(allrec, allprec, label='Precision-Recall curve')
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.ylim([0.0, 1.0])
plt.xlim([0.0, 1.0])
plt.title('Precision-Recall {1} vs. {2}: AUC={0:0.2f}'.format(
aver_prec, map1name, map2name))
plt.legend(loc="lower left")
plt.savefig(plotpath)
def compare_contactmap(self, cmpmap, contactlist, outprefix,
outdir="", distmap=None, human_idx=True):
# CSV file giving TP/FP contacts
......@@ -1101,6 +1127,8 @@ class MapFilter:
mapfilters = [elm for elm in mapfilters if elm in self.filter_types]
else:
mapfilters = [mapfilters]
if "pos" not in mapfilters:
mapfilters.insert(0, "pos")
logger.info("Filtering %s contact map" % mtype)
for flt in mapfilters:
# /!\ cys unicity filter must be the last filter !
......
No preview for this file type
No preview for this file type
No preview for this file type
# Do not edit this file, pipeline versioning is governed by git tags
__version__=v0.1.4-dev1-1-gf2ac0b3
\ No newline at end of file
__version__=v0.1.8-dev2
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment