Commit 994315ae authored by Fabrice Allain's avatar Fabrice Allain
Browse files

Pdbqual command added

parent 664e6661
......@@ -3,6 +3,7 @@
Basic tools aria_ec
"""
from __future__ import absolute_import, division, print_function
from abc import ABCMeta, abstractmethod
import logging
import logging.config
......@@ -18,7 +19,7 @@ import matplotlib.artist as art
from io import StringIO
LOG = logging.getLogger()
LOG = logging.getLogger(__name__)
def addtup(tup, inc=1):
......@@ -255,9 +256,9 @@ class CustomLogging(object):
:return:
"""
# with open(self.default_file, 'rt') as f:
with pkgr.resource_stream(__name__, self.default_file) as f:
config = json.load(f)
logging.config.dictConfig(config)
conf = pkgr.resource_stream(__name__, self.default_file).read().decode()
config = json.loads(conf)
logging.config.dictConfig(config)
return config
def set_outdir(self, outdir):
......@@ -329,6 +330,24 @@ class Capturing(list):
sys.stdout = self._stdout
class CommandProtocol(object):
"""
Abstract class for subcommand protocol
"""
__metaclass__ = ABCMeta
def __init__(self, settings):
self.settings = settings
@abstractmethod
def run(self):
"""
main method to launch protocol
:return:
"""
raise NotImplementedError
if __name__ == "__main__":
# Test Logger
CustomLogging().set_outdir("../examples/out")
......
No preview for this file type
......@@ -12,6 +12,7 @@ from .ecsettings import AriaEcSettings
from .maplot import AriaEcContactMap
from .econverter import AriaEcBbConverter
from .setup import AriaEcSetup
from .pdbqual import AriaEcPdbqual
LOG = logging.getLogger(__name__)
......@@ -42,9 +43,11 @@ class ReadableFile(argp.Action):
if type(values) == list:
for prospective_file in values:
check_file(prospective_file)
setattr(namespace, self.dest,
[os.path.abspath(os.path.expanduser(val)) for val in values])
elif type(values) == str:
check_file(values)
setattr(namespace, self.dest, values)
setattr(namespace, self.dest, os.path.abspath(os.path.expanduser(values)))
# TODO: Make parent Command class with _create_argparser, self.args,
......@@ -54,11 +57,12 @@ class AriaEcCommand(object):
Argparse interface for aria_ec
"""
command_list = ("setup", "bbconv", "contactmap")
command_list = ("setup", "bbconv", "contactmap", "pdbqual")
desc_list = (u"Setup ARIA infrastructure with given contacts translated "
u"into ARIA restraints",
u"Convert contacts in bbcontact format",
u"Contactmap tool")
u"Contactmap tool",
u"Quality tool for pdb file(s)")
contact_types = ("plmdca", "evfold", "bbcontacts", "pconsc", "pconsc1",
"pconsc2", "psicov", "metapsicovhb", "metapsicov_stg1",
"metapsicov_stg2", "gremlin", "pdb", "native",
......@@ -212,11 +216,24 @@ class AriaEcCommand(object):
help="Contact map name", nargs="+")
return parser
@staticmethod
def _pdbqual_parser(desc=None):
parser = argp.ArgumentParser(description=desc,
add_help=False)
parser.add_argument("infiles", nargs="+", metavar="infile",
action=ReadableFile,
help="PDB file(s) used to run quality tools with "
"aria API")
return parser
def create_settings(self):
"""
create settings relative to args.command
:return:
"""
if self.args.debug:
LOG.info("Toggle on debug mode")
logging.getLogger().setLevel(logging.DEBUG)
LOG.debug("Create AriaEcSettings")
settings = AriaEcSettings(self.args.command)
LOG.info("Loading default config file")
......@@ -230,9 +247,6 @@ class AriaEcCommand(object):
if self.args.output_directory:
LOG.info("Updating output directory")
settings.infra = self.args.output_directory
if self.args.debug:
LOG.info("Toggle on debug mode")
logging.getLogger().setLevel(logging.DEBUG)
return settings
def run(self):
......@@ -263,6 +277,14 @@ class AriaEcCommand(object):
econtactmap = AriaEcContactMap(self.create_settings())
econtactmap.run()
def pdbqual(self):
"""
Quality run subcommand
:return:
"""
qualprot = AriaEcPdbqual(self.create_settings())
qualprot.run()
if __name__ == "__main__":
# Test AriaEcCommand object
......
No preview for this file type
......@@ -9,6 +9,11 @@
ss_dist_file:
scsc_min_file:
ariaproject_template: 2.3.0
procheck_executable:
prosa_executable:
whatif_executable:
clashlist_executable:
[contactdef]
; Contact definition section used to define contactmap from pdb file.
......@@ -179,3 +184,8 @@ PSIPREDfile:
diversityvalue:
L:
[pdbqual]
trash_directory:
prosa: False
skip_prefix: fitted
csh_executable: csh
\ No newline at end of file
No preview for this file type
......@@ -25,6 +25,14 @@ class Setting(object):
def __init__(self):
self.config = collections.defaultdict()
self.args = collections.defaultdict()
def __getitem__(self, item):
if item in self.config:
return self.config[item]
elif item in self.args:
return self.args[item]
else:
raise KeyError(item)
def __repr__(self):
return "Setting object\n config: %s\n args : %s" % (self.config,
......@@ -105,14 +113,14 @@ class AriaEcSettings(Settings):
SS_DIST = 'data/ss_dist.txt'
SCSC_MIN = 'data/scsc_min.p'
TOPO = 'data/topallhdg5.3.pro'
COMMANDS = ("main", "setup", "contactmap", "bbconv", "contactdef")
SECTIONS = ("main", "setup", "contactmap", "bbconv", "contactdef", "pdbqual")
def __init__(self, name):
"""
Initiate settings with name related to a command
:param name:
"""
super(AriaEcSettings, self).__init__(self.COMMANDS)
super(AriaEcSettings, self).__init__(self.SECTIONS)
self._infra = {}
self._scsc_min = None
self._ssdist = None
......@@ -158,9 +166,9 @@ class AriaEcSettings(Settings):
:return:
"""
if not self._ssdist:
if self.main.config["ss_dist_file"] and \
os.path.exists(self.main.config["ss_dist_file"]):
self._ssdist = self.main.config["ss_dist_file"]
if self.main["ss_dist_file"] and \
os.path.exists(self.main["ss_dist_file"]):
self._ssdist = self.main["ss_dist_file"]
else:
self._ssdist = pkgr.resource_filename(__name__, self.SS_DIST)
return self._ssdist
......@@ -173,12 +181,12 @@ class AriaEcSettings(Settings):
"""
if not self._template:
templatepath = "templates/aria_project_v%s.xml" % \
str(self.main.config["ariaproject_template"])
str(self.main["ariaproject_template"])
if os.path.exists(pkgr.resource_filename(__name__, templatepath)):
self._template = pkgr.resource_filename(__name__, templatepath)
else:
LOG.error("Template version for aria project (%s) is not "
"supported", self.main.config.get("ariaproject_template"))
"supported", self.main.get("ariaproject_template"))
self._template = pkgr.resource_filename(__name__,
self.ARIAPROJ_TEMPLATE)
return self._template
......@@ -192,7 +200,7 @@ class AriaEcSettings(Settings):
if not self._scsc_min:
try:
# Read scsc_min_file given in aria_ec.ini
with open(self.main.config["scsc_min_file"]) as scsc:
with open(self.main["scsc_min_file"]) as scsc:
scsc_min = pickle.load(scsc)
except (IOError, KeyError, TypeError):
# If file can't be open or given key is invalid, load default
......
No preview for this file type
# coding=utf-8
"""
Created on 9/5/16
@author: fallain
Derived from qual.py script by Dr. Benjamin Bardiaux
"""
from aria.legacy.QualityChecks import QualityChecks
from .base import CommandProtocol
import os
import shutil
import logging
LOG = logging.getLogger(__name__)
class AriaEcPdbqual(CommandProtocol):
"""
Quality pdb tool
"""
def __init__(self, *args, **kwargs):
super(AriaEcPdbqual, self).__init__(*args, **kwargs)
def run(self):
"""
:return:
"""
LOG.info("Starting quality runs with %s file(s)", self.settings.pdbqual["infiles"])
LOG.info("Copying file(s) to output directory")
[shutil.copy(infile, self.settings.pdbqual["output_directory"]) for infile in self.settings.pdbqual["infiles"]]
QualityChecks.runChecks(
workingDirectory=os.path.abspath(
self.settings.pdbqual["output_directory"]),
trashDirectory=self.settings.pdbqual["trash_directory"],
prosaOnOff=1 if self.settings.pdbqual["prosa"] else 0,
procheckExe=self.settings.main["procheck_executable"],
whatIfExe=self.settings.main["whatif_executable"],
clashlistExe=self.settings.main["clashlist_executable"],
prosaExe=self.settings.main["prosa_executable"] if self.settings.main["prosa_executable"] else "",
cshExe=self.settings.pdbqual["csh_executable"],
howManyPdb=len(self.settings.pdbqual["infiles"]),
verbose=1,
fileList=self.settings.pdbqual["infiles"],
skipPrefix=self.settings.pdbqual["skip_prefix"]
)
LOG.info("%s generated",
os.path.join(self.settings.pdbqual["output_directory"],
QualityChecks.FILENAME_REPORT))
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