Changeset 1220 for framspy


Ignore:
Timestamp:
04/17/23 02:30:51 (21 months ago)
Author:
Maciej Komosinski
Message:

Added support for two more phenetic dissimilarity estimation methods, which compare the distributions of samples in the two phenotypes (bodies)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/FramsticksLib.py

    r1218 r1220  
    4141
    4242        def __init__(self, frams_path, frams_lib_name, sim_settings_files):
     43                self.dissim_measure_density_distribution = None  # will be initialized only when necessary (for rare dissimilarity methods)
     44
    4345                if frams_lib_name is None:
    4446                        frams.init(frams_path)  # could add support for setting alternative directories using -D and -d
     
    148150        def dissimilarity(self, genotype_list: List[str], method: int) -> np.ndarray:
    149151                """
    150                         :param method: -1 = genetic Levenshtein distance; 0, 1, 2 = phenetic dissimilarity (SimilMeasureGreedy, SimilMeasureHungarian, SimilMeasureDistribution)
     152                        :param method: -1 = genetic Levenshtein distance; 0, 1, 2 = phenetic dissimilarity (SimilMeasureGreedy, SimilMeasureHungarian, SimilMeasureDistribution); -2, -3 = phenetic density distribution (count, frequency).
     153                        See also prepareDissimilarityCalculation().
    151154                        :return: A square array with dissimilarities of each pair of genotypes.
    152155                """
     
    174177                                for j in range(n):  # maybe calculate only one triangle if you really need a 2x speedup
    175178                                        square_matrix[i][j] = Levenshtein.distance(genotype_list[i], genotype_list[j])
     179                elif method in (-2, -3):
     180                        if self.dissim_measure_density_distribution is None:
     181                                from dissimilarity.densityDistribution import DensityDistribution
     182                                self.dissim_measure_density_distribution = DensityDistribution(frams)
     183                        self.dissim_measure_density_distribution.frequency = (method == -3)
     184                        square_matrix = self.dissim_measure_density_distribution.getDissimilarityMatrix(genotype_list)
    176185                else:
    177                         raise Exception("Don't know what to do with dissimilarity method = %d" % method)
     186                        raise ValueError("Don't know what to do with dissimilarity method = %d" % method)
    178187
    179188                for i in range(n):
Note: See TracChangeset for help on using the changeset viewer.