Prepare a delly-specific exclude file eliminating chromosomes.
    Delly wants excluded chromosomes listed as just the chromosome, with no coordinates.
501091
def _delly_exclude_file(items, base_file, chrom):
    
    base_exclude = sshared.prepare_exclude_file(items, base_file, chrom)
    out_file = "%s-delly%s" % utils.splitext_plus(base_exclude)
    with file_transaction(items[0], out_file) as tx_out_file:
        with open(tx_out_file, "w") as out_handle:
            with open(base_exclude) as in_handle:
                for line in in_handle:
                    parts = line.split("\t")
                    if parts[0] == chrom:
                        out_handle.write(line)
                    else:
                        out_handle.write("%s\n" % parts[0])
    return out_file
885403
def remove_polyx_regions(in_file, items):
    
    ex_bed = tz.get_in(["genome_resources", "variation", "polyx"], items[0])
    if ex_bed and os.path.exists(ex_bed):
        return _remove_regions(in_file, [ex_bed], "nopolyx", items[0])
    else:
        return in_file
1005230
def prepare_output(d):
    """"""
    outDir = os.path.join(d, 'inorder')
    if not os.path.exists(outDir):
        os.mkdir(outDir)
    for f in os.listdir(outDir):
        f = os.path.join(outDir, f)
        if os.path.islink(f):
            os.remove(f)
    return outDir
1117726
def clear(self, exclude=None):
        
        if exclude is None:
            self.cache = {}
        else:
            self.cache = {k: v for k, v in self.cache.items()
                          if k in exclude}
1359215
def exclude_by_filter(self, filename, module_name):
        '''
        
        '''
        for exclude_filter in self._exclude_filters:  # : :type exclude_filter: ExcludeFilter
            if exclude_filter.is_path:
                if glob_matches_path(filename, exclude_filter.name):
                    if exclude_filter.exclude:
                        pydev_log.debug("File %s ignored by filter %s" % (filename, exclude_filter.name))
                    return exclude_filter.exclude
            else:
                # Module filter.
                if exclude_filter.name == module_name or module_name.startswith(exclude_filter.name + '.'):
                    return exclude_filter.exclude
        return None
1248065
def filter(self, chromosome, **kwargs) :
		""""""
		def appendAllele(alleles, sources, snp) :
			pos = snp.start
			if snp.alt[0] == '-' :
				pass
				# print warn % ('DELETION', snpSet, snp.start, snp.chromosomeNumber)
			elif snp.ref[0] == '-' :
				pass
				# print warn % ('INSERTION', snpSet, snp.start, snp.chromosomeNumber)
			else :
				sources[snpSet] = snp
				alleles.append(snp.alt) #if not an indel append the polymorphism
			
			refAllele = chromosome.refSequence[pos]
			alleles.append(refAllele)
			sources['ref'] = refAllele
			return alleles, sources
				
		warn = 'Warning: the default snp filter ignores indels. IGNORED %s of SNP set: %s at pos: %s of chromosome: %s'
		sources = {}
		alleles = []
		for snpSet, data in kwargs.iteritems() :
			if type(data) is list :
				for snp in data :
					alleles, sources = appendAllele(alleles, sources, snp)
			else :
				allels, sources = appendAllele(alleles, sources, data)

		#appends the refence allele to the lot

		#optional we keep a record of the polymorphisms that were used during the process
		return SequenceSNP(alleles, sources = sources)
995298
def clear_offsets_excluding(excluded)
      # Clear all offsets that aren't in `excluded`.
      @processed_offsets.each do |topic, partitions|
        partitions.keep_if do |partition, _|
          excluded.fetch(topic, []).include?(partition)
        end
      end

      # Clear the cached commits from the brokers.
      @committed_offsets = nil
      @resolved_offsets.clear
    end
405767
def exclude_data_files(self, package, src_dir, files):
        """'"""
        files = list(files)
        patterns = self._get_platform_patterns(
            self.exclude_package_data,
            package,
            src_dir,
        )
        match_groups = (
            fnmatch.filter(files, pattern)
            for pattern in patterns
        )
        # flatten the groups of matches into an iterable of matches
        matches = itertools.chain.from_iterable(match_groups)
        bad = set(matches)
        keepers = (
            fn
            for fn in files
            if fn not in bad
        )
        # ditch dupes
        return list(_unique_everseen(keepers))
23099
def exclude_SNPs_samples(inPrefix, outPrefix, exclusionSNP=None,
                         keepSample=None, transpose=False):
    """"""
    if (exclusionSNP is None) and (keepSample is None):
        msg = "Something wront with development... work on that source code..."
        raise ProgramError(msg)

    plinkCommand = ["plink", "--noweb", "--bfile", inPrefix, "--out",
                    outPrefix]
    if exclusionSNP is not None:
        # We want to exclude SNP
        plinkCommand.extend(["--exclude", exclusionSNP])
    if keepSample is not None:
        # We want to keep samples
        plinkCommand.extend(["--keep", keepSample])
    if transpose:
        # We want a transpose ped file
        plinkCommand.extend(["--recode", "--transpose", "--tab"])
    else:
        # We want a binary file
        plinkCommand.append("--make-bed")
    runCommand(plinkCommand)
1335659
def normalize_excludes(rootpath, excludes):
    
    sep = os.path.sep
    f_excludes = []
    for exclude in excludes:
        if not os.path.isabs(exclude) and not exclude.startswith(rootpath):
            exclude = os.path.join(rootpath, exclude)
        if not exclude.endswith(sep):
            exclude += sep
        f_excludes.append(exclude)
    return f_excludes
1316451
def exclude(*args)
      args.flatten! # allow [] as a param
      args.collect!(&:to_sym) # symbolize the args
      # check respond_to? :to_sym, ActionColumns doesn't respond to to_sym
      @set.reject! { |c| c.respond_to?(:to_sym) && args.include?(c.to_sym) } # reject all items specified
    end
1194067
def exclude(self, data, range_obj):
        
        if isinstance(range_obj, (pd.DatetimeIndex, tuple)):
            range_obj = DateRange(range_obj[0], range_obj[-1])
        if 'date' in data.index.names:
            return data[(data.index.get_level_values('date') < range_obj.start) | (data.index.get_level_values('date') > range_obj.end)]
        elif 'date' in data.columns:
            return data[(data.date < range_obj.start) | (data.date > range_obj.end)]
        else:
            return data
557173
def exclude_file(sp, f):
    
    # Make everything a list if it isn't already
    for k in sp:
        if k in ['exclude_fn', 'exclude_fn_re' 'exclude_contents', 'exclude_contents_re']:
            if not isinstance(sp[k], list):
                sp[k] = [sp[k]]

    # Search by file name (glob)
    if 'exclude_fn' in sp:
        for pat in sp['exclude_fn']:
            if fnmatch.fnmatch(f['fn'], pat):
                return True

    # Search by file name (regex)
    if 'exclude_fn_re' in sp:
        for pat in sp['exclude_fn_re']:
            if re.match( pat, f['fn']):
                return True

    # Search the contents of the file
    if 'exclude_contents' in sp or 'exclude_contents_re' in sp:
        # Compile regex patterns if we have any
        if 'exclude_contents_re' in sp:
            sp['exclude_contents_re'] = [re.compile(pat) for pat in sp['exclude_contents_re']]
        with io.open (os.path.join(f['root'],f['fn']), "r", encoding='utf-8') as fh:
            for line in fh:
                if 'exclude_contents' in sp:
                    for pat in sp['exclude_contents']:
                        if pat in line:
                            return True
                if 'exclude_contents_re' in sp:
                    for pat in sp['exclude_contents_re']:
                        if re.search(pat, line):
                            return True
    return False
112499
def parse_exclusions(exclusions):
    
    fname = fileutil.osfn(exclusions)
    if os.path.exists(fname):
        with open(fname) as f:
            flines = f.readlines()
    else:
        print('No valid exclusions file "', fname, '" could be found!')
        print('Skipping application of exclusions files to source catalogs.')
        return None

    # Parse out lines which can be interpreted as positions and distances
    exclusion_list = []
    units = None
    for line in flines:
        if line[0] == '#' or 'global' in line[:6]:
            continue
        # Only interpret the part of the line prior to the comment
        # if a comment has been attached to the line
        if '#' in line:
            line = line.split('#')[0].rstrip()

        if units is None:
            units = 'pixels'
            if line[:3] in ['fk4', 'fk5', 'sky']:
                units = 'sky'
            if line[:5] in ['image', 'physi', 'pixel']:
                units = 'pixels'
            continue

        if 'circle(' in line:
            nline = line.replace('circle(', '')
            nline = nline.replace(')', '')
            nline = nline.replace('"', '')
            vals = nline.split(',')
            if ':' in vals[0]:
                posval = vals[0] + ' ' + vals[1]
            else:
                posval = (float(vals[0]), float(vals[1]))
        else:
            # Try to interpret unformatted line
            if ',' in line:
                split_tok = ','
            else:
                split_tok = ' '
            vals = line.split(split_tok)
            if len(vals) == 3:
                if ':' in vals[0]:
                    posval = vals[0] + ' ' + vals[1]
                else:
                    posval = (float(vals[0]), float(vals[1]))
            else:
                continue
        exclusion_list.append(
            {'pos': posval, 'distance': float(vals[2]), 'units': units}
        )
    return exclusion_list
1139023
def exclude_options(ignore_file_path)
      ar = File.read(ignore_file_path)
      ar = ar.split("\n")
      ar.map! do |r|
        r.gsub!(/#.*$/,""); r.gsub!(/^\s*?$/,"")
        r.gsub!(/^\//,"./"); r.gsub!(/\/$/,"/*")
        r
      end
      ar =  ar.delete_if{|r|r==""}
      ar.map! do |r|
        "--exclude '" + r + "'"
      end
      return ar.join(" ")
    end
632300
def remove_excluded(self):
        
        # import yaml
        # print yaml.dump({k:v.__json__() for k,v in self.sources.items()}, default_flow_style=False)
        sources = list(self.sources.values())
        for src in sources:
            if src.excluded:
                del self.sources[src.name]
            src.imports = [m for m in src.imports if not self._exclude(m)]
            src.imported_by = [m for m in src.imported_by if not self._exclude(m)]
939841
def _remove_haplotype_chroms(in_file, data):
    
    larger_chroms = set(_get_larger_chroms(dd.get_ref_file(data)))
    out_file = os.path.join(_sv_workdir(data), "%s-chromfilter%s" % utils.splitext_plus(os.path.basename(in_file)))
    if not utils.file_exists(out_file):
        with file_transaction(data, out_file) as tx_out_file:
            with open(in_file) as in_handle:
                with open(tx_out_file, "w") as out_handle:
                    for line in in_handle:
                        if ((line.find("chromosome") >= 0 and line.find("start") >= 0)
                              or line.split()[0] in larger_chroms):
                            out_handle.write(line)
    return out_file