Esempio n. 1
0
##  This file is part of PASTA and is forked from SATe2.
##  See "LICENSE.txt" for terms and conditions of usage.
#############################################################################

"""
File and path management.
"""

import os
import sys
import re
import tempfile
import shutil
from threading import Lock
from pasta import get_logger
_LOG = get_logger(__name__)

_ILLEGAL_FILENAME_PATTERN = re.compile(r'[^-_a-zA-Z0-9.]')
def get_safe_filename(filename):
    return "".join(_ILLEGAL_FILENAME_PATTERN.split(filename))

def quoted_file_path(path):
    if '"' not in path:
        return '"'+ path + '"'
    elif "'" not in path:
        return "'" + path + "'"
    else:
        path = path.replace('"', r'\"')
        return '"' + path + '"'

def open_with_intermediates(filepath, mode):
Esempio n. 2
0
#
# You should have received a copy of the GNU General Public License
# along with this program.      If not, see <http://www.gnu.org/licenses/>.

# Jiaye Yu, Mark Holder, and Jeet Sukumaran, University of Kansas
"""
SATe testing suite.
"""

import unittest
import re
import os

from pasta import get_logger
from pasta.configure import get_configuration
_LOG = get_logger("pasta.tests")

try:
    import pkg_resources
    TESTS_DIR = pkg_resources.resource_filename("pasta", "test")
    #SCRIPTS_DIR = pkg_resources.resource_filename("pasta", os.path.join(os.pardir, "scripts"))
    _LOG.info("using pkg_resources path mapping")
except:
    LOCAL_DIR = os.path.dirname(__file__)
    TESTS_DIR = os.path.join(LOCAL_DIR, os.path.pardir)
    PACKAGE_DIR = os.path.join(TESTS_DIR, os.path.pardir)
    #SCRIPTS_DIR = os.path.join(PACKAGE_DIR, os.path.pardir, "scripts")
    _LOG.info("using local filesystem path mapping")

TESTS_DATA_DIR = os.path.join(TESTS_DIR, "data")
TESTS_OUTPUT_DIR = os.path.join(TESTS_DIR, "output")
Esempio n. 3
0
# uym2 added
# June 2017
# utils for tree decomposition


from dendropy import Tree, Node
try:
    from queue import Queue # python 3
except:
    from Queue import Queue # python 2
from sys import argv

from pasta import get_logger

_LOG = get_logger(__name__)

def min_cluster_size_bisect(a_tree,max_size):
    for node in a_tree.postorder_node_iter():
        if node.is_leaf():
            node.nleaf = 1
        else:
            node.nleaf = 0
            max_child = None
            max_nleaf = 0
            for ch in node.child_node_iter():
                   node.nleaf += ch.nleaf
                   if ch.nleaf > max_nleaf:
                       max_nleaf = ch.nleaf
                       max_child = ch
        if node.nleaf > max_size:
            node.remove_child(max_child)
Esempio n. 4
0
# You should have received a copy of the GNU General Public License
# along with this program.      If not, see <http://www.gnu.org/licenses/>.

# Jiaye Yu, Mark Holder, and Jeet Sukumaran, University of Kansas

"""
SATe testing suite.
"""

import unittest
import re
import os

from pasta import get_logger
from pasta.configure import get_configuration
_LOG = get_logger("pasta.tests")

try:
    import pkg_resources
    TESTS_DIR = pkg_resources.resource_filename("pasta", "test")
    #SCRIPTS_DIR = pkg_resources.resource_filename("pasta", os.path.join(os.pardir, "scripts"))
    _LOG.info("using pkg_resources path mapping")
except:
    LOCAL_DIR = os.path.dirname(__file__)
    TESTS_DIR = os.path.join(LOCAL_DIR, os.path.pardir)
    PACKAGE_DIR = os.path.join(TESTS_DIR, os.path.pardir)
    #SCRIPTS_DIR = os.path.join(PACKAGE_DIR, os.path.pardir, "scripts")
    _LOG.info("using local filesystem path mapping")

TESTS_DATA_DIR = os.path.join(TESTS_DIR, "data")
TESTS_OUTPUT_DIR = os.path.join(TESTS_DIR, "output")