def __init__( self, gene_id, gene_name, contig, start, end, strand, biotype, ensembl, require_valid_biotype=True): self.id = gene_id # can't check the type of ensembl since it will create a circular # dependency between this module and ensembl_release but note that # it's expected to be an EnsemblRelease object self.ensembl = ensembl self.db = ensembl.db require_instance(self.db, Database, "db") self.name = gene_name Locus.__init__(self, contig, start, end, strand) if require_valid_biotype and not is_valid_biotype(biotype): raise ValueError( "Invalid gene_biotype %s for gene with ID = %s" % ( biotype, gene_id)) self.biotype = biotype
def __init__( self, gene_id, gene_name, contig, start, end, strand, biotype, genome, require_valid_biotype=True): """ genome is a Genome object. """ self.id = gene_id self.genome = genome self.db = genome.db require_instance(self.db, Database, "db") self.name = gene_name Locus.__init__(self, contig, start, end, strand) if require_valid_biotype and not is_valid_biotype(biotype): raise ValueError( "Invalid gene_biotype %s for gene with ID = %s" % ( biotype, gene_id)) self.biotype = biotype
def __init__(self, gene_id, gene_name, contig, start, end, strand, biotype, genome, require_valid_biotype=True): """ genome is a Genome object. """ self.id = gene_id self.genome = genome self.db = genome.db require_instance(self.db, Database, "db") self.name = gene_name Locus.__init__(self, contig, start, end, strand) if require_valid_biotype and not is_valid_biotype(biotype): raise ValueError("Invalid gene_biotype %s for gene with ID = %s" % (biotype, gene_id)) self.biotype = biotype
def __lt__(self, other): """ Variants are ordered by locus. """ require_instance(other, Variant, name="variant") if self.contig == other.contig: return self.start < other.start return self.contig < other.contig
def check_pMHC_affinity_arrays(alleles, peptides, affinities, sample_weights): """ Make sure that we have the same number of peptides, affinity values, and weights. """ require_instance(alleles, np.ndarray) require_instance(peptides, np.ndarray) require_instance(affinities, np.ndarray) require_instance(sample_weights, np.ndarray) if len(alleles.shape) != 1: raise ValueError("Expected 1d array of alleles but got shape %s" % (alleles.shape, )) if len(peptides.shape) != 1: raise ValueError("Expected 1d array of peptides but got shape %s" % (peptides.shape, )) if len(affinities.shape) != 1: raise ValueError( "Expected 1d array of affinity values but got shape %s" % (alleles.shape, )) if len(sample_weights.shape) != 1: raise ValueError( "Expected 1d array of sample weights but got shape %s" % (sample_weights.shape, )) n = len(alleles) if len(peptides) != n: raise ValueError("Expected %d peptides but got %d" % (n, len(peptides))) if len(affinities) != n: raise ValueError("Expected %d affinity values but got %d" % (n, len(affinities))) if len(sample_weights) != n: raise ValueError("Expected %d sample weights but got %d" % (n, len(sample_weights)))
def check_pMHC_affinity_arrays(alleles, peptides, affinities, sample_weights): """ Make sure that we have the same number of peptides, affinity values, and weights. """ require_instance(alleles, np.ndarray) require_instance(peptides, np.ndarray) require_instance(affinities, np.ndarray) require_instance(sample_weights, np.ndarray) if len(alleles.shape) != 1: raise ValueError("Expected 1d array of alleles but got shape %s" % ( alleles.shape,)) if len(peptides.shape) != 1: raise ValueError("Expected 1d array of peptides but got shape %s" % ( peptides.shape,)) if len(affinities.shape) != 1: raise ValueError( "Expected 1d array of affinity values but got shape %s" % ( alleles.shape,)) if len(sample_weights.shape) != 1: raise ValueError( "Expected 1d array of sample weights but got shape %s" % ( sample_weights.shape,)) n = len(alleles) if len(peptides) != n: raise ValueError( "Expected %d peptides but got %d" % (n, len(peptides))) if len(affinities) != n: raise ValueError( "Expected %d affinity values but got %d" % (n, len(affinities))) if len(sample_weights) != n: raise ValueError( "Expected %d sample weights but got %d" % (n, len(sample_weights)))
def _validate_peptide_lengths(self, peptides, max_peptide_length=None): require_instance(peptides, (list, tuple, np.ndarray)) if max_peptide_length is None: max_peptide_length = max(len(p) for p in peptides) if self.variable_length_sequences: max_observed_length = max(len(p) for p in peptides) if max_observed_length > max_peptide_length: example = [ p for p in peptides if len(p) == max_observed_length ][0] raise ValueError( "Peptide(s) of length %d when max = %d (example '%s')" % (max_observed_length, max_peptide_length, example)) elif any(len(p) != max_peptide_length for p in peptides): example = [p for p in peptides if len(p) != max_peptide_length][0] raise ValueError( "Expected all peptides to have length %d, '%s' has length %d" % (max_peptide_length, example, len(example))) return max_peptide_length