@@ -0,0 +1,2170 @@
+import time%0A%0Aimport pandas%0Aimport sklearn.decomposition%0A%0A%0Aclass AlleleEncodingTransform(object):%0A    def transform(self, data):%0A        raise NotImplementedError()%0A%0A    def get_fit(self):%0A        %22%22%22%0A        Get the fit for serialization, which must be in the form of one or more%0A        dataframes.%0A%0A        Returns%0A        -------%0A        dict : string to DataFrame%0A        %22%22%22%0A        raise NotImplementedError()%0A%0A    def restore_fit(self, fit):%0A        %22%22%22%0A        Restore a serialized fit.%0A%0A        Parameters%0A        ----------%0A        fit : string to DataFrame%0A        %22%22%22%0A%0A%0Aclass PCATransform(AlleleEncodingTransform):%0A    name = 'pca'%0A    serialization_keys = %5B'data'%5D%0A%0A    def __init__(self):%0A        self.model = None%0A%0A    def is_fit(self):%0A        return self.model is not None%0A%0A    def fit(self, allele_representations):%0A        self.model = sklearn.decomposition.PCA()%0A        shape = allele_representations.shape%0A        flattened = allele_representations.reshape(%0A            (shape%5B0%5D, shape%5B1%5D * shape%5B2%5D))%0A        print(%22Fitting PCA allele encoding transform on data of shape: %25s%22 %25 (%0A            str(flattened.shape)))%0A        start = time.time()%0A        self.model.fit(flattened)%0A        print(%22Fit complete in %250.3f sec.%22 %25 (time.time() - start))%0A%0A    def get_fit(self):%0A        df = pandas.DataFrame(self.model.components_)%0A        df.columns = %5B%22pca_%25s%22 %25 c for c in df.columns%5D%0A        df%5B%22mean%22%5D = self.model.mean_%0A        return %7B%0A            'data': df%0A        %7D%0A%0A    def restore_fit(self, fit):%0A        assert list(fit) == %5B'data'%5D%0A        data = fit%5B%22data%22%5D%0A        self.model = sklearn.decomposition.PCA()%0A        self.model.mean_ = data%5B%22mean%22%5D.values%0A        self.model.components_ = data.drop(columns=%22mean%22).values%0A%0A    def transform(self, allele_representations):%0A        if not self.is_fit():%0A            self.fit(allele_representations)%0A        flattened = allele_representations.reshape(%0A            (allele_representations.shape%5B0%5D,%0A             allele_representations.shape%5B1%5D * allele_representations.shape%5B2%5D))%0A        return self.model.transform(flattened)%0A%0A%0ATRANSFORMS = dict((klass.name, klass) for klass in %5BPCATransform%5D)%0A

add missing file