#!/usr/bin/python
import sys
import argparse

parser = argparse.ArgumentParser(
    description="""Command-line benchmark utility.""",
    formatter_class=argparse.RawDescriptionHelpFormatter,
    add_help=False)

parser.add_argument('vambpath', help='Path to vamb directory')
parser.add_argument('clusterspath', help='Path to clusters.tsv')
parser.add_argument('refpath', help='Path to reference file')
parser.add_argument('--tax', dest='taxpath', help='Path to taxonomic maps')
parser.add_argument('-m', dest='min_bin_size', metavar='', type=int,
                    default=200000, help='Minimum size of bins [200000]')
parser.add_argument('-s', dest='separator', help='Binsplit separator', default=None)
parser.add_argument('--disjoint', action='store_true', help='Enforce disjoint clusters')

if len(sys.argv) == 1:
    parser.print_help()
    sys.exit()

args = parser.parse_args()

sys.path.append(args.vambpath)
import vamb
import os

# Check that files exist
for path in args.clusterspath, args.refpath, args.taxpath:
    if path is not None and not os.path.isfile(path):
        raise FileNotFoundError(path)

with open(args.clusterspath) as file:
    clusters = vamb.cluster.read_clusters(file)

with open(args.refpath) as file:
    reference = vamb.benchmark.Reference.from_file(file)

if args.taxpath is not None:
    with open(args.taxpath) as file:
        reference.load_tax_file(file)

binning = vamb.benchmark.Binning(clusters, reference, minsize=args.min_bin_size, disjoint=args.disjoint,
                            binsplit_separator=args.separator)

print('#genome', 'bestbin', 'F1', 'recall', 'precision', sep='\t')
for genome in reference.genomes.values():
    dict_ = binning.intersectionsof.get(genome, dict())
    bestbin, bestf1, recall, precision = 'NA', 'NA', 'NA', 'NA'
    for binname, intersection in dict_.items():
        tp, tn, fp, fn = binning.confusion_matrix(genome, binname)
        f1 = 2*tp / (2*tp + fp + fn)
        if bestf1 == 'NA' or f1 > bestf1:
            bestf1 = f1
            recall = tp / (tp + fn)
            precision = tp / (tp + fp)
            bestbin = binname

    print('{}\t{}\t{}\t{}\t{}'.format(genome.name, bestbin, bestf1, recall, precision))

7a11d072bc813107fb58297752ed88dfde6ff46a
<mask token>

<mask token>
parser.add_argument('vambpath', help='Path to vamb directory')
parser.add_argument('clusterspath', help='Path to clusters.tsv')
parser.add_argument('refpath', help='Path to reference file')
parser.add_argument('--tax', dest='taxpath', help='Path to taxonomic maps')
parser.add_argument('-m', dest='min_bin_size', metavar='', type=int,
    default=200000, help='Minimum size of bins [200000]')
parser.add_argument('-s', dest='separator', help='Binsplit separator',
    default=None)
parser.add_argument('--disjoint', action='store_true', help=
    'Enforce disjoint clusters')
if len(sys.argv) == 1:
    parser.print_help()
    sys.exit()
<mask token>
sys.path.append(args.vambpath)
<mask token>
for path in (args.clusterspath, args.refpath, args.taxpath):
    if path is not None and not os.path.isfile(path):
        raise FileNotFoundError(path)
with open(args.clusterspath) as file:
    clusters = vamb.cluster.read_clusters(file)
with open(args.refpath) as file:
    reference = vamb.benchmark.Reference.from_file(file)
if args.taxpath is not None:
    with open(args.taxpath) as file:
        reference.load_tax_file(file)
<mask token>
print('#genome', 'bestbin', 'F1', 'recall', 'precision', sep='\t')
for genome in reference.genomes.values():
    dict_ = binning.intersectionsof.get(genome, dict())
    bestbin, bestf1, recall, precision = 'NA', 'NA', 'NA', 'NA'
    for binname, intersection in dict_.items():
        tp, tn, fp, fn = binning.confusion_matrix(genome, binname)
        f1 = 2 * tp / (2 * tp + fp + fn)
        if bestf1 == 'NA' or f1 > bestf1:
            bestf1 = f1
            recall = tp / (tp + fn)
            precision = tp / (tp + fp)
            bestbin = binname
    print('{}\t{}\t{}\t{}\t{}'.format(genome.name, bestbin, bestf1, recall,
        precision))

<mask token>
parser = argparse.ArgumentParser(description=
    'Command-line benchmark utility.', formatter_class=argparse.
    RawDescriptionHelpFormatter, add_help=False)
parser.add_argument('vambpath', help='Path to vamb directory')
parser.add_argument('clusterspath', help='Path to clusters.tsv')
parser.add_argument('refpath', help='Path to reference file')
parser.add_argument('--tax', dest='taxpath', help='Path to taxonomic maps')
parser.add_argument('-m', dest='min_bin_size', metavar='', type=int,
    default=200000, help='Minimum size of bins [200000]')
parser.add_argument('-s', dest='separator', help='Binsplit separator',
    default=None)
parser.add_argument('--disjoint', action='store_true', help=
    'Enforce disjoint clusters')
if len(sys.argv) == 1:
    parser.print_help()
    sys.exit()
args = parser.parse_args()
sys.path.append(args.vambpath)
<mask token>
for path in (args.clusterspath, args.refpath, args.taxpath):
    if path is not None and not os.path.isfile(path):
        raise FileNotFoundError(path)
with open(args.clusterspath) as file:
    clusters = vamb.cluster.read_clusters(file)
with open(args.refpath) as file:
    reference = vamb.benchmark.Reference.from_file(file)
if args.taxpath is not None:
    with open(args.taxpath) as file:
        reference.load_tax_file(file)
binning = vamb.benchmark.Binning(clusters, reference, minsize=args.
    min_bin_size, disjoint=args.disjoint, binsplit_separator=args.separator)
print('#genome', 'bestbin', 'F1', 'recall', 'precision', sep='\t')
for genome in reference.genomes.values():
    dict_ = binning.intersectionsof.get(genome, dict())
    bestbin, bestf1, recall, precision = 'NA', 'NA', 'NA', 'NA'
    for binname, intersection in dict_.items():
        tp, tn, fp, fn = binning.confusion_matrix(genome, binname)
        f1 = 2 * tp / (2 * tp + fp + fn)
        if bestf1 == 'NA' or f1 > bestf1:
            bestf1 = f1
            recall = tp / (tp + fn)
            precision = tp / (tp + fp)
            bestbin = binname
    print('{}\t{}\t{}\t{}\t{}'.format(genome.name, bestbin, bestf1, recall,
        precision))

import sys
import argparse
parser = argparse.ArgumentParser(description=
    'Command-line benchmark utility.', formatter_class=argparse.
    RawDescriptionHelpFormatter, add_help=False)
parser.add_argument('vambpath', help='Path to vamb directory')
parser.add_argument('clusterspath', help='Path to clusters.tsv')
parser.add_argument('refpath', help='Path to reference file')
parser.add_argument('--tax', dest='taxpath', help='Path to taxonomic maps')
parser.add_argument('-m', dest='min_bin_size', metavar='', type=int,
    default=200000, help='Minimum size of bins [200000]')
parser.add_argument('-s', dest='separator', help='Binsplit separator',
    default=None)
parser.add_argument('--disjoint', action='store_true', help=
    'Enforce disjoint clusters')
if len(sys.argv) == 1:
    parser.print_help()
    sys.exit()
args = parser.parse_args()
sys.path.append(args.vambpath)
import vamb
import os
for path in (args.clusterspath, args.refpath, args.taxpath):
    if path is not None and not os.path.isfile(path):
        raise FileNotFoundError(path)
with open(args.clusterspath) as file:
    clusters = vamb.cluster.read_clusters(file)
with open(args.refpath) as file:
    reference = vamb.benchmark.Reference.from_file(file)
if args.taxpath is not None:
    with open(args.taxpath) as file:
        reference.load_tax_file(file)
binning = vamb.benchmark.Binning(clusters, reference, minsize=args.
    min_bin_size, disjoint=args.disjoint, binsplit_separator=args.separator)
print('#genome', 'bestbin', 'F1', 'recall', 'precision', sep='\t')
for genome in reference.genomes.values():
    dict_ = binning.intersectionsof.get(genome, dict())
    bestbin, bestf1, recall, precision = 'NA', 'NA', 'NA', 'NA'
    for binname, intersection in dict_.items():
        tp, tn, fp, fn = binning.confusion_matrix(genome, binname)
        f1 = 2 * tp / (2 * tp + fp + fn)
        if bestf1 == 'NA' or f1 > bestf1:
            bestf1 = f1
            recall = tp / (tp + fn)
            precision = tp / (tp + fp)
            bestbin = binname
    print('{}\t{}\t{}\t{}\t{}'.format(genome.name, bestbin, bestf1, recall,
        precision))

#!/usr/bin/python
import sys
import argparse

parser = argparse.ArgumentParser(
    description="""Command-line benchmark utility.""",
    formatter_class=argparse.RawDescriptionHelpFormatter,
    add_help=False)

parser.add_argument('vambpath', help='Path to vamb directory')
parser.add_argument('clusterspath', help='Path to clusters.tsv')
parser.add_argument('refpath', help='Path to reference file')
parser.add_argument('--tax', dest='taxpath', help='Path to taxonomic maps')
parser.add_argument('-m', dest='min_bin_size', metavar='', type=int,
                    default=200000, help='Minimum size of bins [200000]')
parser.add_argument('-s', dest='separator', help='Binsplit separator', default=None)
parser.add_argument('--disjoint', action='store_true', help='Enforce disjoint clusters')

if len(sys.argv) == 1:
    parser.print_help()
    sys.exit()

args = parser.parse_args()

sys.path.append(args.vambpath)
import vamb
import os

# Check that files exist
for path in args.clusterspath, args.refpath, args.taxpath:
    if path is not None and not os.path.isfile(path):
        raise FileNotFoundError(path)

with open(args.clusterspath) as file:
    clusters = vamb.cluster.read_clusters(file)

with open(args.refpath) as file:
    reference = vamb.benchmark.Reference.from_file(file)

if args.taxpath is not None:
    with open(args.taxpath) as file:
        reference.load_tax_file(file)

binning = vamb.benchmark.Binning(clusters, reference, minsize=args.min_bin_size, disjoint=args.disjoint,
                            binsplit_separator=args.separator)

print('#genome', 'bestbin', 'F1', 'recall', 'precision', sep='\t')
for genome in reference.genomes.values():
    dict_ = binning.intersectionsof.get(genome, dict())
    bestbin, bestf1, recall, precision = 'NA', 'NA', 'NA', 'NA'
    for binname, intersection in dict_.items():
        tp, tn, fp, fn = binning.confusion_matrix(genome, binname)
        f1 = 2*tp / (2*tp + fp + fn)
        if bestf1 == 'NA' or f1 > bestf1:
            bestf1 = f1
            recall = tp / (tp + fn)
            precision = tp / (tp + fp)
            bestbin = binname

    print('{}\t{}\t{}\t{}\t{}'.format(genome.name, bestbin, bestf1, recall, precision))
