diff --git a/ariaec/base.py b/ariaec/base.py index 46748347a79176122da65a5fae5ef5ded53e8e5e..2330b20412fab2df0c073c94de3263795a4b1f22 100644 --- a/ariaec/base.py +++ b/ariaec/base.py @@ -10,13 +10,14 @@ import json import re import ast import sys +import shutil import numpy as np import pkg_resources as pkgr import matplotlib.artist as art from io import StringIO -logger = logging.getLogger() +LOG = logging.getLogger() def titleprint(outfile, progname='', desc=''): @@ -121,11 +122,11 @@ def format_str(string): try: ev_str = ast.literal_eval(string) except ValueError: - logger.error("Don't understand given string %s. Please check " - "format." % string) + LOG.error("Don't understand given string %s. Please check " + "format.", string) return None except SyntaxError: - logger.error("Given string %s is not a valid expression" % string) + LOG.error("Given string %s is not a valid expression", string) return None return ev_str else: @@ -251,15 +252,23 @@ class CustomLogging: :param outdir: path output directory :return: """ - outdir = os.path.join(outdir, "log") if "log" not in outdir else outdir + outdir = os.path.join(outdir, + "log") if "log" not in outdir else outdir if not os.path.exists(os.path.abspath(outdir)): os.makedirs(outdir) + else: + # Trick to avoid overwriting files with w mode after copy2 call + shutil.rmtree(os.path.abspath(outdir)) + os.makedirs(outdir) if outdir and "handlers" in self.config: for hand in self.config["handlers"]: if "filename" in self.config["handlers"][hand]: - self.config["handlers"][hand]["filename"] = \ - os.path.join(outdir, os.path.basename( - self.config["handlers"][hand]["filename"])) + oldpath = self.config["handlers"][hand]["filename"] + newpath = os.path.abspath(os.path.join( + outdir, os.path.basename( + self.config["handlers"][hand]["filename"]))) + self.config["handlers"][hand]["filename"] = newpath + shutil.copy2(oldpath, newpath) logging.config.dictConfig(self.config) def welcome(self): @@ -275,6 +284,11 @@ class CustomLogging: ================================================================================ '''.format(self.msg) print(desc) + for hand in self.config.get("handlers"): + if "filename" in self.config["handlers"][hand]: + with open(self.config["handlers"][hand]["filename"], + 'w') as f: + f.write(desc) class Capturing(list): @@ -293,7 +307,7 @@ class Capturing(list): """ :return: """ - logger.error("Error during capture [%s]" % str(args)) + LOG.error("Error during capture [%s]", str(args)) self.extend("\n".join(self._stringio.getvalue().splitlines())) sys.stdout = self._stdout @@ -301,6 +315,6 @@ class Capturing(list): if __name__ == "__main__": # Test Logger CustomLogging().set_outdir("../examples/out") - logger = logging.getLogger("TEST") - logger.info(dir(logger)) - logger.info("Log test") + LOG = logging.getLogger("TEST") + LOG.info(dir(LOG)) + LOG.info("Log test") diff --git a/ariaec/base.pyc b/ariaec/base.pyc index 7bf708fc2a352ffa32022e43a46d1585927ecd8c..d7e6811a8be63e072cc464796d4e9212f524b606 100644 Binary files a/ariaec/base.pyc and b/ariaec/base.pyc differ diff --git a/ariaec/commands.py b/ariaec/commands.py index bee32d6e00022175300a714cc90ddb7e972f5542..ad37ce5fdb528f7a3d5f265e0e79a177e3e674aa 100644 --- a/ariaec/commands.py +++ b/ariaec/commands.py @@ -12,7 +12,8 @@ from .maplot import AriaEcContactMap from .econverter import AriaEcBbConverter from .setup import AriaEcSetup -logger = logging.getLogger(__name__) + +LOG = logging.getLogger(__name__) def check_file(prospective_file): @@ -62,7 +63,7 @@ class AriaEcCommand: parser = self._create_argparser() # parse args self.args = parser.parse_args() - # Update logger with outdir + # Update LOG with outdir self._update_logger(custom_logging) def _update_logger(self, log): @@ -70,9 +71,9 @@ class AriaEcCommand: if not self.args.nolog: # Don't generate log files # TODO: get handler list from json file or customlogging object - logger.removeHandler("info_file_handler") - logger.removeHandler("error_file_handler") - logger.removeHandler("debug_file_handler") + LOG.removeHandler("info_file_handler") + LOG.removeHandler("error_file_handler") + LOG.removeHandler("debug_file_handler") log.set_outdir(self.args.output_directory) log.update_msg(self.args.command) log.welcome() @@ -201,24 +202,24 @@ class AriaEcCommand: return parser def create_settings(self): - logger.debug("Create AriaEcSettings") + LOG.debug("Create AriaEcSettings") settings = AriaEcSettings(self.args.command) - logger.info("Loading default config file") + LOG.info("Loading default config file") settings.load_config(self.default_confile, pkg=True) if self.args.conf_file: - logger.info("Updating settings with conf file") + LOG.info("Updating settings with conf file") settings.load_config(self.args.conf_file) # Update settings associated to command section - logger.info("Updating %s settings with args" % self.args.command) + LOG.info("Updating %s settings with args", self.args.command) getattr(settings, self.args.command).args.update(self.args.__dict__) if self.args.output_directory: - logger.info("Updating output directory") + LOG.info("Updating output directory") settings.infra = self.args.output_directory return settings def run(self): # call method relative to args.command - logger.info("Run %s command" % self.args.command) + LOG.info("Run %s command", self.args.command) getattr(self, self.args.command)() def setup(self): @@ -238,5 +239,5 @@ class AriaEcCommand: if __name__ == "__main__": # Test AriaEcCommand object logging.basicConfig(level=logging.DEBUG) - logger = logging.getLogger("IO") + LOG = logging.getLogger("IO") argparser = AriaEcCommand() diff --git a/ariaec/conf/logging.json b/ariaec/conf/logging.json index 1b1cd5dab4eb5c3ec0148ca5a9e86423edee17ae..f4eea3defb2521b08188573539665aad74dece6d 100644 --- a/ariaec/conf/logging.json +++ b/ariaec/conf/logging.json @@ -3,10 +3,10 @@ "disable_existing_loggers": false, "formatters": { "simple": { - "format": "%(levelname)-8s --- %(message)s" + "format": "%(levelname)-8s %(message)s" }, "detail": { - "format": "[%(asctime)s] --- %(levelname)8s --- %(message)s (%(filename)s:%(lineno)s)", + "format": "[%(asctime)s] --- %(levelname)-8s --- %(message)s (%(filename)s:%(lineno)s)", "datefmt": "%m/%d/%Y %I:%M:%S %p" }, "colored": { @@ -18,7 +18,7 @@ "handlers": { "console": { "class": "logging.StreamHandler", - "level": "INFO", + "level": "DEBUG", "formatter": "colored", "stream": "ext://sys.stdout" }, @@ -26,19 +26,18 @@ "info_file_handler": { "class": "logging.handlers.RotatingFileHandler", "level": "INFO", - "formatter": "detail", - "filename": "/tmp/aria_ec.log", - "maxBytes": 10485760, - "backupCount": 20, + "formatter": "simple", + "filename": "/tmp/ariaec.log", + "mode": "a", "encoding": "utf8" }, "debug_file_handler": { "class": "logging.handlers.RotatingFileHandler", "level": "DEBUG", - "formatter": "simple", - "filename": "/tmp/debug.log", - "mode": "w", + "formatter": "detail", + "filename": "/tmp/ariaec.debug", + "mode": "a", "encoding": "utf8" }, @@ -46,15 +45,14 @@ "class": "logging.handlers.RotatingFileHandler", "level": "ERROR", "formatter": "detail", - "filename": "/tmp/errors.log", - "maxBytes": 10485760, - "backupCount": 20, + "filename": "/tmp/ariaec.error", + "mode": "a", "encoding": "utf8" } }, "root": { - "level": "DEBUG", + "level": "INFO", "handlers": ["console", "info_file_handler", "error_file_handler", "debug_file_handler"] } diff --git a/ariaec/econverter.py b/ariaec/econverter.py index 2ff6a606effff8bff1b4ef7decbb6bfc8e2a6e79..42d075d6d7b2c501848dbb2f23e7ab30abd15864 100644 --- a/ariaec/econverter.py +++ b/ariaec/econverter.py @@ -25,7 +25,7 @@ from aria.AriaXML import AriaXMLPickler from aria.conversion import Converter, SequenceList, MoleculeSettings -logger = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) class AriaEcBbConverter(object): @@ -38,10 +38,10 @@ class AriaEcBbConverter(object): def run(self): # Check input - logger.debug("Settings:\n" + json.dumps(self.settings.setup.config, - indent=4)) - logger.debug("Args:\n" + json.dumps(self.settings.setup.args, - indent=4)) + LOG.debug("Settings:\n" + json.dumps(self.settings.setup.config, + indent=4)) + LOG.debug("Args:\n" + json.dumps(self.settings.setup.args, + indent=4)) # TODO: redirect print output to logging ? (low priority) # ----------------------------- Input -------------------------------- # self.outprefix = get_filename(self.settings.bbconv.args.get("seq", @@ -128,7 +128,7 @@ class AriaXMLConverter(Converter, object): sequence.parse(self._mol_set['input'], self._mol_set['format'], self._mol_set['naming_convention']) - # logger.info("\n" + "".join(output)) + # LOG.info("\n" + "".join(output)) factory = self.create_factory() @@ -232,7 +232,7 @@ assign (resid {res1} and name o) (resid {res2} and name hn) 1.8 {dminus} {dplus distmap = hbmap.get("distmap") if n_hb: contacts = contacts[:n_hb] - logger.debug(contacts) + LOG.debug(contacts) donors = [] acces = [] for contact in contacts: @@ -265,15 +265,15 @@ assign (resid {res1} and name o) (resid {res2} and name hn) 1.8 {dminus} {dplus raise NotImplementedError else: if hb_type != "main": - logger.error("Wrong longrange hbond type given. Default " + LOG.error("Wrong longrange hbond type given. Default " "option used (main)") # First residue = donor for a backbone hydrogen bond (N-H...O=C) outfile.write('''\ assign (resid {res1} and name o) (resid {res2} and name n) 2.8 {dminus} {dplus} assign (resid {res1} and name o) (resid {res2} and name hn) 1.8 {dminus} {dplus} '''.format(res1=res1, res2=res2, dminus=dminus, dplus=dplus, dist=dist)) - logger.info("Writing %d hbonds from hbmap in %s" % (len(donors), - outfile.name)) + LOG.info("Writing %d hbonds from hbmap in %s", len(donors), + outfile.name) def write_hb_tbl(self, protein, outfile, hbmap=None, dminus=0.0, dplus=0.5, n_hb=None, lr_type='main'): @@ -428,7 +428,7 @@ class AriaEcXMLConverter(AriaXMLConverter): elif prod_type == "all": return list(itertools.product(atms1, atms2)) else: - logger.error("Wrong pair_list option. Pair_list set to min") + LOG.error("Wrong pair_list option. Pair_list set to min") return min_atms(res1, res2, list(itertools.product(atms1, atms2))) def targetdistmap(self, distype, sequence, distfile=None, groupby=None): @@ -514,7 +514,7 @@ class AriaEcXMLConverter(AriaXMLConverter): nb_c) # Initial contact list start at 0 # pair_list = [(int(x[0]) + 1, int(x[1]) + 1) for x in pair_list] - logger.info("Selecting %d contacts:\n%s" % (nb_c, pair_list)) + LOG.info("Selecting %d contacts:\n%s", nb_c, pair_list) if self.settings.setup.config['evfold_weight'] and scoremap is not None: weight_list = list(float(10.0 / (x + 1)) for x, v in enumerate( @@ -544,7 +544,7 @@ class AriaEcXMLConverter(AriaXMLConverter): contrib_id = 0 for contactidx, contact in enumerate(pair_list): - logger.debug("Contact %s" % str(contact)) + LOG.debug("Contact %s" % str(contact)) # Add neighbors if neigh_flag resx_idx = range(min_ind(contact[0] - 1), @@ -616,10 +616,10 @@ class AriaEcXMLConverter(AriaXMLConverter): # In case missing distance values target_dist = self.settings.setup.config[ "restraint_distance"] - logger.warning( + LOG.warning( "Target distance is missing for restraint " - "%s-%s (%s). Using default distance (%s)" - % (idx_x + 1, idx_y + 1, atm_pair, target_dist)) + "%s-%s (%s). Using default distance (%s)", + idx_x + 1, idx_y + 1, atm_pair, target_dist) rest_id += 1 contrib_id = 1 @@ -662,7 +662,7 @@ class AriaEcXMLConverter(AriaXMLConverter): } xml_file = self.settings.infra["xml"] + "/" + "_".join(( self.outprefix, listname)) + ".xml" - logger.info("Write %d xml distance restraints in %s" % (nb_c, xml_file)) + LOG.info("Write %d xml distance restraints in %s", nb_c, xml_file) self.write_dist_xml(restraint_dict, xml_file) return xml_file, pair_list @@ -670,7 +670,7 @@ class AriaEcXMLConverter(AriaXMLConverter): out = ([], []) for maptype in maplist: - logger.info("Writing %s ARIA XML distance restraints" % maptype) + LOG.info("Writing %s ARIA XML distance restraints", maptype) outfile, pairlist = self.write_map_restraint( maplist[maptype]['contactmap'], maplist[maptype]["nb_c"], targetmap, listname=maptype, @@ -694,16 +694,16 @@ class AriaEcXMLConverter(AriaXMLConverter): "_hbond.tbl") ssdist_file = os.path.join(self.settings.infra["tbl"], self.outprefix + "_ssdist.tbl") - logger.info(" Dihedral restraints (%s)" % dihed_file) + LOG.info(" Dihedral restraints (%s)", dihed_file) self.write_dihedral_tbl(protein.sec_struct.ss_matrix, dihed_file) - logger.info(" Helix bond restraints (%s)" % hb_file) + LOG.info(" Helix bond restraints (%s)", hb_file) self.write_hb_tbl(protein, hb_file, hbmap=hbmap, n_hb=n_hb, lr_type=self.settings.setup.config['longrange_hbtype'], dminus=self.settings.setup.config['hb_dminus'], dplus=self.settings.setup.config['hb_dplus']) - logger.info(" Secondary structure restraints (%s)" % - ssdist_file) + LOG.info(" Secondary structure restraints (%s)", + ssdist_file) self.write_ssdist_tbl(protein.sec_struct.ss_matrix, protein.sec_struct.ssdist, ssdist_file) @@ -718,7 +718,7 @@ class AriaEcXMLConverter(AriaXMLConverter): except Exception as msg: - logger.error("Error writing xml seq file : %s" % msg) + LOG.error("Error writing xml seq file : %s", msg) return self._mol_set['output'] @@ -733,7 +733,7 @@ class AriaEcXMLConverter(AriaXMLConverter): :param desc: :return: """ - logger.info("Loading aria template file %s" % aria_template) + LOG.info("Loading aria template file %s", aria_template) templatepath = os.path.abspath(aria_template) ariaproj_template = Template(filename=templatepath, @@ -741,7 +741,7 @@ class AriaEcXMLConverter(AriaXMLConverter): try: t = open(templatepath, 'r') - except Exception, msg: + except Exception as msg: sys.exit("""Can't open "%s" file. %s""" % (templatepath, msg)) aria_project_template = t.read() @@ -761,13 +761,13 @@ class AriaEcXMLConverter(AriaXMLConverter): temp_root = os.path.abspath(aria_project_dict['temp_root']) if not os.path.exists(work_dir): - logger.info("Working dir %s doesn't exist." % work_dir) - logger.info("Create new directory %s" % work_dir) + LOG.info("Working dir %s doesn't exist.", work_dir) + LOG.info("Create new directory %s", work_dir) os.makedirs(work_dir) if not os.path.exists(temp_root): - logger.info("Temp directory %s doesn't exist." % temp_root) - logger.info("Create new directory %s" % temp_root) + LOG.info("Temp directory %s doesn't exist.", temp_root) + LOG.info("Create new directory %s", temp_root) os.makedirs(temp_root) aria_project_dict['working_directory'] = work_dir @@ -834,5 +834,5 @@ class AriaEcXMLConverter(AriaXMLConverter): proj_file = "%s/ariaproject.xml" % work_dir with open(proj_file, 'w') as proj_xml: - logger.info("Writing ARIA project file (%s)" % proj_file) + LOG.info("Writing ARIA project file (%s)", proj_file) proj_xml.write(ariaproj_template.render(**aria_project_dict)) diff --git a/ariaec/ecsettings.py b/ariaec/ecsettings.py index bebf738e19d8cfe0693e494b1b9b53a747435607..3ecb943f78b0939aa3dbb52e8d25e21328d43af3 100644 --- a/ariaec/ecsettings.py +++ b/ariaec/ecsettings.py @@ -12,7 +12,7 @@ import pkg_resources as pkgr from .base import format_dict -logger = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) class Setting: @@ -21,6 +21,10 @@ class Setting: self.config = collections.defaultdict() self.args = collections.defaultdict() + def __repr__(self): + return "Setting object\n config: %s\n args : %s" % (self.config, + self.args) + class Settings(object): @@ -40,7 +44,7 @@ class Settings(object): if os.path.exists(configpath): self.configfile = configpath elif not pkg: - logger.error("Configuration file not found (%s)" % configpath) + LOG.error("Configuration file not found (%s)", configpath) return None config = SafeConfigParser(allow_no_value=True) if pkg: @@ -48,20 +52,20 @@ class Settings(object): config.readfp(conf) else: config.read(configpath) - logger.debug(config) + LOG.debug(config) for section in config.sections(): if hasattr(self, section): tmp = format_dict(dict(config.items(section))) getattr(self, section).config.update(tmp) - logger.debug("%s config updated" % section) - logger.debug("%s.%s : %s" % (self.__class__.__name__, section, - getattr(self, section))) + LOG.debug("%s config updated", section) + LOG.debug("%s.%s : %s", self.__class__.__name__, section, + getattr(self, section)) else: - logger.warning("Unknow config section %s" % section) + LOG.warning("Unknow config section %s", section) def write_config(self, filename): # Ecrit les config de toutes les sections dans un autre fichier - logger.info("Writing .ini file (%s)" % filename) + LOG.info("Writing .ini file (%s)", filename) config = SafeConfigParser(allow_no_value=True) iniout = open(filename, mode="w") for section in self._sections: @@ -72,6 +76,9 @@ class Settings(object): str(getattr(self, section).config.get(opt))) config.write(iniout) + def __repr__(self): + return "<Settings object>\n sections: %s" % self._sections + class AriaEcSettings(Settings): @@ -97,7 +104,7 @@ class AriaEcSettings(Settings): def _up_infra(self): for d in self.infra: - logger.debug("set %s dir: %s" % (d, os.path.join(self.outdir, d))) + LOG.debug("set %s dir: %s", d, os.path.join(self.outdir, d)) self._infra[d] = os.path.join(self.outdir, d) @property @@ -138,8 +145,8 @@ class AriaEcSettings(Settings): if os.path.exists(pkgr.resource_filename(__name__, templatepath)): self._template = pkgr.resource_filename(__name__, templatepath) else: - logger.error("Template version for aria project (%s) is not " - "supported" % self.main.config.get("ariaproject_template")) + LOG.error("Template version for aria project (%s) is not " + "supported", self.main.config.get("ariaproject_template")) self._template = pkgr.resource_filename(__name__, self.ARIAPROJ_TEMPLATE) return self._template @@ -167,9 +174,9 @@ class AriaEcSettings(Settings): return self._scsc_min def make_infra(self): - logger.info("Making output directories") + LOG.info("Making output directories") for direct in self.infra: - logger.debug("Create %s directory" % self.infra[direct]) + LOG.debug("Create %s directory", self.infra[direct]) if not os.path.exists(self.infra[direct]): os.makedirs(os.path.abspath(self.infra[direct])) diff --git a/ariaec/ecsettings.pyc b/ariaec/ecsettings.pyc index e9698ea485d18bb65619b3c4df6e8879e8beef31..7de756ad69f384c7d04df4932dde27ffa396fab4 100644 Binary files a/ariaec/ecsettings.pyc and b/ariaec/ecsettings.pyc differ diff --git a/ariaec/maplot.py b/ariaec/maplot.py index a5e0e61f1f690205cfd35bbe4bdc6dcdc5acdd5f..127f8d6aa7dfa727c2f8dab6365c6945f59f83fd 100644 --- a/ariaec/maplot.py +++ b/ariaec/maplot.py @@ -11,7 +11,7 @@ from .reader import ProtFileListReader from .protmap import MapFilter from .protein import Protein -logger = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) class AriaEcContactMap(object): @@ -30,10 +30,10 @@ class AriaEcContactMap(object): def run(self): # Check input - logger.debug("Settings:\n" + json.dumps(self.settings.contactmap.config, - indent=4)) - logger.debug("Args:\n" + json.dumps(self.settings.contactmap.args, - indent=4)) + LOG.debug("Settings:\n" + json.dumps(self.settings.contactmap.config, + indent=4)) + LOG.debug("Args:\n" + json.dumps(self.settings.contactmap.args, + indent=4)) if not self.settings.contactmap.args.get("onlyreport", False): self.settings.make_infra() # ----------------------------- Input -------------------------------- # @@ -65,7 +65,7 @@ class AriaEcContactMap(object): # TODO: filter pour toutes les map de mapdict !! (fonction remove # s'applique sur l'humanidx contenant les residus) if idx == 0: - logger.info("%s map set as reference" % fo.filetype.capitalize()) + LOG.info("%s map set as reference", fo.filetype.capitalize()) self.refmap = fo.mapdict self.reftype = fo.filetype self.refname = fo.filename if type(self.outprefix) != list \ @@ -89,7 +89,7 @@ class AriaEcContactMap(object): try: refmap = self.refmap["contactmap"] except TypeError: - logger.error("First contact map should be a valid file") + LOG.error("First contact map should be a valid file") sys.exit(1) # nb_c = int(len(self.protein.aa_sequence.sequence) * @@ -115,8 +115,8 @@ class AriaEcContactMap(object): for mapname, mapt in self.allresmap.keys(): if mapt != self.reftype: # TODO: DON'T WORK !!!! - logger.info("Merging %s with %s map" % ( - mergetype, mapt)) + LOG.info("Merging %s with %s map", + mergetype, mapt) up_map = self.allresmap[mapt]["contactmap"] up_map[:] = up_map[:] + mergecontactmap[:] mergekey = "%s_%s" % (mapt, mergetype) @@ -150,8 +150,8 @@ class AriaEcContactMap(object): cmplist = self.allresmap[(mapname, mapt, mapath)][ 'contactmap'].contact_list(human_idx=True) # else: - # logger.warning("%s map doesn't have any score related. Can't " - # "define top list related to this map" % mapt) + # LOG.warning("%s map doesn't have any score related. Can't " + # "define top list related to this map", mapt) # continue # TODO: only one function for output files @@ -183,5 +183,5 @@ class AriaEcContactMap(object): **plotparams) # Contingency table # print(cmpmap.to_series()) - # logger.info(pd.crosstab(cmpmap.values, refmap.values, + # LOG.info(pd.crosstab(cmpmap.values, refmap.values, # rownames=[mapt], colnames=[self.reftype])) diff --git a/ariaec/protein.py b/ariaec/protein.py index e060ae1cf9c1abb8a63f66abb4803811642c2c76..feb8a87bee2ce17a8ec88f11c37cb82a2b8bd016 100644 --- a/ariaec/protein.py +++ b/ariaec/protein.py @@ -17,7 +17,7 @@ from .base import (reg_load, ppdict) # TODO: interface skbio ?? -logger = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) class SsList: @@ -77,17 +77,16 @@ class SsList: :return: """ self.check_filetype(filename) - logger.info("Reading secondary structure file %s [%s]" % ( - filename, - self.filetype)) + LOG.info("Reading secondary structure file %s [%s]", + filename, self.filetype) # TODO: better read with getattr if self.filetype == "indextableplus": self.read_indextableplus(filename) else: self.read_psipred(filename) - logger.debug("Secondary structure matrix:\n%s\n" - "Secondary structure dict:\n%s" % (self.ss_matrix, - self.ssdict)) + LOG.debug("Secondary structure matrix:\n%s\n" + "Secondary structure dict:\n%s", self.ss_matrix, + self.ssdict) if sequence: self.seq_sublist(sequence) @@ -175,7 +174,7 @@ class SsList: :param filename: :return: """ - logger.info("Reading distance file {0}".format(filename)) + LOG.info("Reading distance file {0}".format(filename)) c = 0 atom_list = [] for line in infile: @@ -208,14 +207,14 @@ class SsList: """ filename = os.path.abspath(ssdistpath) if ssdistpath else None - logger.info("Loading ss dist file") + LOG.info("Loading ss dist file") try: with open(filename) as f: self._read_ssdist(f, filename=filename) except Exception as message: - logger.error("%s" % message) - logger.error("Can't load given ss dist file...") - logger.error("Loading default ss dist file") + LOG.error("%s", message) + LOG.error("Can't load given ss dist file...") + LOG.error("Loading default ss dist file") with pkgr.resource_stream(__name__, self.settings.SS_DIST) as f: self._read_ssdist(f, filename=self.settings.SS_DIST) @@ -238,8 +237,8 @@ class SsList: sys.exit('Missing residues in indextableplus file') self.ss_matrix = self.ss_matrix[imin:imax] - logger.debug("Secondary structure matrix relative to given " - "sequence:\n%s" % self.ss_matrix) + LOG.debug("Secondary structure matrix relative to given " + "sequence:\n%s", self.ss_matrix) # TODO: read_dssp @@ -365,7 +364,7 @@ class AminoAcidSequence(SequenceList.SequenceList, object): # Add dict topo[resname][regid].append(match.groupdict()) break - logger.debug("Topology used:\n%s" % ppdict(topo)) + LOG.debug("Topology used:\n%s", ppdict(topo)) return topo def read(self, filename): @@ -378,11 +377,11 @@ class AminoAcidSequence(SequenceList.SequenceList, object): # TODO: capturing has some troubles with unicode ... # with Capturing() as output: self.ReadFasta(text_type(filename)) - # logger.info(''.join(output)) + # LOG.info(''.join(output)) self.sequence = "".join((AmnAcd.AminoAcid(str(_))[0] for _ in self.aalist)) - logger.info("Amino acid sequence:\t%s" % self.sequence) + LOG.info("Amino acid sequence:\t%s", self.sequence) class Protein: @@ -441,7 +440,7 @@ class Protein: if self.sec_struct.ss_matrix: self.sec_struct.seq_sublist(self.aa_sequence.sequence) if ssidx: - logger.info("Using secondary structure index for amino acid " + LOG.info("Using secondary structure index for amino acid " "sequence") self.index = self.sync_index(self.aa_sequence.humanidx, self.sec_struct.index) @@ -462,15 +461,15 @@ class Protein: # Read secondary distance matrix self.sec_struct.read_ssdist(ssdist_filename) else: - logger.error("No secondary structure distance file found. Please " + LOG.error("No secondary structure distance file found. Please " "check configuration file") if self.aa_sequence.sequence: # Synchronise sec structure sequence with aa sequence - logger.info("Align secondary structure sequence with protein " + LOG.info("Align secondary structure sequence with protein " "sequence") self.sec_struct.seq_sublist(self.aa_sequence.sequence) if ssidx: - logger.info("Using secondary structure index for amino acid " + LOG.info("Using secondary structure index for amino acid " "sequence") self.index = self.sync_index(self.aa_sequence.humanidx, self.sec_struct.index) @@ -484,7 +483,7 @@ class Protein: # TODO: same as above, trouble with unicode calls inside capturing # with Capturing() as output: self.aa_sequence.WriteSeq(text_type(outfile)) - # logger.info(''.join(output)) + # LOG.info(''.join(output)) self.seqfile_path = outfile @@ -493,4 +492,4 @@ if __name__ == "__main__": settings = AriaEcSettings("setup") prot = Protein(settings) prot.set_aa_sequence("../examples/data/BPT1_BOVIN.fa") - logger.info(prot.aa_sequence) + LOG.info(prot.aa_sequence) diff --git a/ariaec/protmap.py b/ariaec/protmap.py index 266156bf3d6baf09d044bb54b22daade6cce8076..d99940d83629e98e23fb69ead7b0189950fb1c0d 100644 --- a/ariaec/protmap.py +++ b/ariaec/protmap.py @@ -27,7 +27,7 @@ from .base import (tickmin, tickrot, titleprint) import sklearn.metrics as skm -logger = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) # TODO: check dataframe symmetry or always use unstack @@ -96,8 +96,8 @@ class Map(pd.DataFrame): if value: return value else: - logger.error("Map type should be in list %s" % - self.mtype_choices.keys()) + LOG.error("Map type should be in list %s", + self.mtype_choices.keys()) return None def reduce(self): @@ -136,7 +136,7 @@ class Map(pd.DataFrame): def topmap(self, scoremap, nb_topcontact): if self.dtype != bool: - logger.info("Error when retrieving top contact map. The type of " + LOG.info("Error when retrieving top contact map. The type of " "the given map is not a contact type!") return self self[:] = False @@ -147,7 +147,7 @@ class Map(pd.DataFrame): self.iat[(contact[0], contact[1])] = True return self else: - logger.error("Given scoremap has not the same dimension !") + LOG.error("Given scoremap has not the same dimension !") return None def subfill(self, pairdict, level=0): @@ -201,7 +201,7 @@ class ProteinMap(Map): # Contact map Plot if not self._maplot: # Flush matplot - logger.debug("Build maplot") + LOG.debug("Build maplot") minticks = tickmin(self, shift=1) # Nb graduations self._maplot = sns.heatmap(self, square=True, cbar=False, @@ -217,7 +217,7 @@ class ProteinMap(Map): plot_ext="pdf", plot_dpi=200): plotpath = os.path.join(outdir, "%s.contactmap.%s" % ( outprefix, plot_ext)) - logger.info("Generate contact map plot (%s)" % plotpath) + LOG.info("Generate contact map plot (%s)", plotpath) f, ax = plt.subplots(figsize=(12, 9)) tickrot(self.maplot.axes, self.maplot.figure, rotype='horizontal') @@ -296,13 +296,13 @@ class ProteinMap(Map): linewidths=0.1, alpha=alpha, marker=mark) else: - logger.info("Contact list: %s" % cmplist) + LOG.info("Contact list: %s", cmplist) xind = [x - .5 for x in zip(*cmplist)[0] + zip(*cmplist)[1]] yind = [ymax - y + 1.5 for y in zip(*cmplist)[1] + zip(*cmplist)[0]] - logger.debug("Xind: %s" % xind) - logger.debug("Yind: %s" % yind) + LOG.debug("Xind: %s", xind) + LOG.debug("Yind: %s", yind) color = "red" # width = [0.3 for _ in xind] # for x, y, h in zip(xind, yind, width): @@ -318,7 +318,7 @@ class ProteinMap(Map): filename = ".".join((outprefix, "mapreport")) if outprefix else \ "mapreport" reportpath = "%s/%s" % (outdir, filename) - logger.info("Generate map report file (%s)" % reportpath) + LOG.info("Generate map report file (%s)", reportpath) with open(reportpath, 'w') as reportf: y_true = list(self.values.astype(int).flat) y_pred = list(cmpmap.values.astype(int).flat) @@ -418,12 +418,12 @@ class ProteinMap(Map): roc_auc=roc_auc, allprec=allprec, allrec=allrec, prthres=prthresholds, alltpr=alltpr, allfpr=allfpr, rocthres=rocthresholds) - logger.debug("\n" + msg) + LOG.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) + LOG.info("Generate roc file (%s)", csv_roc) with open(csv_roc, "w") as f: f.write("TPR,FPR,Treshold\n") writer = csv.writer(f) @@ -431,7 +431,7 @@ class ProteinMap(Map): plotpath = os.path.join(plotdir, "%s.roc.%s" % (outprefix, plot_ext)) - logger.info("Generate roc plot (%s)" % plotpath) + LOG.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--') @@ -445,7 +445,7 @@ class ProteinMap(Map): plt.savefig(plotpath) csv_precall = os.path.join(plotdir, "%s.roc.csv" % outprefix) - logger.info("Generate precall file (%s)" % csv_precall) + LOG.info("Generate precall file (%s)", csv_precall) with open(csv_precall, "w") as f: f.write("Precision,Recall,Treshold\n") writer = csv.writer(f) @@ -453,7 +453,7 @@ class ProteinMap(Map): plotpath = os.path.join(plotdir, "%s.precall.%s" % (outprefix, plot_ext)) - logger.info("Generate precall plot (%s)" % plotpath) + LOG.info("Generate precall plot (%s)", plotpath) # Precision recall curve plt.clf() plt.plot(allrec, allprec, label='Precision-Recall curve') @@ -470,7 +470,7 @@ class ProteinMap(Map): outdir="", distmap=None, human_idx=True): # CSV file giving TP/FP contacts outpath = "%s/%s.contactcmp.csv" % (outdir, outprefix) - logger.info("Generate stat file (%s)" % outpath) + LOG.info("Generate stat file (%s)", outpath) with open(outpath, 'w') as outfile: offset = 1 if human_idx else 0 extra_header = "" if distmap is None else ",dmin" @@ -500,7 +500,7 @@ class ProteinMap(Map): def write_contacts(self, filename, outdir="", human_idx=True, scoremap=None): filepath = "%s/%s.contact.txt" % (outdir, filename) - logger.info("Generate contact file (%s)" % filepath) + LOG.info("Generate contact file (%s)", filepath) with open(filepath, 'w') as outfile: offset = 1 if human_idx else 0 # contacts = [sorted(contact) for contact in self.contactset()] @@ -557,7 +557,7 @@ class ResAtmMap(ProteinMap): def create_index(self, sequence, seq_pos=True, seqidx=None, idxnames=None, colnames=None): - logger.info("Indexing res - res dataframe") + LOG.info("Indexing res - res dataframe") # Atom table for residues (keys are in 3L code) seqidx = seqidx if seqidx and len(seqidx) == len(sequence) else None iupac_aa = ConversionTable.ConversionTable().table['AMINO_ACID'][ @@ -584,8 +584,8 @@ class ResAtmMap(ProteinMap): atm_list = [atm for aa in seq for atm in filter(self.heavy_reg.match, iupac_aa[aa].keys())] if len(atm_list) != len(res_list): - logger.error("Index lists aren't the same size\n%s\n%s" % ( - res_list, atm_list)) + LOG.error("Index lists aren't the same size\n%s\n%s", + res_list, atm_list) idxnames = idxnames if idxnames and len(idxnames) == 2 else [ "residuex", "atomx"] @@ -596,7 +596,7 @@ class ResAtmMap(ProteinMap): columns = pd.MultiIndex.from_tuples(list(zip(*[res_list, atm_list])), names=colnames) - logger.debug("Index:\n%s" % index) + LOG.debug("Index:\n%s", index) return index, columns def create_heatmap(self): @@ -632,8 +632,8 @@ class ResAtmMap(ProteinMap): # If self is already a contact map return None # TODO: issue with sc_sc treshold !!!!! - logger.info("Generate contact map using contact definition %s" % - contactdef) + LOG.info("Generate contact map using contact definition %s", + contactdef) # Initialize contact map to a boolean matrix filled with False contact_map = ResAtmMap(sequence=self.sequence, mtype="contact", desc=self.desc, sym=self.sym, path=self.path) @@ -644,7 +644,7 @@ class ResAtmMap(ProteinMap): contact_map[:] = self.applymap(lambda x: x < contactdef) elif sum(x is not None for x in contactdef.values()) == 1 and def_cutoff: - logger.info("Using default cutoff") + LOG.info("Using default cutoff") contact_map[:] = self.applymap(lambda x: x < contactdef.get("default_cutoff")) elif sum(x is not None for x in contactdef.values()) > 1: @@ -659,11 +659,11 @@ class ResAtmMap(ProteinMap): if contactdef[pair] > def_cutoff: treshold = contactdef[pair] else: - logger.warning("Treshold for %s ignored (lower than " - "the default cutoff)" % str(pair)) - logger.info( - "Filtering values in matrix related to %s (%s)" % - (str(pair), str(treshold) if treshold else def_cutoff)) + LOG.warning("Treshold for %s ignored (lower than " + "the default cutoff)", str(pair)) + LOG.info( + "Filtering values in matrix related to %s (%s)", + str(pair), str(treshold) if treshold else def_cutoff) if pair in (("SC", "SC"), ("sc", "sc")): # Use scsc_min to apply treshold updateonly for selected atom # sidechain @@ -683,11 +683,11 @@ class ResAtmMap(ProteinMap): mask = ([any(tup) for tup in zip(*idx_list)], [any(tup) for tup in zip(*col_list)]) elif pair not in atms_list: - logger.error("Pair %s doesn't exist ..." % str(pair)) + LOG.error("Pair %s doesn't exist ...", str(pair)) # Already applied a treshold for this pair continue else: - logger.debug("Apply treshold for %s" % str(pair)) + LOG.debug("Apply treshold for %s", str(pair)) atms_list.discard(pair) # Selecting rows for each atom mask = (self.index.get_level_values(1) == pair[0], @@ -695,9 +695,9 @@ class ResAtmMap(ProteinMap): tmp = self.loc[mask].apply(lambda x: x < float(treshold)) contact_map.update(tmp) else: - logger.error("Missing values in contact definition section. Add " + LOG.error("Missing values in contact definition section. Add " "at least a default_cutoff value.") - logger.debug("Contact map\n%s" % (contact_map.head())) + LOG.debug("Contact map\n%s", contact_map.head()) return contact_map @@ -905,12 +905,12 @@ class MapFilter: def nd_filter(self, mapdict): # TODO: build ROC curve with number of top contacts as the parameter - logger.info("...Network deconvolution filter (alpha=%.2f, beta=%.2f)" % - (self.settings["nd_beta"], self.settings["nd_alpha"])) + LOG.info("...Network deconvolution filter (alpha=%.2f, beta=%.2f)", + self.settings["nd_beta"], self.settings["nd_alpha"]) scoremap = mapdict["scoremap"] - logger.info(net_deconv(mapdict["scoremap"].as_matrix(), - beta=self.settings["nd_beta"], - alpha=self.settings["nd_alpha"])) + LOG.info(net_deconv(mapdict["scoremap"].as_matrix(), + beta=self.settings["nd_beta"], + alpha=self.settings["nd_alpha"])) # TODO: MAJ score map avec matrice obtenue !!! # !!!! Verifier que scoremap est bien maj et UTILISEE !! return scoremap @@ -924,7 +924,7 @@ class MapFilter: """ # Liste les contacts proches clash_list = kwargs.get("clash_list") - logger.info("...Position filter") + LOG.info("...Position filter") close_list = [] contact_list = mapdict["contactmap"].contact_list() @@ -938,7 +938,7 @@ class MapFilter: def cons_filter(self, mapdict, **kwargs): # Liste les contacts aves des residus fortement conserves - logger.info("...Conservation filter") + LOG.info("...Conservation filter") sec_struct = kwargs.get("sec_struct") clash_list = kwargs.get("clash_list") cons_pair = [] @@ -946,7 +946,7 @@ class MapFilter: contact_list = mapdict["contactmap"].contact_list() if sec_struct.filetype != "indextableplus": - logger.warning("Conservation filter only works with indextableplus " + LOG.warning("Conservation filter only works with indextableplus " "files !") return {'clash': None, 'desc': None} @@ -962,7 +962,7 @@ class MapFilter: # If this clash already exist continue cons_pair.append(contact) - logger.debug("Highly conserverd residue list: %s" % cons_res) + LOG.debug("Highly conserverd residue list: %s", cons_res) return {'clash': cons_pair, 'desc': None} @staticmethod @@ -970,7 +970,7 @@ class MapFilter: # Si scoremap existe, selectionner les contacts cys-cys qui ont les # meilleurs scores, fournit une liste des contacts disulfures qui # possedent des scores plus faibles - logger.info("...Disulfure bridge unicity filter") + LOG.info("...Disulfure bridge unicity filter") clash_list = kwargs.get("clash_list") unidisbridge_list = [] # Liste les ponts disulfures uniques clashdisbridge_list = [] # Liste les ponts disulfures incompatibles @@ -1030,7 +1030,7 @@ class MapFilter: # TODO: better add clash list and sec_struct as object attribute sec_struct = kwargs.get("sec_struct") clash_list = kwargs.get("clash_list") - logger.info("...Secondary structure clash filter") + LOG.info("...Secondary structure clash filter") ss_matrix = sec_struct.ss_matrix ss_list = zip(*ss_matrix)[2] # contact_list from contact map start at 0 !! @@ -1075,8 +1075,8 @@ class MapFilter: # If both residues are in same helix or strand desc = "%s,%s" % (ssi[0], ssj[0]) desc_dict[contact] = desc - logger.debug("Ss conflict for contact %d %s (%s)" % ( - icontact, outcontact, desc)) + LOG.debug("Ss conflict for contact %d %s (%s)", + icontact, outcontact, desc) ssclash_pair.append(contact) # ELIF encadre H ou E elif ssi != ssj: @@ -1150,63 +1150,63 @@ class MapFilter: break if ssclash: - logger.debug("Ss clash for contact %d %s (%s)" % ( - icontact, outcontact, ssclash)) + LOG.debug("Ss clash for contact %d %s (%s)", + icontact, outcontact, ssclash) if ssclash in ("H-2,H", "H+2,H") \ and abs(resi - resj) == 6: # Allow contact to the fifth residue in the # helix - logger.debug("Found (H-2, H) for contact %s clash " + LOG.debug("Found (H-2, H) for contact %s clash " "but contact with fifth residue is " - "actually allowed" % - outcontact) + "actually allowed", + outcontact) ssclash = None elif ssclash in ("H-3,H", "H+3,H") \ and abs(resi - resj) < 12: - logger.debug("Found (H-3, H) for contact %s clash " + LOG.debug("Found (H-3, H) for contact %s clash " "but contact between 3rd and 10th " - "residues are actually allowed" % - outcontact) + "residues are actually allowed", + outcontact) # Allow contact between 3rd residue and 10th ssclash = None elif ssclash in ("H-4,H", "H+4,H"): - logger.debug("H-4,H are actually allowed") + LOG.debug("H-4,H are actually allowed") ssclash = None elif ssclash in ("H-2,H+2", "H+2,H-2"): - logger.debug("H-2,H+2 are actually allowed") + LOG.debug("H-2,H+2 are actually allowed") ssclash = None elif ssclash in ("H-3,H+3", "H+3,H-3"): - logger.debug("H-3,H+3 are actually allowed") + LOG.debug("H-3,H+3 are actually allowed") ssclash = None elif ssclash in ("H-4,H+4", "H+4,H-4"): - logger.debug("H-4,H+4 are actually allowed") + LOG.debug("H-4,H+4 are actually allowed") ssclash = None elif ssclash == "E-2,E+2": strand = ssj if ssj[0] == "E" else ssi start = ss_start_end[strand][1] end = ss_start_end[strand][0] if abs(start - end + 1) <= 5: - logger.debug("Found (E-2, E+2) for contact " + LOG.debug("Found (E-2, E+2) for contact " "%s clash but strand " - "is < 5 residues" % outcontact) + "is < 5 residues", outcontact) # Allow contact if strand < 5 residues (gap <8) ssclash = None elif ssclash in ("E-3,E+3", "E+3,E-3"): - logger.debug("E-3,E+3 are actually allowed") + LOG.debug("E-3,E+3 are actually allowed") ssclash = None elif ssclash in ("E-4,E+4", "E+4,E-4"): - logger.debug("E-4,E+4 are actually allowed") + LOG.debug("E-4,E+4 are actually allowed") ssclash = None elif ssclash in ("E-4,E", "E+4,E") \ and abs(resi - resj) < 8: - logger.debug("Found (E-4, E) for contact %s clash " + LOG.debug("Found (E-4, E) for contact %s clash " "but contacts below 4th residue are " - "actually allowed" % outcontact) + "actually allowed", outcontact) ssclash = None if ssclash: - logger.debug( - "Ss conflict for contact %d %s (%s)" % ( - icontact, outcontact, ssclash)) + LOG.debug( + "Ss conflict for contact %d %s (%s)", + icontact, outcontact, ssclash) desc_dict[contact] = ssclash ssclash_pair.append(contact) break @@ -1241,7 +1241,7 @@ class MapFilter: mapfilters = [mapfilters] if "pos" not in mapfilters: mapfilters.insert(0, "pos") - logger.info("Filtering %s contact map" % mtype) + LOG.info("Filtering %s contact map", mtype) for flt in mapfilters: # /!\ cys unicity filter must be the last filter ! # TODO: contacts_flt.out checking if given clash in coupling @@ -1253,9 +1253,9 @@ class MapFilter: if flt_res.get("clash"): clash_list.extend(flt_res.get("clash")) hum_list = [(x + 1, y + 1) for x, y in flt_res.get("clash")] - logger.info( - "Removed %d contacts:\n%s" % (len(flt_res.get("clash")) / 2, - hum_list)) + LOG.info( + "Removed %d contacts:\n%s", len(flt_res.get("clash")) / 2, + hum_list) clash_dict[flt] = flt_res.get("clash") if flt_res.get("desc"): desc_dict.update(flt_res.get("desc")) @@ -1266,28 +1266,28 @@ class MapFilter: # Contactmap always filtered # TODO: could set a treshold instead of n_factor - logger.info("Setting contact number with treshold %s" % - self.settings.get("n_factor")) + LOG.info("Setting contact number with treshold %s", + self.settings.get("n_factor")) nb_c = int(len(mapdict["contactmap"].sequence) * float( self.settings.get("n_factor"))) nb_c = nb_c if nb_c < len(mapdict["contactmap"].contactset()) else len( mapdict["contactmap"].contactset()) mapdict["nb_c"] = nb_c - logger.info("Update %s contactmap" % mtype) + LOG.info("Update %s contactmap", mtype) mapdict["contactmap"].remove(clash_list) if mapdict["scoremap"] is not None: - logger.info("Update %s scoremap" % mtype) + LOG.info("Update %s scoremap", mtype) mapdict["scoremap"].remove(clash_list) # Get nb_c top maps - logger.info("Select top %d contacts according to scoremap" % nb_c) + LOG.info("Select top %d contacts according to scoremap", nb_c) # TODO: deplacer cette partie dans l'appel de contactmap une fois # la classe mapcollections utilisee mapdict["contactmap"] = mapdict["contactmap"].topmap(mapdict["scoremap"], nb_c) if mapdict["distmap"] is not None: - logger.info("Update %s distmap" % mtype) + LOG.info("Update %s distmap", mtype) mapdict["distmap"].remove(clash_list) return mapdict diff --git a/ariaec/reader.py b/ariaec/reader.py index 30b7a9c05b59787334883d9fa6aed81eef139c83..7b27c166b3c0620d0fe0283178cdff51b2fd4668 100644 --- a/ariaec/reader.py +++ b/ariaec/reader.py @@ -12,7 +12,7 @@ import scipy.spatial.distance as distance from .base import sort_2dict from .protmap import (ResMap, ResAtmMap) -logger = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) Atom = collections.namedtuple("Atom", ["name", "coords"]) @@ -33,7 +33,7 @@ class RegexFile(object): lines_dict = {} if not self.regex: - logger.error("Can't parse file %s" % self.filepath) + LOG.error("Can't parse file %s", self.filepath) with open(self.filepath) as f: for index, line in enumerate(f): @@ -226,12 +226,12 @@ class MapFile(RegexFile): Check if plm_dict is consistent with input sequence :param aa_seq: """ - logger.info("Checking consistency of contacts with input sequence") + LOG.info("Checking consistency of contacts with input sequence") for line in self.lines: if self.lines[line]['res1_name'] != aa_seq[int(self.lines[line]['res1_nb']) - 1] \ or self.lines[line]['res2_name'] != aa_seq[int(self.lines[line]['res2_nb']) - 1]: - logger.error("Difference between given sequence and residu " - "names in contact file at line %d !" % line) + LOG.error("Difference between given sequence and residu " + "names in contact file at line %d !", line) def update_map(self, resmap): """ @@ -247,7 +247,7 @@ class MapFile(RegexFile): :return: """ - logger.info("Checking format for file %s" % self.filepath) + LOG.info("Checking format for file %s", self.filepath) # Check if given type is supported # TODO: report this check into commands section with open(self.filepath) as infile: @@ -257,52 +257,52 @@ class MapFile(RegexFile): match = self.types[self.filetype].get("regex").match(line) else: match = None - logger.error("Format %s not supported !" % self.filetype) + LOG.error("Format %s not supported !", self.filetype) # TODO: DRY rule !! def1match = self.types["default_1"]["regex"].match(line) def2match = self.types["default_2"]["regex"].match(line) def3match = self.types["default_3"]["regex"].match(line) def4match = self.types["default_4"]["regex"].match(line) if match: - logger.debug("Format type correct") + LOG.debug("Format type correct") return [ self.types[self.filetype].get("regex"), self.filetype, self.types[self.filetype].get("score_field") ] elif def1match: - logger.debug("Format type correct") + LOG.debug("Format type correct") return [ self.types["default_1"].get("regex"), self.filetype, self.types["default_1"].get("score_field") ] elif def2match: - logger.debug("Format type correct") + LOG.debug("Format type correct") return [ self.types["default_2"].get("regex"), self.filetype, self.types["default_2"].get("score_field") ] elif def3match: - logger.debug("Format type correct") + LOG.debug("Format type correct") return [ self.types["default_3"].get("regex"), self.filetype, self.types["default_3"].get("score_field") ] elif def4match: - logger.debug("Format type correct") + LOG.debug("Format type correct") return [ self.types["default_4"].get("regex"), self.filetype, self.types["default_4"].get("score_field") ] if index > 2: - logger.error("Error reading %s file." % self.filetype) + LOG.error("Error reading %s file.", self.filetype) # Remove contact file break - logger.error("Wrong format type given ...") + LOG.error("Wrong format type given ...") return [None] * 3 def read(self, protein=None, contactdef=5.0, groupby_method="min", @@ -315,13 +315,13 @@ class MapFile(RegexFile): :param scsc: :return: """ - logger.info("Reading %s file" % self.filepath) + LOG.info("Reading %s file", self.filepath) if self.filetype: # Read file with regex related to filetype self.load() - logger.debug(self.lines) + LOG.debug(self.lines) if protein: - logger.info("Loading contact list") + LOG.info("Loading contact list") if self.filetype == "contactlist": self.flaglist = { tuple(sorted( @@ -348,7 +348,7 @@ class MapFile(RegexFile): for contact in self.lines if self.lines[contact].get("res1_nb") and self.lines[contact].get("res2_nb")] - logger.debug(self.contactlist) + LOG.debug(self.contactlist) sym = False if self.filetype == "metapsicovhb" else True self.create_map(protein, contactdef, groupby_method=groupby_method, scsc=scsc, @@ -358,7 +358,7 @@ class MapFile(RegexFile): # consistent with given sequence self.check_contacts(protein.aa_sequence.sequence) if self.filetype == "evfold": - logger.info("Loading evfold clash list") + LOG.info("Loading evfold clash list") self.clashlist = [ next((el for el in (self.lines[contact].get("ss_filter"), self.lines[contact].get("high_cons_filter"), @@ -367,9 +367,9 @@ class MapFile(RegexFile): self.lines[contact].get("res1_nb") and self.lines[contact].get("res2_nb")] if len(self.contactlist) != len(self.clashlist): - logger.error("When reading input file, clash list is not " + LOG.error("When reading input file, clash list is not " "the same length than contactlist") - logger.debug(self.clashlist) + LOG.debug(self.clashlist) class ContactMapFile(MapFile): @@ -431,11 +431,11 @@ class ContactMapFile(MapFile): if (int(residx1.split("-")[0]) != resid1) or \ (resid2 != int(residx2.split("-")[0])): - logger.error("Wrong resid humanidx (%d, %d) in contact (%d) is " - "not the same in resmap (%d, %d)" % ( - resid1, resid2, contact_id, - int(residx1.split("-")[0]), - int(residx2.split("-")[0]))) + LOG.error("Wrong resid humanidx (%d, %d) in contact (%d) is " + "not the same in resmap (%d, %d)", + resid1, resid2, contact_id, + int(residx1.split("-")[0]), + int(residx2.split("-")[0])) contactmap.set_value(residx1, residx2, True) if self.sort: @@ -445,9 +445,9 @@ class ContactMapFile(MapFile): if distmap is not None: distmap.set_value(residx1, residx2, dist) - logger.debug("%s contact map:\n%s" % (self.filetype, contactmap)) + LOG.debug("%s contact map:\n%s", self.filetype, contactmap) self.mapdict["contactmap"] = contactmap - logger.debug("%s score map:\n%s" % (self.filetype, scoremap)) + LOG.debug("%s score map:\n%s", self.filetype, scoremap) self.mapdict["scoremap"] = scoremap if distmap is not None: self.mapdict["distmap"] = distmap @@ -479,7 +479,7 @@ class PDBFile(MapFile): flaglist=flaglist, path=path, seqidx=protein.index, desc=self.filetype) resmap[:] = self.update_map(resmap, sym=sym) - logger.debug("pdb distance map:\n%s" % resmap) + LOG.debug("pdb distance map:\n%s", resmap) self.mapdict["alldistmap"] = resmap self.mapdict["distmap"] = resmap.reduce(groupby=groupby_method) self.mapdict["allcontactmap"] = resmap.contact_map( @@ -489,7 +489,7 @@ class PDBFile(MapFile): def update_map(self, resmap, sym=True): # Map only on heavy atoms # TODO: check if same sequence in pdb file - logger.info("Updating distance map with pdb file") + LOG.info("Updating distance map with pdb file") newmap = resmap.copy() heavylist = [] error_list = set() @@ -517,7 +517,7 @@ class PDBFile(MapFile): dist = distance.euclidean(coordx, coordy) if indx[0] in list(resmap.index.get_level_values("residuex"))\ and indy[0] in list(resmap.index.get_level_values("residuex")): - logger.debug("Update distance value (%s, %s)" % (indx, indy)) + LOG.debug("Update distance value (%s, %s)", indx, indy) newmap.at[indx, indy] = dist if sym: # If symmetric matrix @@ -536,8 +536,8 @@ class PDBFile(MapFile): newmap.loc[idx] = None if sym: newmap.loc[:][idx] = None - logger.error("Can't update pdb distance map for pos in pdb file " - "%s with %s" % (list(error_list), missidx)) + LOG.error("Can't update pdb distance map for pos in pdb file " + "%s with %s", list(error_list), missidx) return newmap @@ -572,12 +572,12 @@ class ProtFileListReader: filetypelist) != list else filetypelist if not filetypelist or len(filepathlist) != len(filetypelist): filetypelist = [os.path.splitext(_)[1][1:] for _ in filepathlist] - logger.info("Reader focused on file(s) %s %s" % (filepathlist, - filetypelist)) + LOG.info("Reader focused on file(s) %s %s", filepathlist, + filetypelist) for i, filepath in enumerate(filepathlist): if os.path.exists(filepath): # TODO: check_type functionstr - logger.debug("Adding %s file to watchlist" % filetypelist[i]) + LOG.debug("Adding %s file to watchlist", filetypelist[i]) if filetypelist[i].lower() == "pdb" and \ os.path.splitext(filepath)[1][1:] == "pdb": self.filelist.append(PDBFile(filepath)) @@ -589,7 +589,7 @@ class ProtFileListReader: # filetypelist[i])) # TODO: DistanceMapFile condition if not self.filelist[-1].regex: - logger.warning("Can't read %s" % filepath) + LOG.warning("Can't read %s", filepath) self.filelist.pop() def read(self, filepathlist, filetypelist=None, protein=None, scsc=None, diff --git a/ariaec/setup.py b/ariaec/setup.py index 335a376c45c399144b5dc9e1d2d1fa5d58150f0e..273bacbe337ea9552bd930c6b4246404992990a4 100644 --- a/ariaec/setup.py +++ b/ariaec/setup.py @@ -16,7 +16,7 @@ from .econverter import AriaEcXMLConverter # TODO: S'inspirer de pandas/__init__.py pour les dependances # from basictools import * -logger = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) class AriaEcSetup: @@ -44,10 +44,10 @@ class AriaEcSetup: :return: """ # Check input - logger.debug("Settings:\n" + json.dumps(self.settings.setup.config, - indent=4)) - logger.debug("Args:\n" + json.dumps(self.settings.setup.args, - indent=4)) + LOG.debug("Settings:\n" + json.dumps(self.settings.setup.config, + indent=4)) + LOG.debug("Args:\n" + json.dumps(self.settings.setup.args, + indent=4)) self.settings.make_infra() # -------------------------------------------------------------------- # # ----------------------------- Input -------------------------------- # @@ -89,7 +89,7 @@ class AriaEcSetup: # ---------------------------- target map ---------------------------- # if self.settings.setup.args.get("distfile") and \ self.settings.setup.config.get("distance_type") == "distfile": - logger.info("Loading target distance file") + LOG.info("Loading target distance file") # Read distance file self.reader.read( self.settings.setup.args.get("distfile"), @@ -146,7 +146,7 @@ class AriaEcSetup: # Setting contact number limit for hbmap n_hb = int(len(self.protein.aa_sequence.sequence) * self.settings.setup.config.get("nf_longrange_hb")) - logger.info("Writing tbl files ...") + LOG.info("Writing tbl files ...") tbl_files = self.converter.write_tbl_restraints( self.protein, hbmap=self.hbmaps, n_hb=n_hb) @@ -229,7 +229,7 @@ class AriaEcSetup: raise TypeError('Contact list must be 2-tuple !') contacts = contacts_list if not nc else contacts_list[:nc] d_type = False - logger.debug("Contact list %s" % contacts) + LOG.debug("Contact list %s", contacts) for contact in contacts: if d_type: @@ -240,7 +240,7 @@ class AriaEcSetup: resid1 = int(contact[0]) resid2 = int(contact[1]) - logger.debug("Contact %s" % (str(contact))) + LOG.debug("Contact %s", str(contact)) if distmap is not None: dist = distmap.ix[(resid1, resid2)] else: @@ -279,5 +279,5 @@ if __name__ == "__main__": from .ecsettings import AriaEcSettings logging.basicConfig(level=logging.DEBUG) - logger = logging.getLogger("Setup") + LOG = logging.getLogger("Setup") AriaEcSettings('setup').load_config('aria_ec.ini') diff --git a/bin/ec2aria.py b/bin/ec2aria.py index e34f43723092801e25fc2605755ea4960b08b1fa..72b3342be8a820983b52ec02b46927bf038678f6 100644 --- a/bin/ec2aria.py +++ b/bin/ec2aria.py @@ -6,26 +6,15 @@ """ from __future__ import absolute_import, division, print_function -# TODO: replace all aria_ec ref into script name # TODO: Utiliser scikit-bio pour traiter les sequences biologiques import logging -# Adding aria path -# if 'ARIA2' not in os.environ: -# sys.exit("This program needs ARIA2 !") -# else: -# ariapath = os.path.abspath(os.path.join(os.environ['ARIA2'], 'src/py')) -# sys.path.insert(0, ariapath) - -# Adding ariaec path -# TODO: remove this part if setup.py works !!! -# sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(__file__)))) from ariaec.base import CustomLogging import ariaec.commands as ecio -logger = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) def main():