Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def shift(inputfile=None,
outputfile=None,
shift_value=None,
chrom_info=None,
stranded=False,
allow_outside=False):
"""Shift coordinates in 3' or 5' direction.
"""
gtf = GTF(inputfile, check_ensembl_format=False)
chrom_list_gtf = gtf.get_chroms(nr=True)
chrom_info = chrom_info_as_dict(chrom_info)
for chr in chrom_list_gtf:
if chr not in chrom_info:
raise GTFtkError("Chromosome " + chr + " was not found in chrom-info file.")
for i in gtf:
size = i.end - i.start + 1
if not stranded:
new_start = i.start + shift_value
new_end = i.end + shift_value
else:
if i.strand == "-":
new_start = i.start - shift_value
new_end = i.end - shift_value
else:
new_start = i.start + shift_value
go_id="GO:0003700",
species="hsapiens",
upstream=1000,
downstream=1000,
chrom_info=None,
distal=1000000,
mode='basal_plus_extension',
http_proxy=None,
https_proxy=None):
""" Given a GTF and a GO term, attempt compute labeled regions using GREAT 'association rule'. """
# -------------------------------------------------------------------------
# chrom_len will store the chromosome sizes.
# -------------------------------------------------------------------------
chrom_len = chrom_info_as_dict(chrom_info)
# -------------------------------------------------------------------------
# Read the GTF
# -------------------------------------------------------------------------
gtf = GTF(inputfile, check_ensembl_format=False)
# -------------------------------------------------------------------------
# Get the TSSs -- Extend them by upstream/dowstream
# -------------------------------------------------------------------------
message("Defining basal regulatory domains.", type="INFO")
basal_reg_bed = gtf.get_tss(name=['gene_id', 'gene_name']).slop(s=True,
l=upstream,
r=downstream,
g=chrom_info.name).sort()
"provide --more-keys or --more-bed.",
type="ERROR")
else:
if inputfile is None:
message("Please provide a GTF.",
type="ERROR")
if chrom_info is None:
message("Please provide a chromInfo file (--chrom-info)",
type="ERROR")
# -------------------------------------------------------------------------
# chrom_len will store the chromosome sizes.
# -------------------------------------------------------------------------
chrom_len = chrom_info_as_dict(chrom_info)
# -------------------------------------------------------------------------
# Load the peak file as pybedtools.BedTool object
# -------------------------------------------------------------------------
peak_file = pybedtools.BedTool(peak_file.name)
# -------------------------------------------------------------------------
# Check chromosomes for peaks are defined in the chrom-info file
# Depending on force_chrom_peak, peaks undefined in peak_file may
# be silently removed.
# -------------------------------------------------------------------------
peak_chrom_list = set()
for i in pybedtools.BedTool(peak_file):
tmp_file_chr = make_tmp_file(prefix='chromsize', suffix='.txt')
for chrom, size in chr_size.items():
tmp_file_chr.write(chrom + "\t" + str(size[1]) + "\n")
tmp_file_chr.close()
values = open(tmp_file_chr.name, 'r')
elif values == 'simple':
chr_size = {'chr1': 300, 'chr2': 600}
tmp_file_chr = make_tmp_file(prefix='chromsize', suffix='.txt')
for chrom, size in chr_size.items():
tmp_file_chr.write(chrom + "\t" + str(size) + "\n")
tmp_file_chr.close()
values = open(tmp_file_chr.name, 'r')
else:
check_file_or_dir_exists(values)
values = open(values, "r")
chrom_info_as_dict(values)
# Add the attribute
setattr(namespace, self.dest, values)