Translate all the genes in a chromosome.
        
        chromosome:  a ``chromosomes.Chromosome`` instance to translate
        
        return:  a list of translation products for the genes in the chromosome
423175
def translate_chromosome(self, chromosome):
        
        assert isinstance(chromosome, Chromosome)
        return [self.translate_gene(g) for g in chromosome]
532956
def get_gene2binvec(self):
        """"""
        _sec2chr = self.sec2chr
        return {g:[s in s2gos for s in _sec2chr] for g, s2gos in self.gene2section2gos.items()}
689409
def get_gene(self, gene_name):
        
        if not gene_name:
            return

        gene_pk = self.genes.get(gene_name)
        if gene_pk:
            return gene_pk

        chrom = self.chromosomes[self.variants.chrom]
        gene = Gene.objects.find(gene_name, chrom, create=True)
        if gene:
            return gene.pk
1279247
def target_gene_indices(gene_names,
                        target_genes):
    

    if isinstance(target_genes, list) and len(target_genes) == 0:
        return []

    if isinstance(target_genes, str) and target_genes.upper() == 'ALL':
        return list(range(len(gene_names)))

    elif isinstance(target_genes, int):
        top_n = target_genes
        assert top_n > 0

        return list(range(min(top_n, len(gene_names))))

    elif isinstance(target_genes, list):
        if not target_genes:  # target_genes is empty
            return target_genes
        elif all(isinstance(target_gene, str) for target_gene in target_genes):
            return [index for index, gene in enumerate(gene_names) if gene in target_genes]
        elif all(isinstance(target_gene, int) for target_gene in target_genes):
            return target_genes
        else:
            raise ValueError("Mixed types in target genes.")

    else:
        raise ValueError("Unable to interpret target_genes.")
800909
def process_mgi_relationship_transgene_genes(self, limit=None):
        
        if self.test_mode:
            graph = self.testgraph
        else:
            graph = self.graph
        LOG.info("getting transgene genes")
        raw = '/'.join((self.rawdir, 'mgi_relationship_transgene_genes'))
        geno = Genotype(graph)
        col = [
            'rel_key', 'allele_key', 'allele_id', 'allele_label', 'category_key',
            'category_name', 'property_key', 'property_name', 'gene_num'
        ]
        with open(raw, 'r', encoding="utf8") as csvfile:
            filereader = csv.reader(csvfile, delimiter='\t', quotechar='\"')
            header = next(filereader)
            if header != col:
                LOG.error('expected columns:  %s\n\tBut got:\n%s', col, header)
            for row in filereader:
                # rel_key,
                allele_key = int(row[col.index('allele_key')])
                allele_id = row[col.index('allele_id')]
                # allele_label,
                # category_key,
                # category_name,
                # property_key,
                # property_name,
                gene_num = int(row[col.index('gene_num')])

                if self.test_mode and allele_key not in self.test_keys.get('allele')\
                        and gene_num not in self.test_ids:
                    continue

                gene_id = 'NCBIGene:' + str(gene_num)

                # geno.addParts(gene_id, allele_id, self.globaltt['has_variant_part'])
                seqalt_id = self.idhash['seqalt'].get(allele_key)
                if seqalt_id is None:
                    seqalt_id = allele_id
                geno.addSequenceDerivesFrom(seqalt_id, gene_id)

                if not self.test_mode and limit is not None and \
                        filereader.line_num > limit:
                    break

        return
393312
def from_genes(cls, genes: List[ExpGene]):
        """"""
        data = [g.to_dict() for g in genes]
        index = [d.pop('ensembl_id') for d in data]
        table = cls(data, index=index)
        return table
700150
def gene_names(self):
        
        # Iterate through all the target names in the formatted targets file
        for record in SeqIO.parse(self.targets, 'fasta'):
            # Append all the gene names to the list of names
            self.genes.append(record.id)
964614
def genes_with_experimental_structures(self):
        """"""
        return DictList(x for x in self.genes_with_structures if x.protein.num_structures_experimental > 0)
330209
def _parse_gene_coordinates(file):
        
        id_map = {}
        col = ['gene_curie', 'start', 'end', 'strand', 'build']
        if os.path.exists(os.path.join(os.path.dirname(__file__), file)):
            with open(os.path.join(os.path.dirname(__file__), file)) as tsvfile:
                reader = csv.reader(tsvfile, delimiter="\t")
                for row in reader:
                    id_map[row[col.index('gene_curie')]] = {
                        'start': row[col.index('start')],
                        'end': row[col.index('end')],
                        'strand': row[col.index('strand')],
                        'build': row[col.index('build')]
                    }
        return id_map
1351483
def parse_chromosome_string(job, chromosome_string):
    
    if chromosome_string is None:
        return []
    else:
        assert isinstance(chromosome_string, str)
        chroms = [c.strip() for c in chromosome_string.split(',')]
        if 'canonical' in chroms:
            assert 'canonical_chr' not in chroms, 'Cannot have canonical and canonical_chr'
            chr_prefix = False
            chroms.remove('canonical')
            out_chroms = [str(c) for c in range(1, 23)] + ['X', 'Y']
        elif 'canonical_chr' in chroms:
            assert 'canonical' not in chroms, 'Cannot have canonical and canonical_chr'
            chr_prefix = True
            chroms.remove('canonical_chr')
            out_chroms = ['chr' + str(c) for c in range(1, 23)] + ['chrX', 'chrY']
        else:
            chr_prefix = None
            out_chroms = []
        for chrom in chroms:
            if chr_prefix is not None and chrom.startswith('chr') is not chr_prefix:
                job.fileStore.logToMaster('chromosome %s does not match the rest that %s begin '
                                          'with "chr".' % (chrom,
                                                           'all' if chr_prefix else 'don\'t'),
                                          level=logging.WARNING)
            out_chroms.append(chrom)
        return chrom_sorted(out_chroms)
183462
def from_list(cls, gene_ontology, l):
         
        assert isinstance(gene_ontology, GeneOntology)
        assert isinstance(l, list)

        assert len(l) == 17

        go_term = gene_ontology[l[4]]

        qualifier = l[3] or []
        with_from = l[7] or None
        db_name = l[9] or None
        db_syn = l[10] or []
        ext = l[15] or []
        product_id = l[16] or None

        annotation = cls(
            db=l[0],
            db_id=l[1],
            db_symbol=l[2],
            go_term=go_term,
            db_ref=l[5],
            ev_code=l[6],
            db_type=l[11],
            taxon=l[12],
            date=l[13],
            assigned_by=l[14],

            qualifier=qualifier,
            with_from=with_from,
            db_name=db_name,
            db_syn=db_syn,
            ext=ext,
            product_id=product_id,
        )
        return annotation
1023824
def _update_pathway_definitions(crosstalk_corrected_index_map,
                                gene_row_names,
                                pathway_column_names):
    
    corrected_pathway_definitions = {}
    for pathway_index, gene_indices in crosstalk_corrected_index_map.items():
        pathway = pathway_column_names[pathway_index]
        genes = set([gene_row_names[index] for index in list(gene_indices)])
        corrected_pathway_definitions[pathway] = genes
    return corrected_pathway_definitions
154737
def translate(self, instruction):
        
        try:
            trans_instrs = self._translate(instruction)
        except Exception:
            self._log_translation_exception(instruction)

            raise TranslationError("Unknown error")

        return trans_instrs
492865
def exons(self, contig=None, strand=None):
        
        # DataFrame with single column called "exon_id"
        exon_ids = self.exon_ids(contig=contig, strand=strand)
        return [
            self.exon_by_id(exon_id)
            for exon_id in exon_ids
        ]
750108
def gene_features(self):
        
        nm, strand = self.gene_name, self.strand
        feats = [(self.chrom, self.start, self.end, nm, strand, 'gene')]
        for feat in ('introns', 'exons', 'utr5', 'utr3', 'cdss'):
            fname = feat[:-1] if feat[-1] == 's' else feat
            res = getattr(self, feat)
            if res is None or all(r is None for r in res): continue
            if not isinstance(res, list): res = [res]
            feats.extend((self.chrom, s, e, nm, strand, fname) for s, e in res)

        tss = self.tss(down=1)
        if tss is not None:
            feats.append((self.chrom, tss[0], tss[1], nm, strand, 'tss'))
            prom = self.promoter()
            feats.append((self.chrom, prom[0], prom[1], nm, strand, 'promoter'))

        return sorted(feats, key=itemgetter(1))
1348481
def parse_gene_set(gene_set_fp):
    
    group_gene_set_dict = OrderedDict()

    with open(gene_set_fp) as inFile:
        for line in inFile.readlines():
            tokens = line.strip().split('\t')
            group = tokens[0]
            gene_set = set(tokens[1:])

            group_gene_set_dict[group] = gene_set

    return group_gene_set_dict
695618
def get_all_resources(self):
        
        resources = {}
        resources[
            "genetic_map_HapMapII_GRCh37"
        ] = self.get_genetic_map_HapMapII_GRCh37()
        resources["cytoBand_hg19"] = self.get_cytoBand_hg19()
        resources["knownGene_hg19"] = self.get_knownGene_hg19()
        resources["kgXref_hg19"] = self.get_kgXref_hg19()
        for source, target in itertools.permutations(["NCBI36", "GRCh37", "GRCh38"], 2):
            resources[source + "_" + target] = self.get_assembly_mapping_data(
                source, target
            )
        return resources