Ejemplo n.º 1
0
    def __init__(
        self,
        collection,
        nclusters,
        metric='euc',
        tmpdir=None,
    ):

        if not isinstance(nclusters, int) or nclusters <= 1:
            raise Exception('Need appropriate value for number of clusters.')

        self.nclusters = nclusters
        self.scorer = Scorer(collection.records,
                             collection.analysis)  # Could check for entries
        self.datatype = collection.datatype
        self.metric = metric

        try:
            self.tmpdir
        except:
            self.tmpdir = collection.tmpdir
Ejemplo n.º 2
0
    def __init__(self, nclusters, collection, tmpdir=TMPDIR,
                 analysis='nj', initial_assignment=None, scorer=None):
        optioncheck(analysis, ANALYSES + ['tc', 'TreeCollection'])
        if self.analysis == 'tc':
            self.analysis = 'TreeCollection'
        else:
            self.analysis = analysis

        self.Collection = collection

        if not self.Collection.records[0].tree:
            print('Calculating {} trees for collection...'.format(analysis))
            self.Collection.calc_NJ_trees()

        self.datatype = collection.datatype
        if scorer is not None and isinstance(scorer, Scorer):
            self.scorer = scorer
        else:
            self.scorer = Scorer(self.Collection)

        self.nclusters = nclusters
        self.tmpdir = tmpdir

        print('Calculating initial scores...')
        if initial_assignment is None:
            initial_assignment = Partition(tuple([0] * len(collection)))
            # initial_assignment = self.random_partition(nclusters)

        self.global_best_scores = {}
        self.global_best_assignments = {}
        self.global_best_scores[self.nclusters] = self.scorer.score(
            initial_assignment, history=True)
        self.global_best_assignments[self.nclusters] = initial_assignment

        self.done_worse = 0
        self.stayed_put = 0
        self.i = 0
        self.resets = 0
        self.merges = 0
Ejemplo n.º 3
0
 def __init__(self, members, records, analysis):
     self.members = tuple(members)
     self.records = [records[i] for i in self.members]
     self.scorer = Scorer(records, analysis)
     self.tree = self.scorer.add(self.members)
Ejemplo n.º 4
0
#!/usr/bin/env python

from collection import Collection, Scorer
from clustering import Partition
from random import randint
from anneal import *
import pickle

c = Collection(input_dir='/homes/mgperry/treeCl_data/easy_case/', compression='gz', file_format='phylip', datatype='protein')

scorer = Scorer(c.records, 'nj')

k = 4

partition = [randint(1, k) for rec in scorer.records]


def likelihood(partition, scorer):
    score = scorer.score(Partition(partition))
    return(score)

print type(partition)

opts = {'func': likelihood,
        'x0': partition,
        'args': [scorer],
        'schedule': 'cluster',
        'full_output': 1,
        'T0': 100000,
        'Tf': 1,
        'maxeval': None,