Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exit(0)
lang = cls.cmd_obj_list[cmd_name].lang
if lang == 'Python':
if args.tmp_dir is not None:
if not os.path.exists(args.tmp_dir):
msg = "Creating directory {d}."
message(msg.format(d=args.tmp_dir), type="INFO")
mkdir_p(args.tmp_dir)
if not os.path.isdir(args.tmp_dir):
msg = "{d} is not a directory."
message(msg.format(d=args.tmp_dir), type="ERROR")
pygtftk.utils.TMP_DIR = args.tmp_dir
return args
to write to a gtf file.
:Example:
>>> from pygtftk.utils import get_example_feature
>>> from pygtftk.utils import TAB
>>> feat = get_example_feature()
>>> assert len(feat.format().split(TAB)) == 9
"""
tok_list = list()
for key, val in list(self.attr.items()):
tok_list += [key + ' "' + val + '";']
if pygtftk.utils.ADD_CHR == 1:
chrom_out = 'chr' + self.chrom
else:
chrom_out = self.chrom
token = [chrom_out,
self.src,
self.ft_type,
str(self.start),
str(self.end),
str(self.score),
self.strand,
str(self.frame),
' '.join(tok_list)]
return '\t'.join(token)
>>> from pygtftk.utils import get_example_file
>>> from pygtftk.gtf_interface import GTF
>>> from pygtftk.utils import make_tmp_file
>>> from pygtftk.utils import simple_line_count
>>> from pygtftk.utils import simple_nb_column
>>> a_file = get_example_file()[0]
>>> a_tab = GTF(a_file).extract_data("transcript_id,gene_id")
>>> out_file = make_tmp_file()
>>> a_tab.write(out_file)
>>> out_file.close()
>>> assert simple_line_count(out_file) == 70
>>> assert simple_nb_column(out_file) == 2
"""
for i in self:
pygtftk.utils.write_properly(sep.join(list(i)), outfile)
# .pyc -> .py
fun_path = cmd_ob.fun.rstrip("c")
tmp_module = SourceFileLoader('tmp_module', fun_path).load_module()
fun = getattr(tmp_module, args['command'])
# Save args to log file
if cmd_ob.lang == "Python":
# Add 'chr' to the chromosome names
if args['add_chr']:
pygtftk.utils.ADD_CHR = 1
if args['write_message_to_file'] is not None:
pygtftk.utils.MESSAGE_FILE = args['write_message_to_file']
if args['logger_file'] is not None:
if os.path.isdir(args['logger_file']):
message("ERROR --logger-file is a directory.",
type="ERROR")
if not os.path.exists(args['logger_file']):
logger_file_h = open(args['logger_file'], 'w+')
logger_file_h.close()
log_format = "-->> %(asctime)s - %(name)s - " + \
"%(levelname)s - %(message)s"
datefmt = '%Y-%m-%d %H:%M:%S'
logging.basicConfig(filename=args['logger_file'],
level=logging.INFO,
self.start = val
elif key == 'end':
self.end = val
elif key in ['src', 'source']:
self.src = val
elif key == 'score':
self.score = val
elif key == 'frame':
self.frame = val
else:
if upon_none == 'continue':
pass
elif upon_none == 'set_na':
self.add_attr(key, ".")
elif upon_none == 'raise':
pygtftk.utils.message('Attribute ' + key + ' does not exist',
type="ERROR")
else:
pygtftk.utils.message('Attribute ' + key + ' does not exist',
type="ERROR")
# Add a logger to the command object
cls.cmd_obj_list[args['command']].logger = logging.getLogger(__name__)
# .pyc -> .py
fun_path = cmd_ob.fun.rstrip("c")
tmp_module = SourceFileLoader('tmp_module', fun_path).load_module()
fun = getattr(tmp_module, args['command'])
# Save args to log file
if cmd_ob.lang == "Python":
# Add 'chr' to the chromosome names
if args['add_chr']:
pygtftk.utils.ADD_CHR = 1
if args['write_message_to_file'] is not None:
pygtftk.utils.MESSAGE_FILE = args['write_message_to_file']
if args['logger_file'] is not None:
if os.path.isdir(args['logger_file']):
message("ERROR --logger-file is a directory.",
type="ERROR")
if not os.path.exists(args['logger_file']):
logger_file_h = open(args['logger_file'], 'w+')
logger_file_h.close()
log_format = "-->> %(asctime)s - %(name)s - " + \
"%(levelname)s - %(message)s"
datefmt = '%Y-%m-%d %H:%M:%S'
value = str(value)
cmd_ob.logger.info("Argument: " + key + "=" + value)
# Set the level of verbosity
# Can be None if -V is used without value
# (nargs)
if args['verbosity'] is None:
pygtftk.utils.VERBOSITY = 1
else:
pygtftk.utils.VERBOSITY = int(args['verbosity'])
# Set whether date should be added to
# output file
if args['no_date']:
pygtftk.utils.ADD_DATE = False
arg_list_to_del = ['bash_comp', 'add_chr', 'version', 'help',
'plugin_tests', 'list_plugins', 'plugin_tests_no_conn',
'r_libs', 'add_plugin', 'update_plugins', 'system_info',
'plugin_path', 'no_date', 'keep_all', 'logger_file',
'tmp_dir', 'verbosity', 'command', 'write_message_to_file']
for cur_arg in arg_list_to_del:
try:
del args[cur_arg]
except KeyError:
pass
# Run the command
fun(**args)
else:
# -------------------------------------------------------------------------
outputfile_list = {}
message("Using %d bins for main region." % bin_nb)
tmp_file = bw_profile_mp(in_bed_file=main_region_bed.name,
nb_proc=nb_proc,
big_wig=[x.name for x in bigwiglist],
bin_nb=bin_nb,
pseudo_count=pseudo_count,
stranded=not no_stranded,
type="main",
labels=labels,
outputfile=outputfile.name,
zero_to_na=zero_to_na,
verbose=pygtftk.utils.VERBOSITY)
outputfile_list["main"] = tmp_file
# -------------------------------------------------------------------------
# If transcript was requested
# we must process flanking regions
# We need to retrieve coverage of promoter [-upstream, 0]
# as transcript coverage window size will depend on transcript length.
# For promoter the length of windows will be fixed.
# -------------------------------------------------------------------------
if ft_type in ['transcript', 'user_regions']:
# Number of bins for TTS and TSS
around_bin_nb = int(round(bin_nb * bin_around_frac))
if around_bin_nb < 1:
del parser.__dict__['_option_string_actions']['-h']
except:
pass
self.parser = parser
self.fun = fun
self.desc = desc
self.logger = None
self.lang = lang
self.test = test
self.rlib = rlib
if re.search("@test", self.test):
pygtftk.cmd_manager.CmdManager.add_command(self)
else:
pygtftk.utils.message(
"%s command has no test and won't be installed." % name,
type="WARNING")