Commit 68c15add authored by Fabrice  ALLAIN's avatar Fabrice ALLAIN
Browse files

Updated sphinx documentation

parent a63afa91
......@@ -24,15 +24,25 @@ LOG = logging.getLogger(__name__)
class EnsembleAnalysis(object):
"""
ARIA extended ensemble analysis
"""
"""ARIA extended ensemble analysis"""
def __init__(self, settings):
self.settings = settings
@staticmethod
def _get_pdblist(iteration_path):
"""
Parameters
----------
iteration_path :
Returns
-------
"""
# Get the list of all the generated structures in iteration path if no
# clustering. Otherwise, get the list of the lowest energy cluster
if os.path.exists(os.path.join(iteration_path, "report.clustering")):
......@@ -56,23 +66,31 @@ class EnsembleAnalysis(object):
return list_of_pdb
@staticmethod
def violation_analysis(project, iteration_id, restraints, dists, out_file,
def violation_analysis(project, iteration_id, restraints, ensemble, out_file,
dists_ref=None, headerflag=True):
"""
Parameters
----------
project
iteration_id
restraints
dists
out_file
dists_ref
headerflag
project :
iteration_id :
restraints :
ensemble :
out_file :
dists_ref :
(Default value = None)
headerflag :
(Default value = True)
Returns
-------
"""
protein_id = project.getSettings()['name']
nbest = project.getProtocol().getIterationSettings(iteration_id)[
......@@ -93,7 +111,8 @@ class EnsembleAnalysis(object):
dist = None
try:
dist = [dists(*sp.getAtoms()) for sp in contrib]
dist = [ensemble.getDistances(*sp.getAtoms())
for sp in contrib]
# Liste des distances pour la contribution c pour
# chaque structure de l'ensemble (une ou plusieur
# distance(s) par structure de l'ensemble si contribution
......@@ -209,14 +228,19 @@ class EnsembleAnalysis(object):
Parameters
----------
iter_dir
ensemble
molecule
atmask
iter_dir :
ensemble :
molecule :
atmask :
(Default value = "CA")
Returns
-------
"""
mask = [a.getId() for c in molecule.get_chains() for r in c.getResidues()
for a in r.getAtoms() if a.getName() == atmask]
......@@ -238,9 +262,7 @@ class EnsembleAnalysis(object):
# return fitcoords, infos
def run(self):
"""
Execute Violation analysis
"""
"""Execute Violation analysis"""
# Args
project_path = self.settings.analysis.args["project"]
# restraints_path = self.settings.analysis.args["restraints"]
......@@ -331,13 +353,13 @@ class EnsembleAnalysis(object):
dists_ref = native.getDistances
# We get here the distance of ALL THE STRUCTURES IN THE CLUSTER for viol
# analysis
dists = ensemble.getDistances
# We get here the distance of 'number_of_best_structures' in the
# ensemble
# ens_getdists = ensemble.getDistances
LOG.info("Violation analysis")
out_file = os.path.join(out_path, 'violations.csv')
self.violation_analysis(project, iteration_id, restraints, dists,
self.violation_analysis(project, iteration_id, restraints, ensemble,
out_file, dists_ref=dists_ref)
infos = [inf for inf in ensemble.getInfo()]
......
......@@ -24,22 +24,39 @@ LOG = logging.getLogger(__name__)
def addtup(tup, inc=1):
"""
Increment all values by 1 in a tuple
:param tup:
:param inc:
:return:
"""Increment all values by 1 in a tuple
Parameters
----------
tup :
param inc:
inc :
(Default value = 1)
Returns
-------
"""
return tuple((val + inc for val in tup))
def titleprint(outfile, progname='', desc=''):
"""
Init log file
:param outfile:
:param progname: docstring
:param desc:
:return:
"""Init log file
Parameters
----------
outfile :
param progname: docstring
desc :
return: (Default value = '')
progname :
(Default value = '')
Returns
-------
"""
out = '''
================================================================================
......@@ -51,10 +68,17 @@ def titleprint(outfile, progname='', desc=''):
def get_filename(path):
"""
Search filename in the given path
:param path:
:return:
"""Search filename in the given path
Parameters
----------
path :
return:
Returns
-------
"""
return "_".join(path.split("/")[-1].split(".")[:-1])
......@@ -62,10 +86,19 @@ def get_filename(path):
def reg_load(regex, filepath, sort=None):
"""
:param regex:
:param filepath:
:param sort:
:return:
Parameters
----------
regex :
param filepath:
sort :
return: (Default value = None)
filepath :
Returns
-------
"""
lines_dict = {}
......@@ -83,12 +116,21 @@ def reg_load(regex, filepath, sort=None):
def sort_2dict(unsort_dict, key, reverse=True):
"""
Sort 2d dict by key
:param reverse:
:param key:
:param unsort_dict:
:return: sorted dict
"""Sort 2d dict by key
Parameters
----------
reverse :
param key: (Default value = True)
unsort_dict :
return: sorted dict
key :
Returns
-------
"""
sorted_index = sorted(unsort_dict, key=lambda x: float(unsort_dict[x][key]),
reverse=reverse)
......@@ -101,20 +143,35 @@ def sort_2dict(unsort_dict, key, reverse=True):
def cart_dist(vectx, vecty):
"""
Evaluate cartesian distance beetween 2 points x, vecty
:param vectx: numpy array (len = n dimensions)
:param vecty: numpy array (len = n dimensions)
:return:
"""Evaluate cartesian distance beetween 2 points x, vecty
Parameters
----------
vectx :
numpy array (len = n dimensions)
vecty :
numpy array (len = n dimensions)
Returns
-------
"""
return np.sqrt(sum(np.power(vectx - vecty, 2)))
def format_str(string):
"""
Convert str in bool, float, int or str
:param string:
:return:
"""Convert str in bool, float, int or str
Parameters
----------
string :
return:
Returns
-------
"""
if re.search(r"^\s*(true)\s*$", string, re.I):
return True
......@@ -154,8 +211,15 @@ def format_str(string):
def format_dict(indict):
"""
:param indict:
:return:
Parameters
----------
indict :
return:
Returns
-------
"""
for key in indict:
if isinstance(indict[key], str):
......@@ -166,21 +230,39 @@ def format_dict(indict):
def ppdict(indict, indent=2):
"""
:param indict:
:param indent:
:return:
Parameters
----------
indict :
param indent:
indent :
(Default value = 2)
Returns
-------
"""
return json.dumps(indict, indent=indent)
def tickmin(pandata, ntick=None, shift=0, offset=5):
"""
Minimise number of ticks labels for matplotlib or seaborn plot
:param offset:
:param shift:
:param pandata: pandas dataframe
:param ntick: number of ticks wanted per axes
:return:
"""Minimise number of ticks labels for matplotlib or seaborn plot
Parameters
----------
offset :
param shift: (Default value = 5)
pandata :
pandas dataframe
ntick :
number of ticks wanted per axes (Default value = None)
shift :
(Default value = 0)
Returns
-------
"""
yticks = [_ + shift for _ in range(0, len(pandata.index))]
xticks = [_ + shift for _ in range(0, len(pandata.columns))]
......@@ -206,14 +288,25 @@ def tickmin(pandata, ntick=None, shift=0, offset=5):
def tickrot(axes, figure, rotype='horizontal', xaxis=True, yaxis=True):
"""
Matplot rotation of ticks labels
:param axes:
:param figure:
:param rotype:
:param xaxis:
:param yaxis:
:return:
"""Matplot rotation of ticks labels
Parameters
----------
axes :
param figure:
rotype :
param xaxis: (Default value = 'horizontal')
yaxis :
return: (Default value = True)
figure :
xaxis :
(Default value = True)
Returns
-------
"""
if yaxis:
art.setp(axes.get_yticklabels(), rotation=rotype)
......@@ -224,6 +317,7 @@ def tickrot(axes, figure, rotype='horizontal', xaxis=True, yaxis=True):
# TODO: Add another level when we use verbose options instead of displaying debug messages
class CustomLogging(object):
""" """
# default_file = os.path.join(os.path.abspath(os.path.dirname(__file__)),
# "conf/logging.json")
"""
......@@ -249,8 +343,15 @@ class CustomLogging(object):
def update_msg(self, desc):
"""
:param desc:
:return:
Parameters
----------
desc :
return:
Returns
-------
"""
if isinstance(self.msg, list):
self.msg += desc
......@@ -259,10 +360,7 @@ class CustomLogging(object):
self.msg = " - ".join((self.msg, desc.capitalize()))
def default_config(self):
"""
:return:
"""
""":return:"""
# with open(self.default_file, 'rt') as f:
conf = pkgr.resource_stream(__name__, self.default_file).read().decode()
config = json.loads(conf)
......@@ -270,10 +368,17 @@ class CustomLogging(object):
return config
def set_outdir(self, outdir):
"""
Create log directory and change log files location
:param outdir: path output directory
:return:
"""Create log directory and change log files location
Parameters
----------
outdir :
path output directory
Returns
-------
"""
outdir = os.path.join(outdir,
"log") if "log" not in outdir else outdir
......@@ -295,10 +400,7 @@ class CustomLogging(object):
logging.config.dictConfig(self.config)
def welcome(self):
"""
:return:
"""
""":return:"""
desc = '''
================================================================================
......@@ -315,9 +417,7 @@ class CustomLogging(object):
class Capturing(list):
"""
Capture output
"""
"""Capture output"""
def __enter__(self):
"""
......@@ -344,9 +444,7 @@ class Capturing(list):
class RedirectStdStreams(object):
"""
Redirect standard ouput and errors
"""
"""Redirect standard ouput and errors"""
def __init__(self, stdout=None, stderr=None):
self._stdout = stdout or sys.stdout
self._stderr = stderr or sys.stderr
......@@ -366,9 +464,7 @@ class RedirectStdStreams(object):
class CommandProtocol(object):
"""
Abstract class for subcommand protocol
"""
"""Abstract class for subcommand protocol"""
__metaclass__ = ABCMeta
def __init__(self, settings):
......@@ -376,29 +472,35 @@ class CommandProtocol(object):
@abstractmethod
def run(self):
"""
main method to launch protocol
"""main method to launch protocol
:return:
Parameters
----------
Returns
-------
"""
raise NotImplementedError
class NotDisordered(Select):
"""
Define an atom as disordered or not in pdb selection
"""
"""Define an atom as disordered or not in pdb selection"""
def accept_atom(self, atom):
"""
Accept or not the atom if it does not correspond to an alternative
"""Accept or not the atom if it does not correspond to an alternative
location
Parameters
----------
atom
atom :
Returns
-------
"""
return not atom.is_disordered() or atom.get_altloc() == 'A'
......
......@@ -25,7 +25,15 @@ LOG = logging.getLogger(__name__)
def check_file(prospective_file):
"""
:param prospective_file:
Parameters
----------
prospective_file :
Returns
-------
"""
LOG.debug("Checking if %s is a readable file", prospective_file)
if not os.path.exists(prospective_file):
......@@ -37,9 +45,7 @@ def check_file(prospective_file):
class ReadableFile(argp.Action):
"""
Class used with argparse action to check if a file is readable
"""
"""Class used with argparse action to check if a file is readable"""
def __init__(self, *args, **kwargs):
super(ReadableFile, self).__init__(*args, **kwargs)
......@@ -58,9 +64,7 @@ class ReadableFile(argp.Action):
# TODO: Make parent Command class with _create_argparser, self.args,
# update_logger and run
class AriaEcCommands(object):
"""
Argparse interface for aria_ec
"""
"""Argparse interface for aria_ec"""
command_list = ("setup", "bbconv", "maplot", "pdbqual", "analysis",
"tbl2xml", "pdbdist")
......@@ -87,6 +91,18 @@ class AriaEcCommands(object):
self._update_logger(custom_logging)
def _update_logger(self, log):
"""
Parameters
----------
log :
Returns
-------
"""
if log and hasattr(self.args, "output_directory"):
if not self.args.nolog:
# Don't generate log files
......@@ -99,6 +115,7 @@ class AriaEcCommands(object):
log.welcome()
def _create_argparser(self):
""" """
parser = argp.ArgumentParser(description=__doc__,
formatter_class=argp.ArgumentDefaultsHelpFormatter)
parser.add_argument("-o", "--output", dest="output_directory",
......@@ -116,10 +133,17 @@ class AriaEcCommands(object):
return parser
def _create_subparsers(self, parser):
"""
Generate subcommands
:param parser: argparser object
:return:
"""Generate subcommands
Parameters
----------
parser :
argparser object
Returns
-------
"""
for index, command in enumerate(self.command_list):
# Create subparser defined in command list
......@@ -128,10 +152,17 @@ class AriaEcCommands(object):
parser.add_parser(command, parents=[subcommand])
def _setup_argparser(self, desc=None):
"""
setup opt & args
:param desc: command descriptor
:return: argparser object
"""setup opt & args
Parameters
----------
desc :
command descriptor (Default value = None)
Returns
-------
"""
parser = argp.ArgumentParser(description=desc,
add_help=False)
......@@ -167,10 +198,17 @@ class AriaEcCommands(object):
return parser
def _bbconv_argparser(self, desc=None):
"""
bbconv opt & args
:param desc: command descriptor