use pkg_resources to access bundled files
* egg file can remain zipped * see http://peak.telecommunity.com/DevCenter/PythonEggs#accessing-package-resources for details
This commit is contained in:
@@ -4,6 +4,7 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import pickle,sys,os,math,propka.calculations
|
import pickle,sys,os,math,propka.calculations
|
||||||
|
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
class bondmaker:
|
class bondmaker:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -26,8 +27,7 @@ class bondmaker:
|
|||||||
self.max_sq_distance = max(list(self.distances_squared.values())+[self.default_dist_squared])
|
self.max_sq_distance = max(list(self.distances_squared.values())+[self.default_dist_squared])
|
||||||
|
|
||||||
# protein bonding data
|
# protein bonding data
|
||||||
path = os.path.split(__file__)[0]
|
self.data_file_name = pkg_resources.resource_filename(__name__, 'protein_bonds.dat')
|
||||||
self.data_file_name = os.path.join(path,'protein_bonds.dat')
|
|
||||||
|
|
||||||
data = open(self.data_file_name,'rb')
|
data = open(self.data_file_name,'rb')
|
||||||
self.protein_bonds = pickle.load(data)
|
self.protein_bonds = pickle.load(data)
|
||||||
|
|||||||
@@ -1,23 +1,24 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
|
|
||||||
from __future__ import division
|
from __future__ import division
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import string, sys, copy, math, os
|
import string, sys, copy, math, os
|
||||||
|
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
#
|
#
|
||||||
# file I/O
|
# file I/O
|
||||||
#
|
#
|
||||||
def open_file_for_reading(filename):
|
def open_file_for_reading(filename):
|
||||||
if not os.path.isfile(filename):
|
try:
|
||||||
|
f = open(filename,'r')
|
||||||
|
except:
|
||||||
raise Exception('Cannot find file %s' %filename)
|
raise Exception('Cannot find file %s' %filename)
|
||||||
|
return f
|
||||||
return open(filename,'r')
|
|
||||||
|
|
||||||
def open_file_for_writing(filename):
|
def open_file_for_writing(filename):
|
||||||
res = open(filename,'w')
|
try:
|
||||||
if not res:
|
res = open(filename,'w')
|
||||||
|
except:
|
||||||
raise Exception('Could not open %s'%filename)
|
raise Exception('Could not open %s'%filename)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@@ -102,8 +103,8 @@ def loadOptions():
|
|||||||
help="specifying mutation labels which is used to modify <filename> according to, e.g. N25R/N181D")
|
help="specifying mutation labels which is used to modify <filename> according to, e.g. N25R/N181D")
|
||||||
parser.add_option("-v", "--version", dest="version_label", default="Jan15",
|
parser.add_option("-v", "--version", dest="version_label", default="Jan15",
|
||||||
help="specifying the sub-version of propka [Jan15/Dec19]")
|
help="specifying the sub-version of propka [Jan15/Dec19]")
|
||||||
parser.add_option("-p", "--parameters",dest="parameters", default="propka.cfg",
|
parser.add_option("-p", "--parameters",dest="parameters", default=pkg_resources.resource_filename(__name__, "propka.cfg"),
|
||||||
help="set the parameter file")
|
help="set the parameter file [%default]")
|
||||||
parser.add_option("-z", "--verbose", dest="verbose", action="store_true", default=True,
|
parser.add_option("-z", "--verbose", dest="verbose", action="store_true", default=True,
|
||||||
help="sleep during calculations")
|
help="sleep during calculations")
|
||||||
parser.add_option("-q", "--quiet", dest="verbose", action="store_false",
|
parser.add_option("-q", "--quiet", dest="verbose", action="store_false",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import math
|
|||||||
import propka.lib as lib
|
import propka.lib as lib
|
||||||
import sys, os
|
import sys, os
|
||||||
|
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
# names and types of all key words in configuration file
|
# names and types of all key words in configuration file
|
||||||
matrices = ['interaction_matrix']
|
matrices = ['interaction_matrix']
|
||||||
@@ -57,8 +58,7 @@ class Parameters:
|
|||||||
def read_parameters(self, file):
|
def read_parameters(self, file):
|
||||||
# try to locate the parameters file
|
# try to locate the parameters file
|
||||||
try:
|
try:
|
||||||
path = os.path.dirname(__file__)
|
ifile = pkg_resources.resource_filename(__name__, file)
|
||||||
ifile = os.path.join(path,'../'+file)
|
|
||||||
input = lib.open_file_for_reading(ifile)
|
input = lib.open_file_for_reading(ifile)
|
||||||
except:
|
except:
|
||||||
input = lib.open_file_for_reading(file)
|
input = lib.open_file_for_reading(file)
|
||||||
|
|||||||
Reference in New Issue
Block a user