def load_allele_model(allele, length): """Returns the SYFPEITHI pssm for a given allele""" allele_model = "%s_%i" % (allele, length) try: return matrix_max( getattr( __import__("Fred2.Data.pssms.syfpeithi" + ".mat." + allele_model, fromlist=[allele_model]), allele_model)) except ImportError: return None # Calculate the maximum attainable score for each allele converted_alleles = dict(zip(alleles, predictor.convert_alleles(alleles))) max_score_by_allele = {(allele, length): load_allele_model(converted_alleles[allele], length) for length in predictor.supportedLength for allele in alleles} # Run predictions and output results print 'Peptide\tAllele\tSyfpeithiRawScore\tSyfpeithiNormScore' for pep_len, peptides in peptides_by_length.items(): for allele in alleles: if (allele, pep_len ) in max_score_by_allele and max_score_by_allele[allele, pep_len]: results = predictor.predict(peptides, alleles=[allele]) for index, row in results.iterrows(): print '{}\t{}\t{}\t{}'.format( str(index[0]), allele, row[allele],