Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def split_regions(args):
if args.bed:
regions_to_fetch = args.bed
split_function = bed_split
else:
regions_to_fetch = args.regions
split_function = ucsc_split
return (regions_to_fetch, split_function)
def write_sequence(args):
_, ext = os.path.splitext(args.fasta)
if ext:
ext = ext[1:] # remove the dot from extension
filt_function = re.compile(args.regex).search
fasta = Fasta(args.fasta, default_seq=args.default_seq, key_function=eval(args.header_function), strict_bounds=not args.lazy, split_char=args.delimiter, filt_function=filt_function, read_long_names=args.long_names, rebuild=not args.no_rebuild)
regions_to_fetch, split_function = split_regions(args)
if not regions_to_fetch:
regions_to_fetch = fasta.keys()
if args.invert_match:
sequences_to_exclude = set([split_function(region)[0] for region in regions_to_fetch])
fasta = Fasta(args.fasta, default_seq=args.default_seq, key_function=eval(args.header_function), strict_bounds=not args.lazy, split_char=args.delimiter, rebuild=not args.no_rebuild)
regions_to_fetch = (key for key in fasta.keys() if key not in sequences_to_exclude)
split_function = ucsc_split
header = False
for region in regions_to_fetch:
name, start, end = split_function(region)
if args.size_range:
if start is not None and end is not None:
sequence_len = end - start
else:
sequence_len = len(fasta[name])
if args.size_range[0] > sequence_len or args.size_range[1] < sequence_len:
continue
if args.split_files: # open output file based on sequence name
filename = '.'.join(str(e) for e in (name, start, end, ext) if e)
filename = ''.join(c for c in filename if c.isalnum() or c in keepcharacters)
outfile = open(filename, 'w')
elif args.out: