Commit 0db97d48 authored by Fabrice  ALLAIN's avatar Fabrice ALLAIN
Browse files

Added configuration file converter

parent e9599c1a
......@@ -6,6 +6,7 @@ build/
dist/
*.egg-info/
.eggs/
docs.old*
docs/_static/
docs/_templates/
.svn/
......
......@@ -5,7 +5,7 @@
A software for automated NOE assignment
Version 2.3
Version 2.4
===============================================================================
......@@ -43,15 +43,12 @@ structure calculation. Bioinformatics 23:381-382
Contents:
1. What's new in version 2.3 ?
1. What's new in version 2.4 ?
1.1 Support of CCPNMR version 2
1.2 Symmetric oligomers (C3, C5 and D2)
1.3 Log-harmonic potential for distance restraints (Nilges et al. Structure, 2008)
1.4 Import of CCPN Models/Structure Ensembles
1.5 Zinc ions coordination
1.6 Automated Molprobilty clashlist analysis
1.7 Old aria1.x features added
1.1 Potential of Mean Forces for dihedral angles () and H-bonds ()
1.2 Clustering step during the iterative process
1.3 Extended scoring function including PMF, coulombic and full Lennard Jones functions
1.4 Restraints generation from evolutionary couplings and secondary structure prediction
2. Installation
......@@ -98,7 +95,7 @@ Contents:
(go to "Add > Zinc Coordination")
- Automated Molprobilty (clashlist) analysis
(go to "Analyses > Molprobity Classhlist")
(go to "Analyses > Molprobity Clashlist")
- addition of old aria1.x features (keep_structures, only fully assigned peaks)
......
This diff is collapsed.
......@@ -1043,7 +1043,6 @@ def run_aria(project_file, log_file=None, debug=0, test_commands=1,
# is turned of once a project has been set up.
Settings.Path.global_mandatory = 0
project = load_project(project_file)
project.check(test_commands)
......
......@@ -12,7 +12,8 @@ from . import __doc__
from .common import format_dict, CustomLogging
from .settings import AriaEcSettings
from .maplot import AriaEcContactMap
from .converter import AriaEcBbConverter, AriaEcXMLConverter
from .converter import AriaEcBbConverter, AriaEcXMLConverter, \
AriaEcConfigConverter
from .setup import AriaEcSetup
from .pdbqual import AriaEcPdbqual
from .pdbdist import PDBDist
......@@ -69,7 +70,7 @@ class AriaEcCommands(object):
"""Argparse interface for aria_ec"""
command_list = ("setup", "bbconv", "maplot", "pdbqual", "analysis",
"tbl2xml", "pdbdist", "pdbstat")
"tbl2xml", "pdbdist", "pdbstat", "iniconv")
desc_list = (u"Setup ARIA infrastructure with contact maps translated "
u"into ARIA restraints",
u"Convert a contact map in bbcontact format",
......@@ -78,7 +79,8 @@ class AriaEcCommands(object):
u"Extended ARIA ensemble analysis on a specific iteration ",
u"XML converter for tbl distance restraint",
u"Extract distance distribution from culled list of pdb files",
u"Analyze distance distribution with GMM, ...")
u"Analyze distance distribution with GMM",
u"Convert configuration files into a unique csv file")
contact_types = ("evfold", "plmev", "plm", "plmdca", "plmc", "bbcontacts",
"pconsc", "pconsc1", "pconsc2", "psicov", "metapsicovhb",
"metapsicov_stg1", "metapsicov_stg2", "gremlin", "pdb",
......@@ -119,9 +121,9 @@ class AriaEcCommands(object):
log.welcome()
def _create_argparser(self):
""" """
parser = argp.ArgumentParser(description=__doc__,
formatter_class=argp.ArgumentDefaultsHelpFormatter)
parser = argp.ArgumentParser(
description=__doc__,
formatter_class=argp.ArgumentDefaultsHelpFormatter)
parser.add_argument("-o", "--output", dest="output_directory",
type=str, help="Output directory", required=True)
parser.add_argument("-c", "--conf", action=ReadableFile,
......@@ -179,7 +181,7 @@ class AriaEcCommands(object):
help="sequence file [FASTA]")
# group.add_argument("sspred", action=ReadableFile,
# help="secondary structure prediction file")
group.add_argument("infiles", nargs="+", metavar="infile",
group.add_argument("infiles", nargs="*", metavar="infile",
action=ReadableFile,
help="contact or pdb file(s) used to build aria "
"distance restraints")
......@@ -195,8 +197,8 @@ class AriaEcCommands(object):
action=ReadableFile,
help="ARIA project file. This file will be used as"
"an initialization file if")
group.add_argument("-t", "--type", required=True,
nargs="+", dest="contact_types",
group.add_argument("-t", "--type",
nargs="*", dest="contact_types",
choices=self.contact_types, help="Infile(s) contact "
"type(s)")
group.add_argument("-r", "--ref", dest="ref",
......@@ -244,6 +246,28 @@ class AriaEcCommands(object):
"type")
return parser
@staticmethod
def _iniconv_argparser(desc=None):
"""
iniconv opt & args
Parameters
----------
desc :
command descriptor (Default value = None)
Returns
-------
"""
parser = argp.ArgumentParser(description=desc,
add_help=False)
# args
parser.add_argument("confiles", nargs='+',
type=str, help="config files")
return parser
def _maplot_argparser(self, desc=None):
"""
maplot opt & args
......@@ -454,26 +478,26 @@ class AriaEcCommands(object):
if self.args.verbose:
LOG.info("Toggle on debug mode")
logging.getLogger().setLevel(logging.DEBUG)
LOG.debug("Create AriaEcSettings")
LOG.info("Initialize settings")
settings = AriaEcSettings(self.args.command)
LOG.info("Loading default config file")
LOG.debug("Loading default config file")
settings.load_config(self.default_confile, pkg=True)
if self.args.conf_file:
LOG.info("Updating settings with conf file")
LOG.info("Updating settings according to config file")
settings.load_config(self.args.conf_file)
# Update settings associated to command section
LOG.info("Updating %s args settings", self.args.command)
LOG.debug("Updating %s args settings", self.args.command)
LOG.debug(self.args.__dict__)
getattr(settings, self.args.command).args.update(format_dict(self.args.__dict__))
LOG.debug(getattr(settings, self.args.command).args)
if self.args.output_directory:
LOG.info("Updating output directory %s", self.args.output_directory)
LOG.debug("Output directory: %s", self.args.output_directory)
settings.infra = self.args.output_directory
return settings
def run(self):
"""call method relative to args.command"""
LOG.info("Run %s command", self.args.command)
LOG.debug("Run %s command", self.args.command)
getattr(self, self.args.command)()
def setup(self):
......@@ -516,6 +540,10 @@ class AriaEcCommands(object):
inst = EnsembleAnalysis(self.create_settings())
inst.run()
def iniconv(self):
inst = AriaEcConfigConverter(self.create_settings())
inst.run()
def main():
"""Launch ariaec command interface"""
......
......@@ -17,7 +17,6 @@ import pickle
import pkg_resources as pkgr
import random
import re
import sys
import textwrap
from ..core.AriaXML import AriaXMLPickler
from ..core.ConversionTable import ConversionTable
......@@ -36,6 +35,7 @@ from .common import get_filename, TqdmToLogger
from .protein import Protein
from .protmap import (ResAtmMap, ResMap, SsAaAtmMap)
from .reader import MapFileListReader, TblDistFile
from .settings import AriaEcSettings
LOG = logging.getLogger(__name__)
......@@ -1818,3 +1818,99 @@ class AriaEcXMLConverter(AriaXMLConverter):
list_name = self.settings.tbl2xml.args["listname"]
self.tbl2xml(outdir_path, molecule_path, tbl_paths, list_name)
class AriaEcConfigConverter(object):
OUTFILE = "configs.csv"
def __init__(self, settings):
self.settings = settings
@staticmethod
def formatcell(value):
"""
Format value in order to save it into a panda dataframe
Parameters
----------
value: object
Instance which has to be saved into a unique pandas cell
Returns
-------
value: object
Instance compatible to value of ONE cell
"""
if isinstance(value, list):
return ';'.join(value)
elif value is None:
return np.NaN
else:
return value
def conftodf(self, path=None):
"""
Convert config file into panda dataframe
Parameters
----------
path: str
Path to the config file
Returns
-------
config: pd.Dataframe object
pandas dataframe with all options saved as a 1xn matrix
(n corresponding to the number of columns)
"""
conf = AriaEcSettings('config')
conf.load_config(path)
columns = ['config']
row = [
os.path.splitext(os.path.basename(path))[0] if path else "default"]
for section in conf.SECTIONS:
tmpcols = getattr(getattr(conf, section), 'config').keys()
columns += tmpcols
row += [self.formatcell(
getattr(getattr(conf, section), 'config')[key])
for key in tmpcols]
confdf = pd.DataFrame([row], columns=columns)
return confdf
def confstodf(self, paths):
"""
Read several config files and convert them into a unique pandas
dataframe
Parameters
----------
paths: list
list of config files
Returns
-------
maindf: pd.Dataframe object
"""
maindf = None
for i, path in enumerate(paths):
df = self.conftodf(path)
maindf = pd.merge(maindf, df, how='outer', on='config') \
if i != 0 else df
return maindf
def run(self):
"""
Fetch config files and convert them into a unique csv file
"""
confiles = [None] + [confile for confile in
self.settings.iniconv.args.get("confiles")]
LOG.info("Reading configuration file(s)")
configs = self.confstodf(confiles)
LOG.info("Generate output csv file (%s)", self.OUTFILE)
configs.to_csv(
os.path.join(self.settings.iniconv.args.get("output_directory"),
self.OUTFILE)
if os.path.exists(
self.settings.iniconv.args.get("output_directory"))
else self.OUTFILE, index=False)
......@@ -116,7 +116,8 @@ class Settings(object):
return "<Settings object>\n sections: %s" % self._sections
# TODO: AriaEcSettings should probably be an astract class.
# TODO: AriaEcSettings should be an astract class. Sections are actually
# duplicated with AriaEcCommands
class AriaEcSettings(Settings):
"""
Settings object for ariaec
......@@ -127,6 +128,7 @@ class AriaEcSettings(Settings):
# TODO: move these constant variable in objects which can read these file !!
# TODO: Baseclass inspired from this class and ariabase class. All
# objects in this package should extend the base object
DEFAULT_CONFIG = "conf/config.ini"
ARIAPROJ_TEMPLATE = 'templates/aria_project_v2.3.0.xml'
SS_DIST = 'data/ss_dist.txt'
SCSC_MIN = 'data/scsc_min.p'
......@@ -141,7 +143,8 @@ class AriaEcSettings(Settings):
# TODO: Should define sections in one object, actually we have to define
# sections in settings and also command objects ...
SECTIONS = ("main", "setup", "maplot", "bbconv", "contactdef",
"pdbqual", "pdbdist", "analysis", "tbl2xml", "pdbstat")
"pdbqual", "pdbdist", "analysis", "tbl2xml", "pdbstat",
"iniconv")
# TODO: options in main section should be accessible from all sections ! DO
# not use this a other section as it is done actually
......@@ -296,7 +299,7 @@ class AriaEcSettings(Settings):
if not os.path.exists(self.infra[direct]):
os.makedirs(os.path.abspath(self.infra[direct]))
def load_config(self, configpath, **kwargs):
def load_config(self, configpath=None, **kwargs):
"""
......@@ -312,7 +315,11 @@ class AriaEcSettings(Settings):
"""
super(AriaEcSettings, self).load_config(configpath, **kwargs)
if configpath:
super(AriaEcSettings, self).load_config(configpath, **kwargs)
else:
super(AriaEcSettings, self).load_config(
self.DEFAULT_CONFIG, pkg=True)
def __getitem__(self, item):
for section in self._sections:
......
......@@ -285,8 +285,8 @@ class Job(Thread, AriaBaseClass):
d['check_script'] = os.path.basename(d['check_script'])
command = self.cmd_template % d
msg = 'Starting job %s'
self.message(msg % job_desc)
# msg = 'Starting job %s'
# self.message(msg % job_desc)
self.debug(command)
process = subprocess.Popen(command, shell=True,
......@@ -331,11 +331,15 @@ class Job(Thread, AriaBaseClass):
time.sleep(5.)
if retcode or checkcode:
error = subprocess.CalledProcessError(
retcode, command.split(), output=out) if retcode else \
subprocess.CalledProcessError(checkcode, checkcmd.split(),
output=out)
self.error(str(error))
therror = subprocess.CalledProcessError(
returncode=retcode,
cmd=command,
output=out) if retcode else \
subprocess.CalledProcessError(
returncode=checkcode,
cmd=checkcmd,
output=out)
self.error(msg=str(therror))
# Remove if exists updated checkpoint script
try:
......@@ -344,9 +348,9 @@ class Job(Thread, AriaBaseClass):
pass
if not self.isStopped() and terminated and checkpoint:
self.message('Job "%s" completed.' % job_desc)
self.message('Job %s completed.' % job_desc)
else:
self.debug('Job "%s" has been canceled.\n' % job_desc)
self.debug('Job %s has been canceled.\n' % job_desc)
self.debug('%s' % command)
# notify that we are done.
......
......@@ -1534,7 +1534,6 @@ class Project(AriaBaseClass):
return iteration
def load_and_preprocess_data(self):
self.read_data()
self.preprocess_data()
......
......@@ -812,7 +812,6 @@ class Protocol(AriaBaseClass):
"""
from .Singleton import ProjectSingleton
if kept_structures is None:
kept_structures = []
......@@ -2275,7 +2274,7 @@ class Protocol(AriaBaseClass):
#
# set spectrum-specific parametes for Calibrator
# TODO [FALLAIN]: User ERROR with wml distance files
# TODO [FALLAIN]: User ERROR with xml distance files
self._updateSpectrumSettings(spectrum)
if ensemble is None:
......
......@@ -27,7 +27,6 @@ $Date: 2010/03/23 15:27:24 $
"""
from .ariabase import AriaBaseClass
from .Topology import TYPE_AMINO_ACID, TYPE_DNA_BASE, TYPE_RNA_BASE, \
TERMINUS_N_STANDARD, TERMINUS_C_STANDARD, TERMINUS_N_AMINYL, \
......@@ -45,7 +44,6 @@ if ccpn_path not in sys.path: sys.path.insert(0, ccpn_path)
# TODO [FALLAIN] ccpn in ccpnmr package ?
# noinspection PyUnresolvedReferences
from ccpn.Global import false
import ccpn.Api as api
......
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = AriaEc
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
\ No newline at end of file
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: cbf8f1a8c4c0d68994ae9bd4f214590d
tags: 645f666f9bcd5a90fca523b33c5a78b7
Markdown is supported
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