示例#1
0
def __listDirectory__(directory, files=False, exclude_pattern_starts_with=None):
    """
    Devuelve las carpetas contenidas en el directorio indicado. Si se quieren listar los 
    ficheros se deberá indicar el argumento files=True. En el caso de querer excluir ficheros o carpetas
    se indicará en el argumento exclude_pattern_starts_with con el comienzo de los mism__os.
    """
    mypath = __join(__this_dir__, directory)
    data = ''

    if files:
        data = [f for f in __listdir(mypath) if __isfile(__join(mypath, f))]
    else:
        data = [f for f in __listdir(mypath) if not __isfile(__join(mypath, f))]

    if __blacklist_extensions__:
        new_data = []
        for d in data:
            has_extension = False
            for black_ext in __blacklist_extensions__:
                if black_ext in d:
                    has_extension = True
            if not has_extension:
                new_data.append(d)
        data = new_data

    if exclude_pattern_starts_with:
        new_data = []
        for d in data:
            if not d.startswith(exclude_pattern_starts_with):
                new_data.append(d)
        data = new_data

    if __blacklist_directories__:
        new_data = []
        for d in data:
            for direc in __blacklist_directories__:
                if not direc in d:
                    new_data.append(d)
        data = new_data

    if __ignore_folders__:
        new_data = []
        for d in data:
            exists = False
            for direc in __ignore_folders__:
                if direc in d:
                    exists = True
            if not exists:
                new_data.append(d)
        data = new_data

    if files and __ignore_files__:
        new_data = []
        for d in data:
            for file_ign in __ignore_files__:
                if not file_ign in d:
                    new_data.append(d)
        data = new_data

    return data
示例#2
0
def __cleanOutputModules__():
    for mod in getModulesNames():
        cat = getModuleCategory(mod)
        output_dir = __join(__os.path.dirname(__file__), 'modules', cat, mod.replace('ht_', ''), 'output')
        if __os.path.isdir(output_dir):
            for temp_file in __listdir(output_dir):
                __os.remove(__join(output_dir, temp_file))
示例#3
0
def get_deck(deck_name: str):
    """Reads a deck file and returns the
    ids of the cards in it"""

    deck_path = __join(deck_folder_path, f"{deck_name}.ydk")
    deck_exists = __exists(deck_path)
    if not deck_exists:
        return None
    deck = open(deck_path, mode="r", encoding="utf8")
    cards = __filter_card_id([l.strip() for l in deck.readlines()])
    return cards
示例#4
0
def which(program):
    """returns path to an executable if it is found in the path"""
    fpath, fname = __split(program)
    if fpath:
        if __isfile(program) and __os.access(program, __os.X_OK):
            return program
    else:
        paths_to_search = __os.environ["PATH"].split(__os.pathsep)
        paths_to_search.extend((omelib_directory, ome_directory))
        for path in paths_to_search:
            exe_file = __join(path, program)
            if __isfile(exe_file) and __os.access(exe_file, __os.X_OK):
                return exe_file
    if __os.name == "nt" and not program.endswith(".exe"):
        return which(program + ".exe")
    return None
示例#5
0
def which(program):
    """returns path to an executable if it is found in the path"""
    fpath, fname = __split(program)
    if fpath:
        if __isfile(program) and __os.access(program, __os.X_OK):
            return program
    else:
        paths_to_search = __os.environ["PATH"].split(__os.pathsep)
        paths_to_search.extend((trnlib_directory, trn_directory))
        for path in paths_to_search:
            exe_file = __join(path, program)
            if __isfile(exe_file) and __os.access(exe_file, __os.X_OK):
                return exe_file
    if __os.name == "nt" and not program.endswith(".exe"):
        return which(program + ".exe")
    return None
示例#6
0
def download_image(card_id: int, is_artwork: bool = False):
    """Downloads the card image or artwork and
    puts in the specified folder"""

    img_url = "https://storage.googleapis.com/ygoprodeck.com/pics"
    if not is_artwork:
        img_url += f"/{card_id}.jpg"
        store_at = "./pics/"
    else:
        img_url += f"_artgame/{card_id}.jpg"
        store_at = "./pics/field/"

    file_path = __join(store_at, f"{card_id}.jpg")
    try:
        __request.urlretrieve(img_url, file_path)
        return True

    except Exception as e:
        print(e)
        return False
示例#7
0
def __removeModule__(moduleName, category):
    modulePath = __join(__this_dir__, 'modules', category, moduleName.replace('ht_', ''))
    try:
        __os.chmod(modulePath, 777)
    except:
        pass
    try:
        if __os.path.isdir(modulePath):
            __shutil.rmtree(modulePath, ignore_errors=True)
    except:
        pass
    try:
        if __os.path.isdir(modulePath):
            __os.rmdir(modulePath)
    except:
        pass
    try:
        if __os.path.isdir(modulePath):
            __os.removedirs(modulePath)
    except:
        pass
示例#8
0
from __future__ import with_statement, absolute_import
import sys
from os import name as __name
available_tests = ['unit_tests', 'solvers', 'flux_analysis', 'io_tests']

del __name

from os.path import abspath as __abspath
from os.path import join as __join
from os.path import split as __split
from os.path import sep as __sep

cobra_directory = __abspath(__join(__split(__abspath(__file__))[0], ".."))
cobra_location = __abspath(__join(cobra_directory, ".."))
data_directory = __join(__split(__abspath(__file__))[0], "data")
if not data_directory.endswith(__sep):
    data_directory += __sep

salmonella_sbml = __join(data_directory, "salmonella.xml")
salmonella_fbc_sbml = __join(data_directory, "salmonella_fbc.xml")
salmonella_pickle = __join(data_directory, "salmonella.pickle")
salmonella_reaction_p_values_pickle = __join(data_directory, "salmonella_reaction_p_values.pickle")
ecoli_sbml = __join(data_directory, "iJO1366.xml")
ecoli_pickle = __join(data_directory, "iJO1366.pickle")
ecoli_mat = __join(data_directory, "iJO1366.mat")
ecoli_json = __join(data_directory, "iJO1366.json")
yersinia_sbml = __join(data_directory, 'Yersinia_pestis_CO92_iPC815.xml')
yersinia_pickle = __join(data_directory, 'Yersinia_pestis_CO92_iPC815.pickle')

__test_pickles = {'Salmonella_enterica': salmonella_pickle,
                  'Escherichia_coli': ecoli_pickle,
示例#9
0
def load_settings_from_file(filepath="settings.ini", in_trnlib=True):
    """reload settings from a different settings file
    
    filepath: The path to the settings file to use
    
    in_trnlib: Whether or not the path given is a relative path from the trnlib
        directory"""
    if in_trnlib:
        filepath = __join(trnlib_directory, filepath)
    config.read(filepath)

    # attempt to intellegently determine more difficult settings
    if not config.has_option("DATABASE", "user"):
        if "USERNAME" in __os.environ:  # windows
            user = __os.environ["USERNAME"]
        elif "USER" in __os.environ:  # unix
            user = __os.environ["USER"]
        config.set("DATABASE", "user", user)
    if not config.has_option("EXECUTABLES", "psql"):
        psql = which("psql91")
        if psql is None:
            psql = which("psql")
        if psql is None:
            psql = "SET_PATH_TO_PSQL"
        config.set("EXECUTABLES", "psql", psql)
    if not config.has_option("EXECUTABLES", "R"):
        R = which("R")
        if R is None:
            R = "SET_PATH_TO_R"
        config.set("EXECUTABLES", "R", R)
    if not config.has_option("EXECUTABLES", "Rscript"):
        Rscript = which("Rscript")
        if Rscript is None:
            Rscript = "SET_PATH_TO_Rscript"
        config.set("EXECUTABLES", "Rscript", Rscript)
    if not config.has_option("EXECUTABLES", "primer3"):
        primer3 = which("primer3_core")
        if primer3 is None:
            primer3 = "./primer3_core"
        config.set("EXECUTABLES", "primer3", primer3)

    # write the options back to the file
    with open(filepath, "w") as outfile:
        config.write(outfile)

    # save options as variables
    self.user = config.get("DATABASE", "user")
    self.password = config.get("DATABASE", "password")
    if len(self.password) > 0:
        __os.environ["PGPASSWORD"] = self.password
    self.host = config.get("DATABASE", "host")
    self.database = config.get("DATABASE", "database")
    self.schema = config.get("DATABASE", "schema")
    self.psql = _escape_space(config.get("EXECUTABLES", "psql"))
    self.R = _escape_space(config.get("EXECUTABLES", "R"))
    self.Rscript = _escape_space(config.get("EXECUTABLES", "Rscript"))
    self.primer3 = _escape_space(config.get("EXECUTABLES", "primer3"))
    # make a psql string with the database options included
    self.hostname, self.port = host.split(":")
    self.psql_full = "%s --host=%s --username=%s --port=%s %s" % \
        (self.psql, self.hostname, self.user, self.port, self.database)
    self.entrez_email = config.get("MISC", "entrez_email")
    if self.entrez_email == "SET_ENTREZ_EMAIL": self.entrez_email = None
    #set home directory
    self.home_directory = config.get("MISC", "home_directory")
    self.dropbox_directory = config.get("MISC", "dropbox_directory")
    self.data_directory = config.get("MISC", "data_directory")
    self.dropbox_trn_directory = self.data_directory  # TODO depracate
示例#10
0
"""retrive local user settings"""

from ConfigParser import SafeConfigParser
import os as __os
from os.path import split as __split, join as __join, abspath as __abspath, \
    isfile as __isfile
from sys import modules

self = modules[__name__]

# define various filepaths
omelib_directory = __join(__split(__abspath(__file__))[0], "")
ome_directory = __join(__abspath(__join(omelib_directory, "..")), "")


def which(program):
    """returns path to an executable if it is found in the path"""
    fpath, fname = __split(program)
    if fpath:
        if __isfile(program) and __os.access(program, __os.X_OK):
            return program
    else:
        paths_to_search = __os.environ["PATH"].split(__os.pathsep)
        paths_to_search.extend((omelib_directory, ome_directory))
        for path in paths_to_search:
            exe_file = __join(path, program)
            if __isfile(exe_file) and __os.access(exe_file, __os.X_OK):
                return exe_file
    if __os.name == "nt" and not program.endswith(".exe"):
        return which(program + ".exe")
    return None
示例#11
0
"""retrive local user settings"""

from configparser import SafeConfigParser
import os as __os
from os.path import split as __split, join as __join, abspath as __abspath, \
    isfile as __isfile
from sys import modules

self = modules[__name__]

# define various filepaths
trnlib_directory = __join(__split(__abspath(__file__))[0], "")
trn_directory = __join(__abspath(__join(trnlib_directory, "..")), "")


def which(program):
    """returns path to an executable if it is found in the path"""
    fpath, fname = __split(program)
    if fpath:
        if __isfile(program) and __os.access(program, __os.X_OK):
            return program
    else:
        paths_to_search = __os.environ["PATH"].split(__os.pathsep)
        paths_to_search.extend((trnlib_directory, trn_directory))
        for path in paths_to_search:
            exe_file = __join(path, program)
            if __isfile(exe_file) and __os.access(exe_file, __os.X_OK):
                return exe_file
    if __os.name == "nt" and not program.endswith(".exe"):
        return which(program + ".exe")
    return None
示例#12
0
from __future__ import with_statement, absolute_import
import sys
from os import name as __name
available_tests = ['unit_tests']

del __name

from os.path import abspath as __abspath
from os.path import join as __join
from os.path import split as __split
from os.path import sep as __sep
from cobra.manipulation import initialize_growth_medium

gim3e_directory = __abspath(__join(__split(__abspath(__file__))[0], ".."))
gim3e_location = __abspath(__join(gim3e_directory, ".."))
data_directory = gim3e_directory + "/data/"
gim3e_directory += '/core/'

salmonella_pickle = __join(data_directory, "salmonella_gem.pickle")
ecoli_sbml = __join(data_directory, "E_coli_core_M9.xml")
del __abspath, __join, __split, __sep


def create_test_model(test_pickle=salmonella_pickle):
    """Returns a cobra model for testing.  The default model is the
    version of the Salmonella enterica Typhimurium LT2 model published in
    Thiele et al. 2011 BMC Sys Bio 5:8, which has some updated metabolite
    KEGG id data for Schmidt et al. 2013 Bioinformatics

    test_pickle: The complete file name of a pickled cobra.Model or SBML XML
    file to be read.  We currently provide Salmonella enterica Typhimurium
示例#13
0
from __future__ import with_statement, absolute_import
import sys
from os import name as __name
available_tests = ['unit_tests']

del __name

from os.path import abspath as __abspath
from os.path import join as __join
from os.path import split as __split
from os.path import sep as __sep

nampy_directory = __abspath(__join(__split(__abspath(__file__))[0], ".."))
nampy_location = __abspath(__join(nampy_directory, ".."))
data_directory = nampy_directory + "/data/"
nampy_directory += '/core/'

humannet_filename = __join(data_directory, "HumanNet_v1_join_networkonly.txt")
recon_1_filename = __join(data_directory, "recon_1_nampy_v01")

del __abspath, __join, __split, __sep

def create_test_model(test_network_file = humannet_filename):
    """Returns a nampy model for testing.  

    test_network_file: a two-column network file to be read
    
    """
    # from os import name as __name
    from nampy.networkio import networkio
    
示例#14
0
def load_settings_from_file(filepath="settings.ini", in_omelib=True):
    """reload settings from a different settings file

    filepath: The path to the settings file to use

    in_omelib: Whether or not the path given is a relative path from the omelib
        directory"""
    if in_omelib:
        filepath = __join(omelib_directory, filepath)
    config.read(filepath)

    # attempt to intellegently determine more difficult settings
    if not config.has_option("DATABASE", "user"):
        if "USERNAME" in __os.environ:  # windows
            user = __os.environ["USERNAME"]
        elif "USER" in __os.environ:  # unix
            user = __os.environ["USER"]
        config.set("DATABASE", "user", user)
    if not config.has_option("EXECUTABLES", "psql"):
        psql = which("psql91")
        if psql is None:
            psql = which("psql")
        if psql is None:
            psql = "SET_PATH_TO_PSQL"
        config.set("EXECUTABLES", "psql", psql)
    if not config.has_option("EXECUTABLES", "R"):
        R = which("R")
        if R is None:
            R = "SET_PATH_TO_R"
        config.set("EXECUTABLES", "R", R)
    if not config.has_option("EXECUTABLES", "Rscript"):
        Rscript = which("Rscript")
        if Rscript is None:
            Rscript = "SET_PATH_TO_Rscript"
        config.set("EXECUTABLES", "Rscript", Rscript)
    if not config.has_option("EXECUTABLES", "primer3"):
        primer3 = which("primer3_core")
        if primer3 is None:
            primer3 = "./primer3_core"
        config.set("EXECUTABLES", "primer3", primer3)
    if not config.has_option("EXECUTABLES", "cufflinks"):
        cufflinks = which("cufflinks")
        if cufflinks is None:
            cufflinks = "./cufflinks"
        config.set("EXECUTABLES", "cufflinks", cufflinks)

    # write the options back to the file
    with open(filepath, "w") as outfile:
        config.write(outfile)

    # save options as variables
    self.postgres_user = config.get("DATABASE", "postgres_user")
    self.postgres_password = config.get("DATABASE", "postgres_password")
    if len(self.postgres_password) > 0:
        __os.environ["PGPASSWORD"] = self.postgres_password
    self.postgres_database = config.get("DATABASE", "postgres_database")
    self.postgres_host = config.get("DATABASE", "postgres_host")
    self.psql = _escape_space(config.get("EXECUTABLES", "psql"))
    self.R = _escape_space(config.get("EXECUTABLES", "R"))
    self.Rscript = _escape_space(config.get("EXECUTABLES", "Rscript"))
    self.primer3 = _escape_space(config.get("EXECUTABLES", "primer3"))
    self.cufflinks = config.get("EXECUTABLES", "cufflinks")

    # make a psql string with the database options included
    self.hostname, self.port = postgres_host.split(":")
    self.psql_full = "%s --host=%s --username=%s --port=%s " % \
        (self.psql, self.hostname, self.postgres_user, self.port)
    self.entrez_email = config.get("MISC", "entrez_email")
    if self.entrez_email == "SET_ENTREZ_EMAIL": self.entrez_email = None
    #set home directory
    self.home_directory = config.get("MISC", "home_directory")
    self.data_directory = config.get("MISC", "data_directory")
示例#15
0
"""retrive local user settings"""

from ConfigParser import SafeConfigParser
import os as __os
from os.path import split as __split, join as __join, abspath as __abspath, \
    isfile as __isfile
from sys import modules

self = modules[__name__]

# define various filepaths
omelib_directory = __join(__split(__abspath(__file__))[0], "")
ome_directory = __join(__abspath(__join(omelib_directory, "..")), "")

def which(program):
    """returns path to an executable if it is found in the path"""
    fpath, fname = __split(program)
    if fpath:
        if __isfile(program) and __os.access(program, __os.X_OK):
            return program
    else:
        paths_to_search = __os.environ["PATH"].split(__os.pathsep)
        paths_to_search.extend((omelib_directory, ome_directory))
        for path in paths_to_search:
            exe_file = __join(path, program)
            if __isfile(exe_file) and __os.access(exe_file, __os.X_OK):
                return exe_file
    if __os.name == "nt" and not program.endswith(".exe"):
        return which(program + ".exe")
    return None
示例#16
0
"""retrive local user settings"""

from configparser import SafeConfigParser
import os as __os
from os.path import split as __split, join as __join, abspath as __abspath, \
    isfile as __isfile
from sys import modules

self = modules[__name__]

# define various filepaths
trnlib_directory = __join(__split(__abspath(__file__))[0], "")
trn_directory = __join(__abspath(__join(trnlib_directory, "..")), "")

def which(program):
    """returns path to an executable if it is found in the path"""
    fpath, fname = __split(program)
    if fpath:
        if __isfile(program) and __os.access(program, __os.X_OK):
            return program
    else:
        paths_to_search = __os.environ["PATH"].split(__os.pathsep)
        paths_to_search.extend((trnlib_directory, trn_directory))
        for path in paths_to_search:
            exe_file = __join(path, program)
            if __isfile(exe_file) and __os.access(exe_file, __os.X_OK):
                return exe_file
    if __os.name == "nt" and not program.endswith(".exe"):
        return which(program + ".exe")
    return None
示例#17
0
from __future__ import with_statement, absolute_import
import sys
from os import name as __name
available_tests = ['unit_tests', 'solvers', 'flux_analysis', 'io_tests']

del __name

from os.path import abspath as __abspath
from os.path import join as __join
from os.path import split as __split
from os.path import sep as __sep

cobra_directory = __abspath(__join(__split(__abspath(__file__))[0], ".."))
cobra_location = __abspath(__join(cobra_directory, ".."))
data_directory = __join(__split(__abspath(__file__))[0], "data")
if not data_directory.endswith(__sep):
    data_directory += __sep

salmonella_sbml = __join(data_directory, "salmonella.xml")
salmonella_fbc_sbml = __join(data_directory, "salmonella_fbc.xml")
salmonella_pickle = __join(data_directory, "salmonella.pickle")
salmonella_reaction_p_values_pickle = __join(
    data_directory, "salmonella_reaction_p_values.pickle")
ecoli_sbml = __join(data_directory, "iJO1366.xml")
ecoli_pickle = __join(data_directory, "iJO1366.pickle")
ecoli_mat = __join(data_directory, "iJO1366.mat")
ecoli_json = __join(data_directory, "iJO1366.json")
yersinia_sbml = __join(data_directory, 'Yersinia_pestis_CO92_iPC815.xml')
yersinia_pickle = __join(data_directory, 'Yersinia_pestis_CO92_iPC815.pickle')

__test_pickles = {
示例#18
0
from __future__ import with_statement, absolute_import
import sys
from os import name as __name
available_tests = ['unit_tests']

del __name

from os.path import abspath as __abspath
from os.path import join as __join
from os.path import split as __split
from os.path import sep as __sep
from cobra.manipulation import initialize_growth_medium

gim3e_directory = __abspath(__join(__split(__abspath(__file__))[0], ".."))
gim3e_location = __abspath(__join(gim3e_directory, ".."))
data_directory = gim3e_directory + "/data/"
gim3e_directory += '/core/'

salmonella_pickle = __join(data_directory, "salmonella_gem.pickle")
ecoli_sbml = __join(data_directory, "E_coli_core_M9.xml")
del __abspath, __join, __split, __sep

def create_test_model(test_pickle=salmonella_pickle):
    """Returns a cobra model for testing.  The default model is the
    version of the Salmonella enterica Typhimurium LT2 model published in
    Thiele et al. 2011 BMC Sys Bio 5:8, which has some updated metabolite
    KEGG id data for Schmidt et al. 2013 Bioinformatics

    test_pickle: The complete file name of a pickled cobra.Model or SBML XML
    file to be read.  We currently provide Salmonella enterica Typhimurium
    and Escherichia coli core models whose paths are stored in cobra.test.salmonella_pickle
示例#19
0
from __future__ import with_statement, absolute_import
import sys
from os import name as __name
available_tests = ['unit_tests', 'solvers', 'flux_analysis']
#if not using jython then add the tests that don't currently run through jython
## if __name != 'java':
##      available_tests += ['flux_analysis']

del __name

from os.path import abspath as __abspath
from os.path import join as __join
from os.path import split as __split
from os.path import sep as __sep

cobra_directory = __abspath(__join(__split(__abspath(__file__))[0], ".."))
cobra_location = __abspath(__join(cobra_directory, ".."))
data_directory = __join(__split(__abspath(__file__))[0], "data")
if not data_directory.endswith(__sep):
    data_directory += __sep

salmonella_sbml = __join(data_directory, "salmonella.xml")
salmonella_pickle = __join(data_directory, "salmonella.pickle")
salmonella_reaction_p_values_pickle = __join(data_directory, "salmonella_reaction_p_values.pickle")
ecoli_sbml = __join(data_directory, "iJO1366.xml")
ecoli_pickle = __join(data_directory, "iJO1366.pickle")
ecoli_mat = __join(data_directory, "iJO1366.mat")
__test_pickles = {'Salmonella_enterica': salmonella_pickle,
                  'Escherichia_coli': ecoli_pickle}
__test_xml = {'Salmonella_enterica': salmonella_sbml,
              'Escherichia_coli': ecoli_sbml}