def load(models_dir=None, max_models=None):
        """
        Deserialize a predictor from a directory on disk.
        
        Parameters
        ----------
        models_dir : string
            Path to directory
            
        max_models : int, optional
            Maximum number of `Class1NeuralNetwork` instances to load

        Returns
        -------
        `Class1AffinityPredictor` instance
        """
        if models_dir is None:
            models_dir = get_default_class1_models_dir()

        manifest_path = join(models_dir, "manifest.csv")
        manifest_df = pandas.read_csv(manifest_path, nrows=max_models)

        allele_to_allele_specific_models = collections.defaultdict(list)
        class1_pan_allele_models = []
        all_models = []
        for (_, row) in manifest_df.iterrows():
            weights_filename = Class1AffinityPredictor.weights_path(
                models_dir, row.model_name)
            config = json.loads(row.config_json)

            # We will lazy-load weights when the network is used.
            model = Class1NeuralNetwork.from_config(
                config,
                weights_loader=partial(
                    Class1AffinityPredictor.load_weights,
                    abspath(weights_filename)))
            if row.allele == "pan-class1":
                class1_pan_allele_models.append(model)
            else:
                allele_to_allele_specific_models[row.allele].append(model)
            all_models.append(model)

        manifest_df["model"] = all_models

        allele_to_fixed_length_sequence = None
        if exists(join(models_dir, "allele_sequences.csv")):
            allele_to_fixed_length_sequence = pandas.read_csv(
                join(models_dir, "allele_sequences.csv"),
                index_col="allele").to_dict()

        allele_to_percent_rank_transform = {}
        percent_ranks_path = join(models_dir, "percent_ranks.csv")
        if exists(percent_ranks_path):
            percent_ranks_df = pandas.read_csv(percent_ranks_path, index_col=0)
            for allele in percent_ranks_df.columns:
                allele_to_percent_rank_transform[allele] = (
                    PercentRankTransform.from_series(percent_ranks_df[allele]))

        logging.info(
            "Loaded %d class1 pan allele predictors, %d allele sequences, "
            "%d percent rank distributions, and %d allele specific models: %s" % (
                len(class1_pan_allele_models),
                len(allele_to_fixed_length_sequence) if allele_to_fixed_length_sequence else 0,
                len(allele_to_percent_rank_transform),
                sum(len(v) for v in allele_to_allele_specific_models.values()),
                ", ".join(
                    "%s (%d)" % (allele, len(v))
                    for (allele, v)
                    in sorted(allele_to_allele_specific_models.items()))))

        result = Class1AffinityPredictor(
            allele_to_allele_specific_models=allele_to_allele_specific_models,
            class1_pan_allele_models=class1_pan_allele_models,
            allele_to_fixed_length_sequence=allele_to_fixed_length_sequence,
            manifest_df=manifest_df,
            allele_to_percent_rank_transform=allele_to_percent_rank_transform,
        )
        return result
def load ( models_dir = None , max_models = None ) : if models_dir is None : models_dir = get_default_class1_models_dir ( ) manifest_path = join ( models_dir , "manifest.csv" ) manifest_df = pandas . read_csv ( manifest_path , nrows = max_models ) allele_to_allele_specific_models = collections . defaultdict ( list ) class1_pan_allele_models = [ ] all_models = [ ] for ( _ , row ) in manifest_df . iterrows ( ) : weights_filename = Class1AffinityPredictor . weights_path ( models_dir , row . model_name ) config = json . loads ( row . config_json ) model = Class1NeuralNetwork . from_config ( config , weights_loader = partial ( Class1AffinityPredictor . load_weights , abspath ( weights_filename ) ) ) if row . allele == "pan-class1" : class1_pan_allele_models . append ( model ) else : allele_to_allele_specific_models [ row . allele ] . append ( model ) all_models . append ( model ) manifest_df [ "model" ] = all_models allele_to_fixed_length_sequence = None if exists ( join ( models_dir , "allele_sequences.csv" ) ) : allele_to_fixed_length_sequence = pandas . read_csv ( join ( models_dir , "allele_sequences.csv" ) , index_col = "allele" ) . to_dict ( ) allele_to_percent_rank_transform = { } percent_ranks_path = join ( models_dir , "percent_ranks.csv" ) if exists ( percent_ranks_path ) : percent_ranks_df = pandas . read_csv ( percent_ranks_path , index_col = 0 ) for allele in percent_ranks_df . columns : allele_to_percent_rank_transform [ allele ] = ( PercentRankTransform . from_series ( percent_ranks_df [ allele ] ) ) logging . info ( "Loaded %d class1 pan allele predictors, %d allele sequences, " "%d percent rank distributions, and %d allele specific models: %s" % ( len ( class1_pan_allele_models ) , len ( allele_to_fixed_length_sequence ) if allele_to_fixed_length_sequence else 0 , len ( allele_to_percent_rank_transform ) , sum ( len ( v ) for v in allele_to_allele_specific_models . values ( ) ) , ", " . join ( "%s (%d)" % ( allele , len ( v ) ) for ( allele , v ) in sorted ( allele_to_allele_specific_models . items ( ) ) ) ) ) result = Class1AffinityPredictor ( allele_to_allele_specific_models = allele_to_allele_specific_models , class1_pan_allele_models = class1_pan_allele_models , allele_to_fixed_length_sequence = allele_to_fixed_length_sequence , manifest_df = manifest_df , allele_to_percent_rank_transform = allele_to_percent_rank_transform , ) return result
Deserialize a predictor from a directory on disk.
        
        Parameters
        ----------
        models_dir : string
            Path to directory
            
        max_models : int, optional
            Maximum number of `Class1NeuralNetwork` instances to load

        Returns
        -------
        `Class1AffinityPredictor` instance