Commit 6767d22c authored by Fabrice Allain's avatar Fabrice Allain
Browse files

Updated to python 3.5 syntax

parent b1e477c7
No preview for this file type
......@@ -13,7 +13,7 @@ import sys
import numpy as np
import pkg_resources as pkgr
import matplotlib.artist as art
from cStringIO import StringIO
from io import StringIO
logger = logging.getLogger()
......@@ -289,10 +289,8 @@ class Capturing(list):
sys.stdout = self._stringio = StringIO()
return self
def __exit__(self, *args):
def __exit__(self,):
"""
:param args:
:return:
"""
self.extend("\n".join(self._stringio.getvalue().splitlines()))
......
No preview for this file type
......@@ -27,6 +27,9 @@ def check_file(prospective_file):
class ReadableFile(argp.Action):
def __init__(self, *args, **kwargs):
super(ReadableFile, self).__init__(*args, **kwargs)
def __call__(self, parser, namespace, values, option_string=None):
if type(values) == list:
for prospective_file in values:
......
No preview for this file type
......@@ -13,7 +13,6 @@ import os
import sys
import json
import re
import pkg_resources as pkgr
import aria.legacy.AminoAcid as AminoAcid
from .base import get_filename, Capturing
from .protein import Protein
......@@ -307,7 +306,7 @@ assign (resid {res1} and name o) (resid {res2} and name hn) 1.8 {dminus} {dplus
# Build global secondary structure distance restraints (H-H+4, E-E+1,
# ...)
with open(outfile, 'w') as outfile:
for a in xrange(len(sec_struct) - 1):
for a in range(len(sec_struct) - 1):
for b in range(a + 1, len(sec_struct)):
ss1 = sec_struct[a][2]
ss2 = sec_struct[b][2]
......@@ -331,7 +330,7 @@ assign (resid {res1} and name {atm1}) (resid {res2} and name {atm2}) {dist} {sd
def write_dihedral_tbl(sec_struct, outfile, k=0.5, e=2):
# Build dihedral angle restraints (phi, psi)
with open(outfile, "w") as outfile:
for i in xrange(len(sec_struct)):
for i in range(len(sec_struct)):
if (i + 1) != len(sec_struct):
if sec_struct[i][2] == sec_struct[i + 1][2]:
# Si ss identique
......@@ -396,6 +395,12 @@ assign (resid {res1} and name n) (resid {res1} and name ca) (resid {res1} and na
class AriaEcXMLConverter(AriaXMLConverter):
@staticmethod
def _write_hbmap_tbl(hbmap, outfile, dminus, dplus, n_hb=None, hb_type="main", topo=None):
AriaXMLConverter._write_hbmap_tbl(hbmap, outfile, dminus, dplus, n_hb=None, hb_type="main",
topo=None)
def __init__(self, *args, **kwargs):
self.restraint_list = []
super(AriaEcXMLConverter, self).__init__(*args, **kwargs)
......@@ -711,7 +716,7 @@ class AriaEcXMLConverter(AriaXMLConverter):
self._pickler.dump(self.molecule, self._mol_set[
'output'])
except Exception, msg:
except Exception as msg:
logger.error("Error writing xml seq file : %s" % msg)
......@@ -732,7 +737,7 @@ class AriaEcXMLConverter(AriaXMLConverter):
templatepath = os.path.abspath(aria_template)
ariaproj_template = Template(filename=templatepath,
module_directory="/tmp/mako_modules")
module_directory="/tmp/mako_modules")
try:
t = open(templatepath, 'r')
......
No preview for this file type
......@@ -5,9 +5,9 @@ from __future__ import absolute_import, division, print_function
import logging
import os
import ConfigParser
from configparser import SafeConfigParser
import collections
import cPickle as Pickle
import pickle
import pkg_resources as pkgr
from .base import format_dict
......@@ -42,7 +42,7 @@ class Settings(object):
elif not pkg:
logger.error("Configuration file not found (%s)" % configpath)
return None
config = ConfigParser.SafeConfigParser(allow_no_value=True)
config = SafeConfigParser(allow_no_value=True)
if pkg:
with pkgr.resource_stream(__name__, configpath) as conf:
config.readfp(conf)
......@@ -62,7 +62,7 @@ class Settings(object):
def write_config(self, filename):
# Ecrit les config de toutes les sections dans un autre fichier
logger.info("Writing .ini file (%s)" % filename)
config = ConfigParser.SafeConfigParser(allow_no_value=True)
config = SafeConfigParser(allow_no_value=True)
iniout = open(filename, mode="w")
for section in self._sections:
config.add_section(section)
......@@ -151,12 +151,12 @@ class AriaEcSettings(Settings):
try:
# Read scsc_min_file given in aria_ec.ini
with open(self.main.config["scsc_min_file"]) as scsc:
scsc_min = Pickle.load(scsc)
scsc_min = pickle.load(scsc)
except (IOError, KeyError, TypeError):
# If file can't be open or given key is invalid, load default
# package file
with pkgr.resource_stream(__name__, self.SCSC_MIN) as scsc:
scsc_min = Pickle.load(scsc)
scsc_min = pickle.load(scsc)
scsc_min = dict(
(aa1, dict((aa2, tuple(atm_pair.split(', ')))
for aa2, atm_pair in atm_pairs.items()))
......
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -11,6 +11,7 @@ import logging
import pkg_resources as pkgr
import aria.legacy.SequenceList as SequenceList
import aria.legacy.AminoAcid as AmnAcd
from six import iteritems
from .base import (reg_load, Capturing, ppdict)
# import skbio.Protein as skprot
# TODO: interface skbio ??
......@@ -211,7 +212,7 @@ class SsList:
try:
with open(filename) as f:
self._read_ssdist(f, filename=filename)
except Exception, message:
except Exception as message:
logger.error("%s" % message)
logger.error("Can't load given ss dist file...")
logger.error("Loading default ss dist file")
......@@ -242,7 +243,7 @@ class SsList:
# TODO: read_dssp
class AminoAcidSequence(SequenceList.SequenceList):
class AminoAcidSequence(SequenceList.SequenceList, object):
startres_reg = re.compile(r"^\s*residue\s+(?P<name>[A-Za-z]{1,4})", flags=re.I)
end_reg = re.compile(r"^\s*end", flags=re.I)
......@@ -277,7 +278,7 @@ class AminoAcidSequence(SequenceList.SequenceList):
:param kwargs:
:return:
"""
SequenceList.SequenceList.__init__(self, *args, **kwargs)
super(AminoAcidSequence, self).__init__(*args, **kwargs)
self._topfile = topologyfile
self._topology = None
self._topok = False
......@@ -303,7 +304,7 @@ class AminoAcidSequence(SequenceList.SequenceList):
self._topology = [(aa, topo[aa]) for aa in self.aalist]
self._topok = True
else:
self._topology = list(topo.iteritems())
self._topology = list(iteritems(topo))
return self._topology
def __getitem__(self, key):
......@@ -324,7 +325,7 @@ class AminoAcidSequence(SequenceList.SequenceList):
def readtopo(self):
"""
Parse topology file for amino acids
:return:
"""
topo = {}
......@@ -346,24 +347,24 @@ class AminoAcidSequence(SequenceList.SequenceList):
resname = ""
continue
# Walk along reg dict
for regid, reg in self.restatement_reg.iteritems():
for regid, reg in iteritems(self.restatement_reg):
if regid not in topo[resname]:
topo[resname][regid] = []
if regid == "bond":
match = re.findall(reg, line)
if match:
topo[resname][regid] += match
break
else:
match = reg.search(line)
if match:
if regid not in topo[resname]:
topo[resname][regid] = []
if regid == "bond":
# Add 2-tuple
topo[resname][regid] += match
elif regid in ("improper", "dihedral"):
# Add tuple into list since we need atm order
topo[resname][regid].append(match.groups())
else:
# Add dict
topo[resname][regid].append(match.groupdict())
break
if match:
if regid in ("improper", "dihedral"):
# Add tuple into list since we need atm order
topo[resname][regid].append(match.groups())
else:
# Add dict
topo[resname][regid].append(match.groupdict())
break
logger.debug("Topology used:\n%s" % ppdict(topo))
return topo
......
No preview for this file type
......@@ -41,8 +41,11 @@ class Map(pd.DataFrame):
mtype_choices = {'contact': bool, 'distance': float, "score": float}
def _constructor_expanddim(self):
super(Map, self)._constructor_expanddim()
def update(self, *args, **kwargs):
super(Map, self).update(*args, **kwargs)
# def _constructor_expanddim(self):
# super(Map, self)._constructor_expanddim()
def __init__(self, index=None, columns=None, mtype='distance',
duplicate_levels=False, data=None, dtype=None, sym=True,
......@@ -660,7 +663,7 @@ class ResAtmMap(ProteinMap):
"the default cutoff)" % str(pair))
logger.info(
"Filtering values in matrix related to %s (%s)" %
(str(pair), str(treshold)))
(str(pair), str(treshold) if treshold else def_cutoff))
if pair in (("SC", "SC"), ("sc", "sc")):
# Use scsc_min to apply treshold updateonly for selected atom
# sidechain
......@@ -757,8 +760,8 @@ class AaMap(Map):
Amino Acid Distance Matrix
"""
def _constructor_expanddim(self):
super(AaMap, self)._constructor_expanddim()
# def _constructor_expanddim(self):
# super(AaMap, self)._constructor_expanddim()
def __init__(self, *args, **kwargs):
if ("humanidx", "columns") not in kwargs:
......@@ -781,8 +784,8 @@ class AtmMap(Map):
Atom Distance Matrix
"""
def _constructor_expanddim(self):
super(AtmMap, self)._constructor_expanddim()
# def _constructor_expanddim(self):
# super(AtmMap, self)._constructor_expanddim()
def __init__(self, *args, **kwargs):
super(AtmMap, self).__init__(*args, **kwargs)
......@@ -1037,7 +1040,7 @@ class MapFilter:
ss_start_end = collections.defaultdict(lambda: [None, None])
# TODO: deplacer construction du dic ss_start_end dans SsList
for res_ind in xrange(len(ss_matrix)):
for res_ind in range(len(ss_matrix)):
# Construction du dict ss_start_end
if res_ind == 0:
# If first residue
......@@ -1082,7 +1085,7 @@ class MapFilter:
for n in (1, 2, 3, 4):
# Search type of the bond (H-1 H, E-2 E, ...)
for i in xrange(2):
for i in range(2):
# Test both sides
resi = contact[i]
......@@ -1331,8 +1334,7 @@ class MapFilter:
else:
op = "added"
ctype = clash
meta_clash[clash_t]["warn"] += "\n/!\ Clash: {clash_desc} {" \
"clash} flag for contact " \
meta_clash[clash_t]["warn"] += "\n/!\ Clash: {clash_desc} {clash} flag for contact " \
"{res_pos} ({res1}, {res2})".format(
clash_desc=op, clash=ctype, res_pos=icontact + 1,
res1=contact[0], res2=contact[1])
......
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -97,7 +97,7 @@ setup(
'seaborn',
'scipy',
'sklearn',
'colorlog',
'colorlog', 'mako',
# 'scikit-bio==0.4.0',
# 'aria==2.3'
],
......
# Do not edit this file, pipeline versioning is governed by git tags
__version__=v0.1.11-dev2-8-g4239f50
\ No newline at end of file
__version__=v0.1.11-dev2-16-gb1e477c
\ No newline at end of file
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