go through file and remove lines matching patterns, both single- and multi-line
498868
function grepLines(src, ext, destFile){
      src = grunt.util.normalizelf(src);
      var lines = src.split(grunt.util.linefeed),
          dest = [],
          //pattern for all comments containing denotation
          denotationPattern = updatePattern({
            pattern: options.pattern, 
            ext: ext, 
            isDenotationPattern: true}),
          //pattern for one-line grep usage
          pattern = updatePattern({
            pattern: options.pattern, 
            ext: ext}),
          //patterns for multi-line grep usage
          startPattern = updatePattern({
            pattern:options.pattern, 
            augmentPattern: options.startPattern,
            ext: ext}),
          endPattern = updatePattern({
            pattern: options.pattern, 
            augmentPattern: options.endPattern,
            ext: ext});
        if (pattern !== false){
          var startedRemoving;
          //loop over each line looking for either pattern or denotation comments
          lines.forEach(function(line) {
            if (!startedRemoving){
              //looking for one-line or start of multi-line pattern 
              if (line.search(startPattern) === -1 ){
              //looking for one-line or start of one-line pattern 
                if (line.search(pattern) === -1 ){
                  //looking for denotation comments 
                  if (options.removeDenotationComments && line.search(denotationPattern) !== -1){
                    var lineDenotationLess = line.replace(new RegExp(denotationPattern), '');
                    dest.push(lineDenotationLess);
                  } else {
                    //none of patterns found
                    dest.push(line);
                  }
                }
              } else{
                //multi-line found
                startedRemoving = true;
              }
            } else {
              //looking for end of multi-line pattern 
              if (line.search(endPattern) !== -1 ){
                startedRemoving = false;
              }
            }
          });
          var destText = dest.join(grunt.util.linefeed);
          if (grunt.file.exists(destFile)){
            if (!options.fileOverride){
              grunt.fail.warn('File "' + destFile + '" already exists, though is specified as a dest file. ' +
                'Turn on option "fileOverride" so that old file is removed first.');
            } else {
              grunt.file.delete(destFile);
            }
          }
          grunt.file.write(destFile, destText);

          grunt.log.writeln('File "' + destFile + '" created.');
        } else {
          grunt.log.warn('Pattern for \'' + task.target + '\' should be a string.');
        }
    }
767141
def remove_formatting_codes(line, irc=False):
    """"""
    if irc:
        line = escape(line)
    new_line = ''
    while len(line) > 0:
        try:
            if line[0] == '$':
                line = line[1:]

                if line[0] == '$':
                    new_line += '$'
                    line = line[1:]

                elif line[0] == 'c':
                    line = line[1:]
                    if line[0].isdigit():
                        line = line[1:]
                        if line[0].isdigit():
                            line = line[1:]
                            if line[0] == ',':
                                line = line[1:]
                                if line[0].isdigit():
                                    line = line[1:]
                                    if line[0].isdigit():
                                        line = line[1:]
                        elif line[0] == ',':
                            line = line[1:]
                            if line[0].isdigit():
                                line = line[1:]
                                if line[0].isdigit():
                                    line = line[1:]
                    if line[0] == '[':
                        while line[0] != ']':
                            line = line[1:]
                        line = line[1:]

                elif line[0] == '{':
                    if line[:3] == '{$}':
                        new_line += '$'
                        line = line[3:]
                        continue
                    while line[0] != '}':
                        line = line[1:]
                    line = line[1:]

                else:
                    line = line[1:]

            else:
                new_line += line[0]
                line = line[1:]
        except IndexError:
            continue
    return new_line
559856
def _remove_small_contigs(self, infile, outfile, keep=None):
        ''''''
        removed = set()
        all_names = set()
        if keep is None:
            keep = set()

        file_reader = pyfastaq.sequences.file_reader(infile)
        fout = pyfastaq.utils.open_file_write(outfile)

        for seq in file_reader:
            all_names.add(seq.id)
            if len(seq) >= self.min_contig_length or seq.id in keep:
                print(seq, file=fout)
            else:
                removed.add(seq.id)

        pyfastaq.utils.close(fout)
        return all_names, removed
272077
def _remove_files(self, directory, pattern):
        '''
        
        '''
        for root, dirnames, file_names in os.walk(directory):
            for file_name in fnmatch.filter(file_names, pattern):
                os.remove(os.path.join(root, file_name))
37573
def recursive_exclude(self, dir, pattern):
        
        match = translate_pattern(os.path.join(dir, '**', pattern))
        return self._remove_files(match.match)
963652
def remove_blank_lines(self):
        """"""
        to_remove = []
        for i, line in enumerate(self):
            ln = line.strip()
            if ln == '':
                to_remove.append(i)
        self.delete_lines(to_remove)
885309
def _file_filter(cls, filename, include_patterns, exclude_patterns):
    """"""
    logger.debug('filename: {}'.format(filename))
    for exclude_pattern in exclude_patterns:
      if exclude_pattern.match(filename):
        return False
    if include_patterns:
      found = False
      for include_pattern in include_patterns:
        if include_pattern.match(filename):
          found = True
          break
      if not found:
        return False
    return True
976341
function match (filename, patterns, ignorePatterns) {
  function isMatch (ps) {
    return ps.some(p => {
      return mm.isMatch(filename, p, mmOptions)
    })
  }

  let isIgnore = false

  if (Array.isArray(ignorePatterns) && ignorePatterns.length) {
    isIgnore = isMatch(ignorePatterns)
  }

  if (isIgnore) {
    return false
  }

  return isMatch(patterns)
}
114861
def grep(pattern, *files_or_paths):
    """"""
    matches = []

    for fop in files_or_paths:
        with fileobj(fop) as fo:
            matches.extend((line for line in fo if re.match(pattern, line)))

    return matches
1023901
def exclude_file(self, file):
        """"""
        for pattern in self.compiled_exclude_files:
            if (pattern.match(file)):
                return(True)
        return(False)
34736
def clean():
    
    for dirpath, dirnames, filenames in os.walk('.'):
        for filename in filenames:
            if filename.endswith('.pyc') or filename.endswith('.pyo'):
                filepath = os.path.join(dirpath, filename)
                click.echo(f'Removing {filepath}')
                os.remove(filepath)
836388
def removeDuplicates(inFileName, outFileName) :
	"""'"""
	f = open(inFileName)
	legend = f.readline()
	
	data = ''
	h = {}
	h[legend] = 0
	
	lines = f.readlines()
	for l in lines :
		if not h.has_key(l) :
			h[l] = 0
			data += l
			
	f.flush()
	f.close()
	f = open(outFileName, 'w')
	f.write(legend+data)
	f.flush()
	f.close()
1192379
def strip_instructions(text):
        
        # Pattern can span multiple lines, allows dot to match newline chars
        flags = re.MULTILINE | re.DOTALL
        pattern = '<!--{token}(.*?){token}-->'.format(token=TOKEN)
        text = re.sub(pattern, '', text, flags=flags)
        return re.sub(r'\A[\s\n]*\n', '', text, flags=flags).rstrip()
134834
def trim_lines(lines)
      new_lines = lines.dup
      while new_lines[-1] && new_lines[-1].strip.empty?
        new_lines.pop
      end
      new_lines
    end
1354377
def erase_lines(n=1):
    
    for _ in range(n):
        print(codes.cursor["up"], end="")
        print(codes.cursor["eol"], end="")
962417
def _remove_overlaps(in_file, out_dir, data):
    
    out_file = os.path.join(out_dir, "%s-nooverlaps%s" % utils.splitext_plus(os.path.basename(in_file)))
    if not utils.file_uptodate(out_file, in_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:
                    prev_line = None
                    for line in in_handle:
                        if prev_line:
                            pchrom, pstart, pend = prev_line.split("\t", 4)[:3]
                            cchrom, cstart, cend = line.split("\t", 4)[:3]
                            # Skip if chromosomes match and end overlaps start
                            if pchrom == cchrom and int(pend) > int(cstart):
                                pass
                            else:
                                out_handle.write(prev_line)
                        prev_line = line
                    out_handle.write(prev_line)
    return out_file
328412
function filter(file) {
    if (files.indexOf(file) !== -1) return false;
    let include = true;
    regexs.forEach((regex) => {
      if (file.search(regex) !== -1) include = false;
    });
    return include;
  }