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__) ...@@ -24,15 +24,25 @@ LOG = logging.getLogger(__name__)
class EnsembleAnalysis(object): class EnsembleAnalysis(object):
""" """ARIA extended ensemble analysis"""
ARIA extended ensemble analysis
"""
def __init__(self, settings): def __init__(self, settings):
self.settings = settings self.settings = settings
@staticmethod @staticmethod
def _get_pdblist(iteration_path): def _get_pdblist(iteration_path):
"""
Parameters
----------
iteration_path :
Returns
-------
"""
# Get the list of all the generated structures in iteration path if no # Get the list of all the generated structures in iteration path if no
# clustering. Otherwise, get the list of the lowest energy cluster # clustering. Otherwise, get the list of the lowest energy cluster
if os.path.exists(os.path.join(iteration_path, "report.clustering")): if os.path.exists(os.path.join(iteration_path, "report.clustering")):
...@@ -56,23 +66,31 @@ class EnsembleAnalysis(object): ...@@ -56,23 +66,31 @@ class EnsembleAnalysis(object):
return list_of_pdb return list_of_pdb
@staticmethod @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): dists_ref=None, headerflag=True):
""" """
Parameters Parameters
---------- ----------
project project :
iteration_id
restraints iteration_id :
dists
out_file restraints :
dists_ref
headerflag ensemble :
out_file :
dists_ref :
(Default value = None)
headerflag :
(Default value = True)
Returns Returns
------- -------
""" """
protein_id = project.getSettings()['name'] protein_id = project.getSettings()['name']
nbest = project.getProtocol().getIterationSettings(iteration_id)[ nbest = project.getProtocol().getIterationSettings(iteration_id)[
...@@ -93,7 +111,8 @@ class EnsembleAnalysis(object): ...@@ -93,7 +111,8 @@ class EnsembleAnalysis(object):
dist = None dist = None
try: 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 # Liste des distances pour la contribution c pour
# chaque structure de l'ensemble (une ou plusieur # chaque structure de l'ensemble (une ou plusieur
# distance(s) par structure de l'ensemble si contribution # distance(s) par structure de l'ensemble si contribution
...@@ -209,14 +228,19 @@ class EnsembleAnalysis(object): ...@@ -209,14 +228,19 @@ class EnsembleAnalysis(object):
Parameters Parameters
---------- ----------
iter_dir iter_dir :
ensemble
molecule ensemble :
atmask
molecule :
atmask :
(Default value = "CA")
Returns Returns
------- -------
""" """
mask = [a.getId() for c in molecule.get_chains() for r in c.getResidues() mask = [a.getId() for c in molecule.get_chains() for r in c.getResidues()
for a in r.getAtoms() if a.getName() == atmask] for a in r.getAtoms() if a.getName() == atmask]
...@@ -238,9 +262,7 @@ class EnsembleAnalysis(object): ...@@ -238,9 +262,7 @@ class EnsembleAnalysis(object):
# return fitcoords, infos # return fitcoords, infos
def run(self): def run(self):
""" """Execute Violation analysis"""
Execute Violation analysis
"""
# Args # Args
project_path = self.settings.analysis.args["project"] project_path = self.settings.analysis.args["project"]
# restraints_path = self.settings.analysis.args["restraints"] # restraints_path = self.settings.analysis.args["restraints"]
...@@ -331,13 +353,13 @@ class EnsembleAnalysis(object): ...@@ -331,13 +353,13 @@ class EnsembleAnalysis(object):
dists_ref = native.getDistances dists_ref = native.getDistances
# We get here the distance of ALL THE STRUCTURES IN THE CLUSTER for viol # We get here the distance of 'number_of_best_structures' in the
# analysis # ensemble
dists = ensemble.getDistances # ens_getdists = ensemble.getDistances
LOG.info("Violation analysis") LOG.info("Violation analysis")
out_file = os.path.join(out_path, 'violations.csv') 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) out_file, dists_ref=dists_ref)
infos = [inf for inf in ensemble.getInfo()] infos = [inf for inf in ensemble.getInfo()]
......
...@@ -24,22 +24,39 @@ LOG = logging.getLogger(__name__) ...@@ -24,22 +24,39 @@ LOG = logging.getLogger(__name__)
def addtup(tup, inc=1): def addtup(tup, inc=1):
""" """Increment all values by 1 in a tuple
Increment all values by 1 in a tuple
:param tup: Parameters
:param inc: ----------
:return: tup :
param inc:
inc :
(Default value = 1)
Returns
-------
""" """
return tuple((val + inc for val in tup)) return tuple((val + inc for val in tup))
def titleprint(outfile, progname='', desc=''): def titleprint(outfile, progname='', desc=''):
""" """Init log file
Init log file
:param outfile: Parameters
:param progname: docstring ----------
:param desc: outfile :
:return: param progname: docstring
desc :
return: (Default value = '')
progname :
(Default value = '')
Returns
-------
""" """
out = ''' out = '''
================================================================================ ================================================================================
...@@ -51,10 +68,17 @@ def titleprint(outfile, progname='', desc=''): ...@@ -51,10 +68,17 @@ def titleprint(outfile, progname='', desc=''):
def get_filename(path): def get_filename(path):
""" """Search filename in the given path
Search filename in the given path
:param path: Parameters
:return: ----------
path :
return:
Returns
-------
""" """
return "_".join(path.split("/")[-1].split(".")[:-1]) return "_".join(path.split("/")[-1].split(".")[:-1])
...@@ -62,10 +86,19 @@ def get_filename(path): ...@@ -62,10 +86,19 @@ def get_filename(path):
def reg_load(regex, filepath, sort=None): def reg_load(regex, filepath, sort=None):
""" """
:param regex: Parameters
:param filepath: ----------
:param sort: regex :
:return: param filepath:
sort :
return: (Default value = None)
filepath :
Returns
-------
""" """
lines_dict = {} lines_dict = {}
...@@ -83,12 +116,21 @@ def reg_load(regex, filepath, sort=None): ...@@ -83,12 +116,21 @@ def reg_load(regex, filepath, sort=None):
def sort_2dict(unsort_dict, key, reverse=True): def sort_2dict(unsort_dict, key, reverse=True):
""" """Sort 2d dict by key
Sort 2d dict by key
:param reverse: Parameters
:param key: ----------
:param unsort_dict: reverse :
:return: sorted dict 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]), sorted_index = sorted(unsort_dict, key=lambda x: float(unsort_dict[x][key]),
reverse=reverse) reverse=reverse)
...@@ -101,20 +143,35 @@ def sort_2dict(unsort_dict, key, reverse=True): ...@@ -101,20 +143,35 @@ def sort_2dict(unsort_dict, key, reverse=True):
def cart_dist(vectx, vecty): def cart_dist(vectx, vecty):
""" """Evaluate cartesian distance beetween 2 points x, vecty
Evaluate cartesian distance beetween 2 points x, vecty
:param vectx: numpy array (len = n dimensions) Parameters
:param vecty: numpy array (len = n dimensions) ----------
:return: vectx :
numpy array (len = n dimensions)
vecty :
numpy array (len = n dimensions)
Returns
-------
""" """
return np.sqrt(sum(np.power(vectx - vecty, 2))) return np.sqrt(sum(np.power(vectx - vecty, 2)))
def format_str(string): def format_str(string):
""" """Convert str in bool, float, int or str
Convert str in bool, float, int or str
:param string: Parameters
:return: ----------
string :
return:
Returns
-------
""" """
if re.search(r"^\s*(true)\s*$", string, re.I): if re.search(r"^\s*(true)\s*$", string, re.I):
return True return True
...@@ -154,8 +211,15 @@ def format_str(string): ...@@ -154,8 +211,15 @@ def format_str(string):
def format_dict(indict): def format_dict(indict):
""" """
:param indict: Parameters
:return: ----------
indict :
return:
Returns
-------
""" """
for key in indict: for key in indict:
if isinstance(indict[key], str): if isinstance(indict[key], str):
...@@ -166,21 +230,39 @@ def format_dict(indict): ...@@ -166,21 +230,39 @@ def format_dict(indict):
def ppdict(indict, indent=2): def ppdict(indict, indent=2):
""" """
:param indict: Parameters
:param indent: ----------
:return: indict :
param indent:
indent :
(Default value = 2)
Returns
-------
""" """
return json.dumps(indict, indent=indent) return json.dumps(indict, indent=indent)
def tickmin(pandata, ntick=None, shift=0, offset=5): def tickmin(pandata, ntick=None, shift=0, offset=5):
""" """Minimise number of ticks labels for matplotlib or seaborn plot
Minimise number of ticks labels for matplotlib or seaborn plot
:param offset: Parameters
:param shift: ----------
:param pandata: pandas dataframe offset :
:param ntick: number of ticks wanted per axes param shift: (Default value = 5)
:return: 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))] yticks = [_ + shift for _ in range(0, len(pandata.index))]
xticks = [_ + shift for _ in range(0, len(pandata.columns))] xticks = [_ + shift for _ in range(0, len(pandata.columns))]
...@@ -206,14 +288,25 @@ def tickmin(pandata, ntick=None, shift=0, offset=5): ...@@ -206,14 +288,25 @@ def tickmin(pandata, ntick=None, shift=0, offset=5):
def tickrot(axes, figure, rotype='horizontal', xaxis=True, yaxis=True): def tickrot(axes, figure, rotype='horizontal', xaxis=True, yaxis=True):
""" """Matplot rotation of ticks labels
Matplot rotation of ticks labels
:param axes: Parameters
:param figure: ----------
:param rotype: axes :
:param xaxis: param figure:
:param yaxis: rotype :
:return: param xaxis: (Default value = 'horizontal')
yaxis :
return: (Default value = True)
figure :
xaxis :
(Default value = True)
Returns
-------
""" """
if yaxis: if yaxis:
art.setp(axes.get_yticklabels(), rotation=rotype) art.setp(axes.get_yticklabels(), rotation=rotype)
...@@ -224,6 +317,7 @@ def tickrot(axes, figure, rotype='horizontal', xaxis=True, yaxis=True): ...@@ -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 # TODO: Add another level when we use verbose options instead of displaying debug messages
class CustomLogging(object): class CustomLogging(object):
""" """
# default_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), # default_file = os.path.join(os.path.abspath(os.path.dirname(__file__)),
# "conf/logging.json") # "conf/logging.json")
""" """
...@@ -249,8 +343,15 @@ class CustomLogging(object): ...@@ -249,8 +343,15 @@ class CustomLogging(object):
def update_msg(self, desc): def update_msg(self, desc):
""" """
:param desc: Parameters
:return: ----------
desc :
return:
Returns
-------
""" """
if isinstance(self.msg, list): if isinstance(self.msg, list):
self.msg += desc self.msg += desc
...@@ -259,10 +360,7 @@ class CustomLogging(object): ...@@ -259,10 +360,7 @@ class CustomLogging(object):
self.msg = " - ".join((self.msg, desc.capitalize())) self.msg = " - ".join((self.msg, desc.capitalize()))
def default_config(self): def default_config(self):
""" """:return:"""
:return:
"""
# with open(self.default_file, 'rt') as f: # with open(self.default_file, 'rt') as f:
conf = pkgr.resource_stream(__name__, self.default_file).read().decode() conf = pkgr.resource_stream(__name__, self.default_file).read().decode()
config = json.loads(conf) config = json.loads(conf)
...@@ -270,10 +368,17 @@ class CustomLogging(object): ...@@ -270,10 +368,17 @@ class CustomLogging(object):
return config return config
def set_outdir(self, outdir): def set_outdir(self, outdir):
""" """Create log directory and change log files location
Create log directory and change log files location
:param outdir: path output directory Parameters
:return: ----------
outdir :
path output directory
Returns
-------
""" """
outdir = os.path.join(outdir, outdir = os.path.join(outdir,
"log") if "log" not in outdir else outdir "log") if "log" not in outdir else outdir
...@@ -295,10 +400,7 @@ class CustomLogging(object): ...@@ -295,10 +400,7 @@ class CustomLogging(object):
logging.config.dictConfig(self.config) logging.config.dictConfig(self.config)
def welcome(self): def welcome(self):
""" """:return:"""
:return:
"""
desc = ''' desc = '''
================================================================================ ================================================================================
...@@ -315,9 +417,7 @@ class CustomLogging(object): ...@@ -315,9 +417,7 @@ class CustomLogging(object):
class Capturing(list): class Capturing(list):
""" """Capture output"""
Capture output
"""
def __enter__(self): def __enter__(self):
""" """
...@@ -344,9 +444,7 @@ class Capturing(list): ...@@ -344,9 +444,7 @@ class Capturing(list):
class RedirectStdStreams(object): class RedirectStdStreams(object):
""" """Redirect standard ouput and errors"""
Redirect standard ouput and errors
"""
def __init__(self, stdout=None, stderr=None): def __init__(self, stdout=None, stderr=None):
self._stdout = stdout or sys.stdout self._stdout = stdout or sys.stdout
self._stderr = stderr or sys.stderr self._stderr = stderr or sys.stderr
...@@ -366,9 +464,7 @@ class RedirectStdStreams(object): ...@@ -366,9 +464,7 @@ class RedirectStdStreams(object):
class CommandProtocol(object): class CommandProtocol(object):
""" """Abstract class for subcommand protocol"""
Abstract class for subcommand protocol
"""
__metaclass__ = ABCMeta __metaclass__ = ABCMeta
def __init__(self, settings): def __init__(self, settings):
...@@ -376,29 +472,35 @@ class CommandProtocol(object): ...@@ -376,29 +472,35 @@ class CommandProtocol(object):
@abstractmethod @abstractmethod
def run(self): def run(self):
""" """main method to launch protocol
main method to launch protocol
:return: :return:
Parameters
----------
Returns
-------
""" """
raise NotImplementedError raise NotImplementedError
class NotDisordered(Select): class NotDisordered(Select):
""" """Define an atom as disordered or not in pdb selection"""
Define an atom as disordered or not in pdb selection