Cleanly merge the top files
543882
def merge_tops(self, tops):
        '''
        
        '''
        merging_strategy = self.opts['top_file_merging_strategy']
        try:
            merge_attr = '_merge_tops_{0}'.format(merging_strategy)
            merge_func = getattr(self, merge_attr)
            if not hasattr(merge_func, '__call__'):
                msg = '\'{0}\' is not callable'.format(merge_attr)
                log.error(msg)
                raise TypeError(msg)
        except (AttributeError, TypeError):
            log.warning(
                'Invalid top_file_merging_strategy \'%s\', falling back to '
                '\'merge\'', merging_strategy
            )
            merge_func = self._merge_tops_merge
        return merge_func(tops)
1338724
def merge!(*args)
      val = args.pop
      keys = args.flatten
      StorageFile.merge!(path, [*@parents, *keys], val)
    end
429817
def clean(ctx, dry_run=False):
    """"""
    # -- VARIATION-POINT 1: Allow user to override in configuration-file
    directories = ctx.clean.directories
    files = ctx.clean.files

    # -- VARIATION-POINT 2: Allow user to add more files/dirs to be removed.
    extra_directories = ctx.clean.extra_directories or []
    extra_files = ctx.clean.extra_files or []
    if extra_directories:
        directories.extend(extra_directories)
    if extra_files:
        files.extend(extra_files)

    # -- PERFORM CLEANUP:
    execute_cleanup_tasks(ctx, cleanup_tasks, dry_run=dry_run)
    cleanup_dirs(directories, dry_run=dry_run)
    cleanup_files(files, dry_run=dry_run)
78864
private void mergeWithSmoosher() throws IOException
  {
    // Get processed elements from the stack and write.
    List<File> fileToProcess = new ArrayList<>(completedFiles);
    completedFiles = new ArrayList<>();
    for (File file : fileToProcess) {
      add(file);
      if (!file.delete()) {
        LOG.warn("Unable to delete file [%s]", file);
      }
    }
  }
544864
def clear(self):
        """"""
        for root, dirs, files in os.walk(self._root_dir, topdown=False):
            for file in files:
                os.unlink(os.path.join(root, file))
            os.rmdir(root)
        # Get the root dir back and re-initialise to start again
        root_dir = os.path.abspath(
            os.path.join(self._root_dir, os.pardir))
        self.__init__(root_dir)
507638
def _combine_files(tsv_files, work_dir, data):
    
    header = "\t".join(["caller", "sample", "chrom", "start", "end", "svtype",
                        "lof", "annotation", "split_read_support", "paired_support_PE", "paired_support_PR"])
    sample = dd.get_sample_name(data)
    out_file = os.path.join(work_dir, "%s-prioritize.tsv" % (sample))
    if not utils.file_exists(out_file):
        with file_transaction(data, out_file) as tx_out_file:
            tmpdir = os.path.dirname(tx_out_file)
            input_files = " ".join(tsv_files)
            sort_cmd = bedutils.get_sort_cmd(tmpdir)
            cmd = "{{ echo '{header}'; cat {input_files} | {sort_cmd} -k3,3 -k4,4n; }} > {tx_out_file}"
            do.run(cmd.format(**locals()), "Combine prioritized from multiple callers")
    return out_file
1206064
def _finalize_merge(out_file, bam_files, config):
    
    # Ensure timestamps are up to date on output file and index
    # Works around issues on systems with inconsistent times
    for ext in ["", ".bai"]:
        if os.path.exists(out_file + ext):
            subprocess.check_call(["touch", out_file + ext])
    for b in bam_files:
        utils.save_diskspace(b, "BAM merged to %s" % out_file, config)
683898
def _combine_files(orig_files, base_out_file, data, fill_paths=True):
    
    orig_files = [x for x in orig_files if x and utils.file_exists(x)]
    if not orig_files:
        return None
    out_file = "%s-combine%s" % (utils.splitext_plus(base_out_file)[0],
                                    utils.splitext_plus(orig_files[0])[-1])
    with open(out_file, "w") as out_handle:
        for orig_file in orig_files:
            with open(orig_file) as in_handle:
                for line in in_handle:
                    if fill_paths and line.startswith("file"):
                        line = _fill_file_path(line, data)
                    out_handle.write(line)
            out_handle.write("\n\n")
    return out_file
1000507
def merge (dst, src):
        """"""
        for key in src.keys():
                if key not in dst:
                        dst[key] = src[key]
857917
public function merge()
    {
        // TODO: verify analysis phase run
        foreach ($this->dataFiles as $replicate => $fractions) {
            $firstFile = current($fractions);
            // Write header
            $this->writeHeader($firstFile['path'], $this->spectrumCount[$replicate], $this->outputFiles[$replicate]);

            // Resets vars
            $this->spectrumIdRef = array();
            $this->timeOffset = 0;
            $this->indexOffset = 0;
            $this->idOffset = 0;

            foreach ($fractions as $fractionIndex => $file) {
                $this->writeSpectrum($file['path'], $this->outputFiles[$replicate],
                    $this->fractionOffsets[$fractionIndex]);
            }

            $this->writeFooter($firstFile['path'], $this->outputFiles[$replicate]);
        }
    }
296301
def cleanup(self):
        """"""
        for file in glob.glob(self.basename + '*'):
            os.unlink(file)
591727
def combine_bam(in_files, out_file, config):
    
    runner = broad.runner_from_path("picard", config)
    runner.run_fn("picard_merge", in_files, out_file)
    for in_file in in_files:
        save_diskspace(in_file, "Merged into {0}".format(out_file), config)
    bam.index(out_file, config)
    return out_file
859075
def flush(self):
        
        if os.path.isdir(self._directory):
            for root, dirs, files in os.walk(self._directory, topdown=False):
                for name in files:
                    os.remove(os.path.join(root, name))

                for name in dirs:
                    os.rmdir(os.path.join(root, name))
134734
def _create_merge_filelist(bam_files, base_file, config):
    
    bam_file_list = "%s.list" % os.path.splitext(base_file)[0]
    samtools = config_utils.get_program("samtools", config)
    with open(bam_file_list, "w") as out_handle:
        for f in sorted(bam_files):
            do.run('{} quickcheck -v {}'.format(samtools, f),
                   "Ensure integrity of input merge BAM files")
            out_handle.write("%s\n" % f)
    return bam_file_list
1315678
def _merge_files(self, input_files, output_file):
        """"""
        # we assume that all the input files have the same charset
        with open(output_file, mode='wb') as out:
            for input_file in input_files:
                out.write(open(input_file, mode='rb').read())
1256636
def merge_replacement_files(tmpdir, mergefile):
  """"""
  # The fixes suggested by clang-tidy >= 4.0.0 are given under
  # the top level key 'Diagnostics' in the output yaml files
  mergekey="Diagnostics"
  merged=[]
  for replacefile in glob.iglob(os.path.join(tmpdir, '*.yaml')):
    content = yaml.safe_load(open(replacefile, 'r'))
    if not content:
      continue # Skip empty files.
    merged.extend(content.get(mergekey, []))

  if merged:
    # MainSourceFile: The key is required by the definition inside
    # include/clang/Tooling/ReplacementsYaml.h, but the value
    # is actually never used inside clang-apply-replacements,
    # so we set it to '' here.
    output = { 'MainSourceFile': '', mergekey: merged }
    with open(mergefile, 'w') as out:
      yaml.safe_dump(output, out)
  else:
    # Empty the file:
    open(mergefile, 'w').close()
49867
def merge(self, paths):
        

        # Use local topojson binary
        topojson_binary = 'node_modules/bin/topojson'

        if not os.path.exists(topojson_binary):
            # try with global topojson binary
            topojson_binary = 'topojson'

        merge_cmd = '%(binary)s -o %(output_path)s --bbox -p -- %(paths)s' % {
            'output_path': self.args.output_path,
            'paths': ' '.join(paths),
            'binary': topojson_binary
        }

        sys.stdout.write('Merging layers\n')

        if self.args.verbose:
            sys.stdout.write('  %s\n' % merge_cmd)

        r = envoy.run(merge_cmd)

        if r.status_code != 0:
            sys.stderr.write(r.std_err)