예제 #1
0
 def evaluate(self, true_splits, D_estimated):
     """
     @param true_splits: the set of all full splits implied by the true tree
     @param D_estimated: the estimated distance matrix
     """
     self.true_splits = true_splits
     BuildTreeTopology.get_splits(D_estimated, self.split_function, BuildTreeTopology.update_using_laplacian, self.on_label_split)
예제 #2
0
 def evaluate(self, true_splits, D_estimated, atteson, use_nj, use_modified_nj, use_all_spectral, use_one_spectral):
     """
     @param true_splits: the set of all full splits implied by the true tree
     @param D_estimated: the estimated distance matrix
     @param atteson: True iff the distance matrix is Atteson
     """
     # initialize the errors
     nj_error = None
     modified_nj_error = None
     all_spectral_error = None
     one_spectral_error = None
     if use_nj:
         nj_splits = BuildTreeTopology.get_splits(D_estimated, BuildTreeTopology.split_nj, BuildTreeTopology.update_nj)
         nj_error = Xtree.splits_to_rf_distance(nj_splits, true_splits)
     if use_modified_nj:
         modified_nj_splits = BuildTreeTopology.get_splits(D_estimated, BuildTreeTopology.split_nj, BuildTreeTopology.update_using_laplacian)
         modified_nj_error = Xtree.splits_to_rf_distance(modified_nj_splits, true_splits)
     if use_all_spectral:
         splitter = BuildTreeTopology.split_using_eigenvector_with_nj_fallback
         updater = BuildTreeTopology.update_using_laplacian
         all_spectral_splits = BuildTreeTopology.get_splits(D_estimated, splitter, updater)
         all_spectral_error = Xtree.splits_to_rf_distance(all_spectral_splits, true_splits)
     if use_one_spectral:
         splitter = SplitFunctor(len(D_estimated))
         updater = UpdateFunctor(len(D_estimated))
         one_spectral_splits = BuildTreeTopology.get_splits(D_estimated, splitter, updater)
         one_spectral_error = Xtree.splits_to_rf_distance(one_spectral_splits, true_splits)
     # add the data point
     self.scatter_points.append(ScatterPoint(atteson, nj_error, modified_nj_error, all_spectral_error, one_spectral_error))
예제 #3
0
def do_it_right(D):
    """
    Do neighbor joining correctly.
    @param D: distance matrix
    @return: a sequence of splits
    """
    # use neighbor joining to build the tree, saving the splits in the order they are made
    split_saver = SplitSaver()
    BuildTreeTopology.get_splits(D, BuildTreeTopology.split_nj, BuildTreeTopology.update_nj, split_saver)
    return split_saver.splits
예제 #4
0
def get_response_content(fs):
    # read the matrix
    D = fs.matrix
    # read the ordered labels
    ordered_labels = Util.get_stripped_lines(StringIO(fs.labels))
    # validate the input
    if len(D) != len(ordered_labels):
        raise HandlingError('the number of taxon labels should match the number of rows in the distance matrix')
    # get the split and update methods
    if fs.option_a:
        split_function = BuildTreeTopology.split_nj
        update_function = BuildTreeTopology.update_nj
    elif fs.option_b:
        split_function = BuildTreeTopology.split_nj
        update_function = BuildTreeTopology.update_using_laplacian
    elif fs.option_c:
        split_function = BuildTreeTopology.split_using_eigenvector_with_nj_fallback
        update_function = BuildTreeTopology.update_using_laplacian
    elif fs.option_d:
        split_function = BuildTreeTopology.split_using_eigenvector
        update_function = BuildTreeTopology.update_using_laplacian
    # get the splits
    index_splits = BuildTreeTopology.get_splits(D, split_function, update_function)
    # start to prepare the reponse
    out = StringIO()
    for index_split in index_splits:
        taxon_split = [[ordered_labels[i] for i in group] for group in index_split]
        print >> out, split_to_string(taxon_split)
    # write the response
    return out.getvalue()
예제 #5
0
 def evaluate(self, true_splits, D_estimated):
     """
     @param true_splits: a set of full splits that defines the true tree topology
     @param D_estimated: an estimated distance matrix conformant to the split labels
     @return: 1 if success, 0 if failure
     """
     estimated_splits = BuildTreeTopology.get_splits(D_estimated, self.split_function, self.update_function)
     if estimated_splits == true_splits:
         return 1
     else:
         return 0
예제 #6
0
 def evaluate(self, true_splits, D_estimated, atteson, use_nj,
              use_modified_nj, use_all_spectral, use_one_spectral):
     """
     @param true_splits: the set of all full splits implied by the true tree
     @param D_estimated: the estimated distance matrix
     @param atteson: True iff the distance matrix is Atteson
     """
     # initialize the errors
     nj_error = None
     modified_nj_error = None
     all_spectral_error = None
     one_spectral_error = None
     if use_nj:
         nj_splits = BuildTreeTopology.get_splits(
             D_estimated, BuildTreeTopology.split_nj,
             BuildTreeTopology.update_nj)
         nj_error = Xtree.splits_to_rf_distance(nj_splits, true_splits)
     if use_modified_nj:
         modified_nj_splits = BuildTreeTopology.get_splits(
             D_estimated, BuildTreeTopology.split_nj,
             BuildTreeTopology.update_using_laplacian)
         modified_nj_error = Xtree.splits_to_rf_distance(
             modified_nj_splits, true_splits)
     if use_all_spectral:
         splitter = BuildTreeTopology.split_using_eigenvector_with_nj_fallback
         updater = BuildTreeTopology.update_using_laplacian
         all_spectral_splits = BuildTreeTopology.get_splits(
             D_estimated, splitter, updater)
         all_spectral_error = Xtree.splits_to_rf_distance(
             all_spectral_splits, true_splits)
     if use_one_spectral:
         splitter = SplitFunctor(len(D_estimated))
         updater = UpdateFunctor(len(D_estimated))
         one_spectral_splits = BuildTreeTopology.get_splits(
             D_estimated, splitter, updater)
         one_spectral_error = Xtree.splits_to_rf_distance(
             one_spectral_splits, true_splits)
     # add the data point
     self.scatter_points.append(
         ScatterPoint(atteson, nj_error, modified_nj_error,
                      all_spectral_error, one_spectral_error))
예제 #7
0
 def evaluate(self, true_splits, D_estimated):
     """
     @param true_splits: a set of full splits that defines the true tree topology
     @param D_estimated: an estimated distance matrix conformant to the split labels
     @return: 1 if success, 0 if failure
     """
     estimated_splits = BuildTreeTopology.get_splits(
         D_estimated, self.split_function, self.update_function)
     if estimated_splits == true_splits:
         return 1
     else:
         return 0
예제 #8
0
파일: 20090805a.py 프로젝트: BIGtigr/xgcode
 try:
     D = sample_distance_matrix(tree, sequence_length)
 except InfiniteDistanceError as e:
     return incr_attribute(attribute_array, 'nsamples.rejected.inf')
 except ZeroDistanceError as e:
     return incr_attribute(attribute_array, 'nsamples.rejected.zero')
 except BuildTreeTopology.InvalidSpectralSplitException, e:
     return incr_attribute(attribute_array, 'nsamples.rejected.fail')
 # see if the top down reconstruction was successful
 try:
     splitter = BuildTreeTopology.split_using_eigenvector_with_nj_fallback
     if nj_like:
         updater = BuildTreeTopology.update_generalized_nj
     else:
         updater = BuildTreeTopology.update_using_laplacian
     all_spectral_splits = BuildTreeTopology.get_splits(
         D, splitter, updater)
     top_down_success = (all_spectral_splits == true_splits)
 except BuildTreeTopology.InvalidSpectralSplitException, e:
     return incr_attribute(attribute_array, 'nsamples.rejected.fail')
 # at this point the sample is accepted
 incr_attribute(attribute_array, 'nsamples.accepted')
 # determine whether or not the distance matrix is Atteson with respect to the tree
 if BuildTreeTopology.is_atteson(tree, D):
     incr_attribute(attribute_array, 'nsamples.accepted.atteson')
 # see if the bottom up reconstruction was successful
 nj_splits = BuildTreeTopology.get_splits(D, BuildTreeTopology.split_nj,
                                          BuildTreeTopology.update_nj)
 nj_success = (nj_splits == true_splits)
 # note the joint results of the two reconstruction methods
 if top_down_success and nj_success:
     incr_attribute(attribute_array, 'nsuccesses.both')
예제 #9
0
 try:
     D = sample_distance_matrix(tree, sequence_length)
 except InfiniteDistanceError as e:
     return incr_attribute(attribute_array, 'nsamples.rejected.inf')
 except ZeroDistanceError as e:
     return incr_attribute(attribute_array, 'nsamples.rejected.zero')
 except BuildTreeTopology.InvalidSpectralSplitException, e:
     return incr_attribute(attribute_array, 'nsamples.rejected.fail')
 # see if the top down reconstruction was successful
 try:
     splitter = BuildTreeTopology.split_using_eigenvector_with_nj_fallback
     if nj_like:
         updater = BuildTreeTopology.update_generalized_nj
     else:
         updater = BuildTreeTopology.update_using_laplacian
     all_spectral_splits = BuildTreeTopology.get_splits(D, splitter, updater)
     top_down_success = (all_spectral_splits == true_splits)
 except BuildTreeTopology.InvalidSpectralSplitException, e:
     return incr_attribute(attribute_array, 'nsamples.rejected.fail')
 # at this point the sample is accepted
 incr_attribute(attribute_array, 'nsamples.accepted')
 # determine whether or not the distance matrix is Atteson with respect to the tree
 if BuildTreeTopology.is_atteson(tree, D):
     incr_attribute(attribute_array, 'nsamples.accepted.atteson')
 # see if the bottom up reconstruction was successful
 nj_splits = BuildTreeTopology.get_splits(D, BuildTreeTopology.split_nj, BuildTreeTopology.update_nj)
 nj_success = (nj_splits == true_splits)
 # note the joint results of the two reconstruction methods
 if top_down_success and nj_success:
     incr_attribute(attribute_array, 'nsuccesses.both')
 elif (not top_down_success) and (not nj_success):