benchmate.genome
benchmate.genome.genome
Genome Objects
class Genome()
__init__
def __init__(name,
description,
genome_fasta,
gtf,
transcriptome_fasta=None,
standalone=False,
proteome_fasta=None,
create=True,
db_conn=None,
project=None)
Arguments:
gtf_path: Path to the GTF filegenome_fasta: Path to the genome fasta filetranscriptome_fasta: Path to the transcriptome fasta fileproteome_fasta: Path to the proteome fasta filedb_conn: database connection object this is a sqlalchemy enginetaxon_id: taxon id of the genome
genes
def genes(ids=None, range=None, ignore_strand=True)
Gene id or range if range is provided it will return the genes in that range depending on the overlap type
Arguments:
id: Gene id, that used in the gtf filerange: A GenomicRange objectignore_strand: whether to ignore strand this will return all the genes in the range regardless of strand
Returns:
a GenomicRangesDict object with the genes in it, each key is the gene name and the value is a GenomicRange object
transcripts
def transcripts(gene_ids=None,
ids=None,
range=None,
ignore_strand=True,
group_by_gene=True)
return transcripts by gene id, transcript id or range
Arguments:
gene_ids: return transcripts for these gene idsids: return transcripts with these transcript idsrange: return transcripts in this rangeignore_strand: ignore strand when searching by rangegroup_by_gene: whether to group the returned transcripts by gene id, if true the returned object will have gene ids as keys and GenomicRangesList as values, if false the returned object will have transcript ids as keys and GenomicRange as values
Returns:
a genomic ranges dict object
exons
def exons(transcript_ids=None,
ids=None,
range=None,
group_by_transcript=True,
ignore_strand=True)
same as genes but will need to search by transcript not gene, if you do not know the transcript search for it with transcripts first
Arguments:
transcript_id: return all exons for this transcript idid: return exon with this idrange: return exons in this rangegroup_by_transcript: whether to group the returned exons by transcript id, if true the returned objectignore_strand: whether to ignore strand when searching by range
Returns:
a genomic ranges dict object, if not grouped by transcript the keys will be exon ids otherwise the keys will be transcript ids
coding
def coding(transcript_ids=None,
ids=None,
range=None,
group_by_transcript=True,
ignore_strand=True)
same as exons return all the coding sequences for a transcript or a list of transcripts
Arguments:
transcript_id: return all coding sequences for this transcript idid: return coding sequence with this idrange: return coding sequences in this rangegroup_by_transcript: whether to group the returned coding sequences by transcript id, if true the returned object
Returns:
a genomic ranges dict object, if not grouped by transcript the keys will be coding sequence ids otherwise the keys will be transcript ids
three_utr
def three_utr(transcript_ids=None, ids=None, range=None, ignore_strand=True)
return all the 3’ utrs for a transcript or a list of transcripts
Arguments:
transcript_ids: return 3’ utrs for these transcript idsrange: return 3’ utrs in this rangeignore_strand: regardless of strand
Returns:
a genomic ranges dict object with transcript ids as keys and GenomicRangesList as values, the utrs are not described as separate exons but the exons are merged into one if that utr spans multple exons. Additionally if the utrs ends in the middle of an exon the utr will end there.
five_utr
def five_utr(transcript_ids=None, ids=None, range=None, ignore_strand=True)
return all the 5’ utrs for a transcript or a list of transcripts
Arguments:
transcript_ids: return 3’ utrs for these transcript idsrange: return 3’ utrs in this rangeignore_strand: regardless of strand
Returns:
a genomic ranges dict object with transcript ids as keys and GenomicRangesList as values, the utrs are not described as separate exons but the exons are merged into one if that utr spans multple exons. Additionally if the utrs ends in the middle of an exon the utr will end there.
introns
def introns(transcript_ids=None,
ids=None,
range=None,
group_by_transcript=True,
ignore_strand=True)
return all the introns for a transcript or a list of transcripts
Arguments:
transcript_id: return introns for this transcript idid: return intron with this id (introns usually are not descibed in a gtf, so this id may not be very useful since it is an auto incremented id)range: return introns in this rangegroup_by_transcript: return introns grouped by transcriptignore_strand: whether to ignore strand when searching by range
Returns:
return: a genomic ranges dict object, if not grouped by transcript the keys will be intron ids otherwise the keys will be transcript ids
custom_range
def custom_range(grange=None, ignore_strand=False)
query a user inserted custom ranges
Arguments:
range: a genomic ranges instanceignore_strand: whether to ignore strand when searching by range
Returns:
a GenomicRangesList with all the results, or None
insert_custom_range
def insert_custom_range(grange)
insert a new custom range
Arguments:
range: a GenomicRange instance, if you are using GenomicRangesList of GenomicRangesDict, run this function multiple times
Returns:
None
get_sequence
def get_sequence(genomic_range, type='genome')
Get the sequence of a genomic range. This takes a single genomc range you can iterate over a GenomicRangeList or GenomicRangeDict
Arguments:
genomic_range: GenomicRange object
Returns:
sequence as string
add_annotation
def add_annotation(table, row_id, annots)
add arbitrary annotations as a dictionary to a specific row in a specific table
Arguments:
table: which table to add the annotations toid: which row id to add the annotations to, this is the datbase internal id not the gene_id or transcript_id, those ids can be found in the annotations of each rowannots: a dictionary of annotations to add
Returns:
None but the database will be updated
search_annotation
def search_annotation(table, values=None)
search annotations in the database for a specific key or value in a table
Arguments:
table: this determines what kinds of features you are searching genens, transcripts etcvalues: search all the values of all keys if keys is none otherwise search those keys and return matching values
Returns:
genomicRangesDict object with the matching rows
benchmate.genome.utils
parse_gtf_attributes
def parse_gtf_attributes(attributes_str)
parse the gtf attributes column that is the last one
Arguments:
attributes_str:
parse_gtf
def parse_gtf(filepath)
for a given gtf file parse all the fields and get them ready for db insertion, this needs to be done once per genome
this gets called by the genome class instances, there is no need for the end user to call this
Arguments:
filepath: path for the gtf file
Returns:
a list of all used genomic features
start_genome
def start_genome(genome_name,
genome_fasta_file,
engine,
transcriptome_fasta_file=None,
proteome_fasta_file=None,
description=None)
load a genome instance, this is called by the genome instance
Arguments:
genome_name: name of the genomegenome_fasta_file: name of the fasta file to be usedengine: connection engine used by sqlalchemy, you are responsible for creating thistranscriptome_fasta_file: optional transcritome fileproteome_fasta_file: optional proteome filedescription: description of the genome
Returns:
return genome id, this will be used to add other things to the genome db
insert_chroms
def insert_chroms(genome_id, chrom_list, engine)
insert chrom info for a specific genome, given its id
Arguments:
genome_id: see above,chrom_list: list of chrom idsengine: connection engine
Returns:
inserted chrom ids, these will be used to insert other features
insert_genes
def insert_genes(chrom_ids, gene_list, engine)
insert genes
Arguments:
chrom_ids: see abovegene_list: list of genes to inserengine: connection engine
Returns:
list of gene ids (not gene names or gene unique ids, this is specific to the db)
insert_transcripts
def insert_transcripts(gene_ids, tx_list, engine)
insert transcripts for each gene id
Arguments:
gene_ids: see abovetx_list: list of transcriptsengine: connection engine
Returns:
list of db ids for all the inserted transcripts
insert_exons
def insert_exons(transcript_ids, exon_list, engine)
insert exons for each transcript
Arguments:
transcript_ids: see aboveexon_list: list of exonsengine: connection engine
Returns:
list of db ids for all the inserted exons
insert_three_utrs
def insert_three_utrs(transcript_ids, three_utr_list, engine)
insert three_utrs
Arguments:
transcript_ids: see abovethree_utr_list: see aboveengine: connection engine
Returns:
list of db ids for all the inserted three_utrs
insert_five_utrs
def insert_five_utrs(transcript_ids, five_utr_list, engine)
insert five_utrs
Arguments:
transcript_ids: see abovefive_utr_list: see aboveengine: connection engine
Returns:
list of db ids for all the inserted five_utrs
insert_coding
def insert_coding(transcript_ids, exon_ids, coding_list, engine)
insert coding regions, this tracks not only transcripts but also which cds belongs to which exon
Arguments:
transcript_ids: see aboveexon_ids: see abovecoding_list: see aboveengine: connection engine
Returns:
list of db ids for all the inserted coding regions
insert_introns
def insert_introns(transcript_ids, exon_list, engine)
insert introns, since there is no intron information they are calculated before insertion by grouping things
by transcript and then calculating the missing areas in each exon for each transcript
Arguments:
transcript_ids: see aboveexon_list: see aboveengine: connection engine
Returns:
list of db ids for all the inserted introns
insert_genome
def insert_genome(gtf,
engine,
name,
description,
genome_fasta,
transcriptome_fasta=None,
proteome_fasta=None)
this takes a gtf file and inserts all the available features
Arguments:
gtf: gtf fileengine: connection enginename: name of the genomedescription: description of the genomegenome_fasta: fasta filetranscriptome_fasta: transcriptome fasta fileproteome_fasta: proteome fasta file
Returns:
genome and chrom ids