%prog consensus clustSfile

    Call consensus along the stacks. Tabulate bases at each site, tests for
    errors according to error rate, calls consensus.
189550
def consensus(args):
    
    p = OptionParser(consensus.__doc__)
    p.add_option("--ploidy", default=2, type="int",
                 help="Number of haplotypes per locus")
    add_consensus_options(p)
    p.set_verbose()
    opts, args = p.parse_args(args)

    if len(args) != 1:
        sys.exit(not p.print_help())

    clustSfile, = args
    pf = clustSfile.rsplit(".", 1)[0]
    mindepth = opts.mindepth
    minlength = opts.minlength
    verbose = opts.verbose

    C = ClustFile(clustSfile)
    output = []
    bins = []
    indices = []
    start = end = 0  # Index into base count array
    for data in C:
        names, seqs, nreps = zip(*data)
        total_nreps = sum(nreps)
        # Depth filter
        if total_nreps < mindepth:
            continue

        first_name, first_seq, first_nrep = data[0]
        fname = first_name.split(";")[0] + ";size={0};".format(total_nreps)
        cons_name, cons_seq, cons_nrep = get_seed(data)
        if len(data) > 1 and cons_name != CONSTAG:
            logging.debug("Tag {0} not found in cluster {1}".\
                        format(CONSTAG, cons_name))

        # List for sequence data
        S = [(seq, nrep) for name, seq, nrep in data if nrep]
        # Pileups for base counting
        RAD = stack(S)

        if len(data) == 1:   # No computation needed
            output.append((fname, seq))
            bins.extend(RAD)
            start = end
            end += len(seq)
            indices.append((fname, start, end))
            continue

        shortcon, shortRAD = compute_consensus(fname, cons_seq, \
                                RAD, S, total_nreps,
                                mindepth=mindepth, verbose=verbose)
        if len(shortcon) < minlength:
            cons_seq = seq
            shortcon, shortRAD = compute_consensus(fname, first_seq,\
                                RAD, S, total_nreps,
                                mindepth=mindepth, verbose=verbose)

        if len(shortcon) < minlength:   # Stop trying
            continue

        output.append((fname, shortcon))
        bins.extend(shortRAD)

        start = end
        end += len(shortcon)
        indices.append((fname, start, end))

    consensfile = pf + ".consensus"
    consens = open(consensfile, 'w')
    for k, v in output:
        print("\n".join((k, v)), file=consens)
    consens.close()
    logging.debug("Consensus sequences written to `{0}`".format(consensfile))

    binfile = consensfile + ".bin"
    bins = np.array(bins, dtype=np.uint32)
    ulimit = 65535
    bins[bins > ulimit] = ulimit
    bins = np.array(bins, dtype=np.uint16)  # Compact size
    bins.tofile(binfile)
    logging.debug("Allele counts written to `{0}`".format(binfile))

    idxfile = consensfile + ".idx"
    fw = open(idxfile, "w")
    for fname, start, end in indices:
        print("\t".join(str(x) for x in (fname, start, end)), file=fw)
    fw.close()
    logging.debug("Serializing indices to `{0}`".format(idxfile))

    return consensfile, binfile, idxfile
203937
def get_block_from_consensus( self, consensus_hash ):
        
        query = 'SELECT block_id FROM snapshots WHERE consensus_hash = ?;'
        args = (consensus_hash,)

        con = self.db_open(self.impl, self.working_dir)
        rows = self.db_query_execute(con, query, args, verbose=False)
        res = None

        for r in rows:
            res = r['block_id']

        con.close()
        return res
588384
def fillstats(args):
    
    from jcvi.utils.cbook import SummaryStats, percentage, thousands

    p = OptionParser(fillstats.__doc__)
    opts, args = p.parse_args(args)

    if len(args) != 1:
        sys.exit(not p.print_help())

    fillfile, = args
    fp = open(fillfile)
    scaffolds = 0
    gaps = []
    for row in fp:
        if row[0] == ">":
            scaffolds += 1
            continue
        fl = FillLine(row)
        gaps.append(fl)

    print("{0} scaffolds in total".format(scaffolds), file=sys.stderr)

    closed = [x for x in gaps if x.closed]
    closedbp = sum(x.before for x in closed)
    notClosed = [x for x in gaps if not x.closed]
    notClosedbp = sum(x.before for x in notClosed)

    totalgaps = len(closed) + len(notClosed)

    print("Closed gaps: {0} size: {1} bp".\
                        format(percentage(len(closed), totalgaps), thousands(closedbp)), file=sys.stderr)
    ss = SummaryStats([x.after for x in closed])
    print(ss, file=sys.stderr)

    ss = SummaryStats([x.delta for x in closed])
    print("Delta:", ss, file=sys.stderr)

    print("Remaining gaps: {0} size: {1} bp".\
                        format(percentage(len(notClosed), totalgaps), thousands(notClosedbp)), file=sys.stderr)
    ss = SummaryStats([x.after for x in notClosed])
    print(ss, file=sys.stderr)
1221766
def collapse_to_consensus(seqrecords, strict=False, do_iron=True):
    
    level = 0
    name = seqrecords[0].id
    # If this is a CMA alignment, extract additional info:
    if hasattr(seqrecords, '_records'):
        if hasattr(seqrecords, 'level'):
            level = seqrecords.level
        if hasattr(seqrecords, 'name'):
            name = seqrecords.name
        seqrecords = seqrecords._records

    consensus = seqrecords.pop(0)
    cons_length = len(consensus)
    for i, s in enumerate(seqrecords):
        if len(s) != cons_length:
            raise ValueError(
            "Sequence #%d has length %d, consensus is %d"
            % (i+2, len(s), cons_length))

    if '.' in str(consensus.seq):
        # Strict -- error if there's a '-'
        if '-' in str(consensus.seq):
            if strict:
                raise ValueError("Consensus contains '-' gap characters")
            logging.warn("Consensus sequence contains both '.' and '-' gap "
                         "characters -- is it really the consensus?")
            aligned_cols = [(c not in '.-') for c in str(consensus.seq)]
        else:
            aligned_cols = [c != '.' for c in str(consensus.seq)]
    else:
        # A little more ambiguous...
        aligned_cols = [c != '-' for c in str(consensus.seq)]

    consensus.seq = replace_asterisks(consensus.seq, 'consensus')
    # Start a block with the consensus sequence
    block = consensus2block(consensus, level=level, name=name)
    qlen = block['query_length']

    # Collapse & add remaining sequences to the block
    for index, rec in zip(xrange(2, len(seqrecords)+2), seqrecords):
        # Collapse rec.seq down to aligned size
        new_mol_seq = []
        is_beginning = True
        for aligned_col, char in zip(aligned_cols,
                                     replace_asterisks(rec.seq, index)):
            if aligned_col:
                is_beginning = False
                if char in '-.':
                    # deletion
                    new_mol_seq.append('-')
                else:
                    # aligned character
                    new_mol_seq.append(char.upper())
            else:
                # it's an insert or nothing
                # (also, skip any left-side inserts)
                if char not in '-.' and not is_beginning:
                    new_mol_seq.append(char.lower())
        rec.seq = ''.join(new_mol_seq)
        if do_iron:
            rec.seq = iron(rec.seq)
        block['sequences'].append(seqrecord2sequence(rec, qlen, index))

    return block
219995
def _human_score_map(human_consensus, methods_attrs):
    

    v = 1 - min(np.sum(np.abs(methods_attrs - human_consensus)) / (np.abs(human_consensus).sum() + 1), 1.0)
    return v
1327489
def info(args):
    
    p = OptionParser(info.__doc__)
    p.add_option("--gaps", default=False, action="store_true",
                 help="Count number of gaps [default: %default]")
    p.set_table()
    p.set_outfile()
    opts, args = p.parse_args(args)

    if len(args) == 0:
        sys.exit(not p.print_help())

    fastafiles = args
    data = []
    for f in fastafiles:
        s = SequenceInfo(f, gapstats=opts.gaps)
        data.append(s.data)
    write_csv(s.header, data, sep=opts.sep,
              filename=opts.outfile, align=opts.align)
1100962
def _bsecurate_cli_elements_in_files(args):
    ''''''
    data = curate.elements_in_files(args.files)
    return '\n'.join(format_columns(data.items()))
1283728
def cli(yamlfile, root, format):
    
    print(CsvGenerator(yamlfile, format).serialize(classes=root))
793979
def show_top(**kwargs):
    '''
    
    '''
    __opts__['grains'] = __grains__
    opts = salt.utils.state.get_sls_opts(__opts__, **kwargs)
    st_ = salt.client.ssh.state.SSHHighState(
            opts,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    top_data = st_.get_top()
    errors = []
    errors += st_.verify_tops(top_data)
    if errors:
        return errors
    matches = st_.top_matches(top_data)
    return matches
1159440
def call(*args)

      bottom = stack_top

      load_onto_stack
        # load function on stack

      args.each { |arg| stack_push(arg) }
        # push arguments on stack

      pcall(bottom, args.length, nil, nil, nil)
    end
1112968
def append(args):
    
    p = OptionParser(append.__doc__)
    p.set_sep()
    p.set_outfile()
    opts, args = p.parse_args(args)

    nargs = len(args)
    if nargs not in (1, 2):
        sys.exit(not p.print_help())

    csvfile = args[0]
    tag = args[1] if nargs == 2 else csvfile
    fp = must_open(csvfile)
    fw = must_open(opts.outfile, "w")
    for row in fp:
        row = row.rstrip("\r\n")
        row = opts.sep.join((row, tag))
        print(row, file=fw)
1056461
def run_setup_error_group():
  
  test = htf.Test(htf.PhaseGroup(
      setup=[error_setup_phase],
      main=[main_phase],
      teardown=[teardown_phase],
  ))
  test.execute()
561221
def _bsecurate_cli_compare_basis_files(args):
    ''''''
    ret = curate.compare_basis_files(args.file1, args.file2, args.readfmt1, args.readfmt2, args.uncontract_general)

    if ret:
        return "No difference found"
    else:
        return "DIFFERENCES FOUND. SEE ABOVE"
467051
def cli_action(args):
    
    problem = read_param_file(args.paramfile)
    param_values = sample(problem, seed=args.seed)
    np.savetxt(args.output, param_values, delimiter=args.delimiter,
               fmt='%.' + str(args.precision) + 'e')
1353656
function group_errors(errors) {

	/**
	 *  Array of objects for error groups, initialize with object for errors of
   *  uknown origin (fallback group).
	 */

	var error_groups = [
    {
  		file: '(unknown file)',
  		errors: []
    }
  ];

	var filenames = []; // Array for already used filenames.
	var group_found = false; // Boolean for cases when error group isn't found
                           // --> fallbacks to 'unknown' group.

	/**
	 *	Loop through errors.
	 */

	for (var e = 0; e < errors.length; e++) {

		group_found = false;

		var error = errors[e];

		/**
		 *	Check if there already is a group for this file's errors.
		 */

		if (! error.file || filenames.indexOf(error.file) >= 0) {

			/**
			 *	Group already exists, now we'll loop through the error groups
       *  to find the one matching the filename.
			 */

			for (var eg in error_groups) {
				if (error_groups[eg].file === error.file) {

					/**
					 *	Filename matches, now append error to group's array of errors.
					 */

					error_groups[eg].errors.push(error.error);

					/**
					 *	Set boolean [group_found] to true to make sure error isn't
           *  added into the fallback group.
					 */

					group_found = true;

				}
			}

			/**
			 *	If group was not found, add to fallback group.
			 */

			if (group_found === false) {
				error_groups[0].errors.push(error.error);
			}

		} else {

			/**
			 *	Group doesn't exist, create it with current error if error exists.
			 */

			if (error.error && (error.error instanceof Object) && ! (error.error instanceof Array)) {

				var error_group = {
					file: error.file,
					errors: [error.error]
				};

				error_groups.push(error_group);

				/**
				 *	Add error's filename into used filenames.
				 */

				filenames.push(error.file);

			}

		}

	}

	/**
	 *	Returned organized errors, but only if there are errors.
	 */

	if (error_groups.length > 1 || (error_groups[0].errors.length > 0)) {
		return error_groups;
	}

	/**
	 *	Elsewise return empty string.
	 */

	return '';

}
120746
def run():
    """"""

    # Use print() instead of logging when running in CLI mode:
    set_pyftpsync_logger(None)

    parser = argparse.ArgumentParser(
        description="Synchronize folders over FTP.",
        epilog="See also https://github.com/mar10/pyftpsync",
        parents=[verbose_parser],
    )

    # Note: we want to allow --version to be combined with --verbose. However
    # on Py2, argparse makes sub-commands mandatory, unless `action="version"` is used.
    if check_cli_verbose(3) > 3:
        version_info = "pyftpsync/{} Python/{} {}".format(
            __version__, PYTHON_VERSION, platform.platform()
        )
    else:
        version_info = "{}".format(__version__)

    parser.add_argument("-V", "--version", action="version", version=version_info)

    subparsers = parser.add_subparsers(help="sub-command help")

    # --- Create the parser for the "upload" command ---------------------------

    sp = subparsers.add_parser(
        "upload",
        parents=[verbose_parser, common_parser, matcher_parser, creds_parser],
        help="copy new and modified files to remote folder",
    )

    sp.add_argument(
        "local",
        metavar="LOCAL",
        default=".",
        help="path to local folder (default: %(default)s)",
    )
    sp.add_argument("remote", metavar="REMOTE", help="path to remote folder")
    sp.add_argument(
        "--force",
        action="store_true",
        help="overwrite remote files, even if the target is newer "
        "(but no conflict was detected)",
    )
    sp.add_argument(
        "--resolve",
        default="ask",
        choices=["local", "skip", "ask"],
        help="conflict resolving strategy (default: '%(default)s')",
    )
    sp.add_argument(
        "--delete",
        action="store_true",
        help="remove remote files if they don't exist locally",
    )
    sp.add_argument(
        "--delete-unmatched",
        action="store_true",
        help="remove remote files if they don't exist locally "
        "or don't match the current filter (implies '--delete' option)",
    )

    sp.set_defaults(command="upload")

    # --- Create the parser for the "download" command -------------------------

    sp = subparsers.add_parser(
        "download",
        parents=[verbose_parser, common_parser, matcher_parser, creds_parser],
        help="copy new and modified files from remote folder to local target",
    )

    sp.add_argument(
        "local",
        metavar="LOCAL",
        default=".",
        help="path to local folder (default: %(default)s)",
    )
    sp.add_argument("remote", metavar="REMOTE", help="path to remote folder")
    sp.add_argument(
        "--force",
        action="store_true",
        help="overwrite local files, even if the target is newer "
        "(but no conflict was detected)",
    )
    sp.add_argument(
        "--resolve",
        default="ask",
        choices=["remote", "skip", "ask"],
        help="conflict resolving strategy (default: '%(default)s')",
    )
    sp.add_argument(
        "--delete",
        action="store_true",
        help="remove local files if they don't exist on remote target",
    )
    sp.add_argument(
        "--delete-unmatched",
        action="store_true",
        help="remove local files if they don't exist on remote target "
        "or don't match the current filter (implies '--delete' option)",
    )

    sp.set_defaults(command="download")

    # --- Create the parser for the "sync" command -----------------------------

    sp = subparsers.add_parser(
        "sync",
        parents=[verbose_parser, common_parser, matcher_parser, creds_parser],
        help="synchronize new and modified files between remote folder and local target",
    )

    sp.add_argument(
        "local",
        metavar="LOCAL",
        default=".",
        help="path to local folder (default: %(default)s)",
    )
    sp.add_argument("remote", metavar="REMOTE", help="path to remote folder")
    sp.add_argument(
        "--resolve",
        default="ask",
        choices=["old", "new", "local", "remote", "skip", "ask"],
        help="conflict resolving strategy (default: '%(default)s')",
    )

    sp.set_defaults(command="sync")

    # --- Create the parser for the "run" command -----------------------------

    add_run_parser(subparsers)

    # --- Create the parser for the "scan" command -----------------------------

    add_scan_parser(subparsers)

    # --- Parse command line ---------------------------------------------------

    args = parser.parse_args()

    args.verbose -= args.quiet
    del args.quiet

    # print("verbose", args.verbose)

    ftp_debug = 0
    if args.verbose >= 6:
        ftp_debug = 1

    # Modify the `args` from the `pyftpsync.yaml` config:
    if getattr(args, "command", None) == "run":
        handle_run_command(parser, args)

    if callable(getattr(args, "command", None)):
        # scan_handler
        try:
            return args.command(parser, args)
        except KeyboardInterrupt:
            print("\nAborted by user.", file=sys.stderr)
            sys.exit(3)

    elif not hasattr(args, "command"):
        parser.error(
            "missing command (choose from 'upload', 'download', 'run', 'sync', 'scan')"
        )

    # Post-process and check arguments
    if hasattr(args, "delete_unmatched") and args.delete_unmatched:
        args.delete = True

    args.local_target = make_target(args.local, {"ftp_debug": ftp_debug})

    if args.remote == ".":
        parser.error("'.' is expected to be the local target (not remote)")
    args.remote_target = make_target(args.remote, {"ftp_debug": ftp_debug})
    if not isinstance(args.local_target, FsTarget) and isinstance(
        args.remote_target, FsTarget
    ):
        parser.error("a file system target is expected to be local")

    # Let the command handler do its thing
    opts = namespace_to_dict(args)
    if args.command == "upload":
        s = UploadSynchronizer(args.local_target, args.remote_target, opts)
    elif args.command == "download":
        s = DownloadSynchronizer(args.local_target, args.remote_target, opts)
    elif args.command == "sync":
        s = BiDirSynchronizer(args.local_target, args.remote_target, opts)
    else:
        parser.error("unknown command '{}'".format(args.command))

    s.is_script = True

    try:
        s.run()
    except KeyboardInterrupt:
        print("\nAborted by user.", file=sys.stderr)
        sys.exit(3)
    finally:
        # Prevent sporadic exceptions in ftplib, when closing in __del__
        s.local.close()
        s.remote.close()

    stats = s.get_stats()
    if args.verbose >= 5:
        pprint(stats)
    elif args.verbose >= 1:
        if args.dry_run:
            print("(DRY-RUN) ", end="")
        print(
            "Wrote {}/{} files in {} directories, skipped: {}.".format(
                stats["files_written"],
                stats["local_files"],
                stats["local_dirs"],
                stats["conflict_files_skipped"],
            ),
            end="",
        )
        if stats["interactive_ask"]:
            print()
        else:
            print(" Elap: {}.".format(stats["elap_str"]))

    return
372511
def converge(ctx, scenario_name, ansible_args):  # pragma: no cover
    

    args = ctx.obj.get('args')
    subcommand = base._get_subcommand(__name__)
    command_args = {
        'subcommand': subcommand,
    }

    base.execute_cmdline_scenarios(scenario_name, args, command_args)