scout/parse/ensembl.py
def parse_ensembl_exons(lines):
    """Parse lines with ensembl formated exons

        This is designed to take a biomart dump with exons from ensembl.
        Check documentation for spec for download

        Args:
            lines(iterable(str)): An iterable with ensembl formated exons
        Yields:
            ensembl_gene(dict): A dictionary with the relevant information
    """
    header = []
    LOG.debug("Parsing ensembl exons...")
    for index, line in enumerate(lines):

        # File allways start with a header line
        if index == 0:
            header = line.rstrip().split('\t')
            continue

        exon_info = parse_ensembl_line(line, header)
        chrom = exon_info['chrom']
        start = exon_info['exon_start']
        end = exon_info['exon_end']
        transcript = exon_info['ensembl_transcript_id']
        gene = exon_info['ensembl_gene_id']

        rank = exon_info['exon_rank']
        strand = exon_info['strand']

        # Recalculate start and stop (taking UTR regions into account for end exons)
        if strand == 1:
            # highest position: start of exon or end of 5' UTR
            # If no 5' UTR make sure exon_start is allways choosen
            start = max(start, exon_info.get('utr_5_end') or -1)
            # lowest position: end of exon or start of 3' UTR
            end = min(end, exon_info.get('utr_3_start') or float('inf'))
        elif strand == -1:
            # highest position: start of exon or end of 3' UTR
            start = max(start, exon_info.get('utr_3_end') or -1)
            # lowest position: end of exon or start of 5' UTR
            end = min(end, exon_info.get('utr_5_start') or float('inf'))

        exon_id = "-".join([chrom, str(start), str(end)])

        if start > end:
            raise ValueError("ERROR: %s" % exon_id)
        data = {
            "exon_id": exon_id,
            "chrom": chrom,
            "start": start,
            "end": end,
            "transcript": transcript,
            "gene": gene,
            "rank": rank,
        }

        yield data
def parse_ensembl_exons(lines):
    """Parse lines with ensembl formated exons

        This is designed to take a biomart dump with exons from ensembl.
        Check documentation for spec for download

        Args:
            lines(iterable(str)): An iterable with ensembl formated exons
        Yields:
            ensembl_gene(dict): A dictionary with the relevant information
    """
    header = []
    LOG.debug("Parsing ensembl exons...")
    for index, line in enumerate(lines):

        # File allways start with a header line
        if index == 0:
            header = line.rstrip().split('\t')
            continue

        exon_info = parse_ensembl_line(line, header)
        chrom = exon_info['chrom']
        start = exon_info['exon_start']
        end = exon_info['exon_end']
        transcript = exon_info['ensembl_transcript_id']
        gene = exon_info['ensembl_gene_id']

        rank = exon_info['exon_rank']
        strand = exon_info['strand']

        # Recalculate start and stop (taking UTR regions into account for end exons)
        if strand == 1:
            # highest position: start of exon or end of 5' UTR
            # If no 5' UTR make sure exon_start is allways choosen
            start = max(start, exon_info.get('utr_5_end') or -1)
            # lowest position: end of exon or start of 3' UTR
            end = min(end, exon_info.get('utr_3_start') or float('inf'))
        elif strand == -1:
            # highest position: start of exon or end of 3' UTR
            start = max(start, exon_info.get('utr_3_end') or -1)
            # lowest position: end of exon or start of 5' UTR
            end = min(end, exon_info.get('utr_5_start') or float('inf'))

        exon_id = "-".join([chrom, str(start), str(end)])

        if start > end:
            raise ValueError("ERROR: %s" % exon_id)
        data = {
            "exon_id": exon_id,
            "chrom": chrom,
            "start": start,
            "end": end,
            "transcript": transcript,
            "gene": gene,
            "rank": rank,
        }

        yield data
def parse_ensembl_exons ( lines ) : header = [ ] LOG . debug ( "Parsing ensembl exons..." ) for index , line in enumerate ( lines ) : # File allways start with a header line if index == 0 : header = line . rstrip ( ) . split ( '\t' ) continue exon_info = parse_ensembl_line ( line , header ) chrom = exon_info [ 'chrom' ] start = exon_info [ 'exon_start' ] end = exon_info [ 'exon_end' ] transcript = exon_info [ 'ensembl_transcript_id' ] gene = exon_info [ 'ensembl_gene_id' ] rank = exon_info [ 'exon_rank' ] strand = exon_info [ 'strand' ] # Recalculate start and stop (taking UTR regions into account for end exons) if strand == 1 : # highest position: start of exon or end of 5' UTR # If no 5' UTR make sure exon_start is allways choosen start = max ( start , exon_info . get ( 'utr_5_end' ) or - 1 ) # lowest position: end of exon or start of 3' UTR end = min ( end , exon_info . get ( 'utr_3_start' ) or float ( 'inf' ) ) elif strand == - 1 : # highest position: start of exon or end of 3' UTR start = max ( start , exon_info . get ( 'utr_3_end' ) or - 1 ) # lowest position: end of exon or start of 5' UTR end = min ( end , exon_info . get ( 'utr_5_start' ) or float ( 'inf' ) ) exon_id = "-" . join ( [ chrom , str ( start ) , str ( end ) ] ) if start > end : raise ValueError ( "ERROR: %s" % exon_id ) data = { "exon_id" : exon_id , "chrom" : chrom , "start" : start , "end" : end , "transcript" : transcript , "gene" : gene , "rank" : rank , } yield data
Parse lines with ensembl formated exons

        This is designed to take a biomart dump with exons from ensembl.
        Check documentation for spec for download

        Args:
            lines(iterable(str)): An iterable with ensembl formated exons
        Yields:
            ensembl_gene(dict): A dictionary with the relevant information
Parse lines with ensembl formated exons