Commit 74bee780 authored by Fabrice  ALLAIN's avatar Fabrice ALLAIN
Browse files

Refactored some parts in conbox + beginning of seqrange option

parent 3441970c
......@@ -49,6 +49,14 @@ def check_file(prospective_file):
"file".format(prospective_file))
def seqrange_type(s):
try:
x, y = map(int, s.split('-'))
return x, y
except:
raise argp.ArgumentTypeError("Sequence indexes must be start-end")
class ReadableFile(argp.Action):
"""Class used with argparse action to check if a file is readable"""
......@@ -128,7 +136,6 @@ class AriaEcCommands(object):
LOG.removeHandler("debug_file_handler")
log.set_outdir(self.args.output_directory)
log.update_msg(self.args.command)
log.welcome()
def _create_argparser(self):
parser = argp.ArgumentParser(
......@@ -211,7 +218,11 @@ class AriaEcCommands(object):
nargs="*", dest="contact_types",
choices=self.contact_types, help="Infile(s) contact "
"type(s)")
group.add_argument("-r", "--ref", dest="ref",
group.add_argument("-r", "--range", dest="seqrange", default=(1, -1),
help="Index range if we don't want tu use the whole "
"sequence and map",
type=seqrange_type)
group.add_argument("-n", "--native", dest="ref",
help="Native pdb. Allow TP/FP detection.")
group.add_argument("--hb", dest="hb",
help="H-bonds contact file (eg: metapsicov.hb)")
......
......@@ -446,6 +446,7 @@ class CustomLogging(object):
else:
self.msg = ""
self.config = self.default_config()
self.welcome()
def update_msg(self, desc):
"""
......@@ -524,6 +525,8 @@ class CustomLogging(object):
with open(self.config["handlers"][hand]["filename"],
'w') as outfile:
outfile.write(desc)
elif hand == "console":
print(desc)
class Capturing(list):
......
......@@ -144,6 +144,7 @@ class AriaXMLConverter(Converter, object):
self._pickler = AriaXMLPickler()
self._molecule = None
self._upflag = False
self._sequence = None
self.outprefix = ""
self.settings = settings
self.structure = None
......@@ -170,6 +171,10 @@ class AriaXMLConverter(Converter, object):
else:
return self._molecule
@property
def sequence(self):
return self._sequence
@staticmethod
def upd_mol(molecule, structure):
"""
......@@ -226,12 +231,12 @@ class AriaXMLConverter(Converter, object):
for segid in segids:
chain_types[segid] = self._mol_set['type']
sequence = SequenceList(chain_types,
self._sequence = SequenceList(chain_types,
self._mol_set['first_residue_number'])
# with Capturing() as output:
# Initialize SequenceList object with seq file
sequence.parse(self._mol_set['input'], self._mol_set['format'],
self._sequence.parse(self._mol_set['input'], self._mol_set['format'],
self._mol_set['naming_convention'])
# LOG.info("\n" + "".join(output))
......@@ -243,7 +248,7 @@ class AriaXMLConverter(Converter, object):
factory.unfreeze()
# Create chains in SequenceList object with aria atom factory
chains = sequence.create_chains(factory)
chains = self._sequence.create_chains(factory)
# Instantiate aria molecule object
self._molecule = Molecule(self._mol_set['name'])
......@@ -1455,7 +1460,7 @@ class AriaEcXMLConverter(AriaXMLConverter):
out[1].append(pairlist)
return out
def write_tbl_restraints(self, protein, hbmap=None, n_hb=None):
def write_tbl_restraints(self, protein, hbmap=None):
"""
Write tbl restraints
......@@ -1471,6 +1476,9 @@ class AriaEcXMLConverter(AriaXMLConverter):
dict
{'hbond': hb_file, 'dihed': dihed_file, 'ssdist': ssdist_file}
"""
# Setting contact number limit for hbmap
n_hb = int(len(self.sequence.bases) *
self.settings.setup.config.get("nf_longrange_hb"))
dihed_file = os.path.join(self.settings.infra["tbl"], self.outprefix +
"_dihed.tbl")
hb_file = os.path.join(self.settings.infra["tbl"], self.outprefix +
......
......@@ -14,6 +14,7 @@ import pkg_resources as pkgr
import re
import sys
from six import iteritems, text_type
from copy import copy
from ..core.legacy import AminoAcid as AmnAcd
from .common import (reg_load, ppdict)
......@@ -586,10 +587,9 @@ class AminoAcidSequence(SequenceList.SequenceList, object):
self.ReadSeq(text_type(filename))
else:
self.ReadFasta(text_type(filename))
# LOG.info(''.join(output))
self.sequence = "".join((AmnAcd.AminoAcid(str(_))[0] for _ in
self.aalist))
self.sequence = "".join(
(AmnAcd.AminoAcid(str(_))[0]
for _ in self.aalist))
LOG.info("Amino acid sequence:\t%s", self.sequence)
......@@ -647,7 +647,7 @@ class Protein(object):
def set_aa_sequence(self, filename, ssidx=False):
"""
Save the amino acid sequence
Parameters
----------
......@@ -663,6 +663,7 @@ class Protein(object):
"""
self.aa_sequence.read(filename)
self.index = range(1, len(self.aa_sequence.sequence) + 1)
LOG.debug("Index: %s", self.index)
if self.sec_struct.ss_matrix:
self.sec_struct.seq_sublist(self.aa_sequence.sequence)
if ssidx:
......@@ -710,7 +711,7 @@ class Protein(object):
self.index = self.sync_index(self.aa_sequence.humanidx,
self.sec_struct.index)
def write_seq(self, outfile):
def write_seq(self, outfile, seqrange=(1, -1)):
"""
......@@ -726,7 +727,10 @@ class Protein(object):
"""
# TODO: same as above, trouble with unicode calls inside capturing
# with Capturing() as output:
self.aa_sequence.WriteSeq(text_type(outfile))
seq = copy(self.aa_sequence)
seq.aalist = seq.aalist[seqrange[0] - 1: seqrange[1]] \
if seqrange[1] != -1 else seq.aalist[seqrange[0] - 1:]
seq.WriteSeq(text_type(outfile))
self.seqfile_path = '%s' % outfile
......
......@@ -66,7 +66,8 @@ class AriaEcSetup(object):
self.outprefix = get_filename(self.settings.setup.args.get("seq", ""))
self.converter.outprefix = self.outprefix
# ------------------------- Load sequence ---------------------------- #
self.protein.set_aa_sequence(self.settings.setup.args.get("seq", None))
self.protein.set_aa_sequence(
self.settings.setup.args.get("seq", None))
# -------------- Load secondary structure prediction ----------------- #
if self.settings.setup.args.get("sspred", None):
self.protein.set_sec_struct(self.settings.setup.args.get("sspred",
......@@ -147,6 +148,11 @@ class AriaEcSetup(object):
# ------------------------------ Output ------------------------------ #
# ----------------------------- SEQ file ----------------------------- #
seqrange = self.settings.setup.args.get("seqrange")
# TODO: make seqrange functionnal
# self.protein.write_seq(
# os.path.join(self.settings.infra.get("etc", ''),
# self.outprefix + ".seq"), seqrange=seqrange)
self.protein.write_seq(
os.path.join(self.settings.infra.get("etc", ''),
self.outprefix + ".seq"))
......@@ -154,12 +160,10 @@ class AriaEcSetup(object):
LOG.info("Load molecule file and convert it into xml format")
self.converter.read_seq(self.protein.seqfile_path)
# --------------------------- TBL restraints ------------------------- #
# Setting contact number limit for hbmap
n_hb = int(len(self.protein.aa_sequence.sequence) *
self.settings.setup.config.get("nf_longrange_hb"))
LOG.info("Writing tbl files ...")
tbl_files = self.converter.write_tbl_restraints(
self.protein, hbmap=self.hbmaps, n_hb=n_hb)
self.protein, hbmap=self.hbmaps)
# --------------------------- XML restraints ------------------------- #
# Setting contact number limit for map restraints (native, ec, ...)
......@@ -171,9 +175,9 @@ class AriaEcSetup(object):
xmlseq_file = self.converter.write_xmlseq()
# ---------------------- ARIA XML project file ----------------------- #
self.converter.write_ariaproject(self.settings.template,
xmlseq_file, dist_files, tbl_files,
desclist=self.allresmap.keys())
self.converter.write_ariaproject(
self.settings.template, xmlseq_file, dist_files, tbl_files,
desclist=self.allresmap.keys())
# -------------------------------- etc ------------------------------- #
self.write_optional_files()
......
......@@ -671,7 +671,6 @@ class Settings(UserDict, AriaBaseClass):
self.update(default_settings)
for key, value in self.create_default_values().items():
print(key, value)
entity = self.getEntity(key)
entity.set_default_value(value)
......
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