# Path: grit/transcript.py
# VERBOSE = False
# def partition_coding_and_utr_segments( exons, cds_start, cds_stop ):
#     def mod_external_bndrys( exons, lower_bnd, upper_bnd ):
#     def __init__(self, id, name, 
#                  chrm, strand, start, stop, 
#                  transcripts, meta_data={}):
#     def find_nonoverlapping_boundaries( self ):
#     def write_to_file(self, ofname=None):
#     def find_transcribed_regions( self ):
#     def calc_bpkm(self, read_cov):
#     def extract_elements(self):
#     def __init__(self, trans_id, chrm, strand, exons, cds_region,
#                  gene_id, score=None, fpkm=None, fpk=None, 
#                  promoter=None, polya_region=None, coding_sequence=None,
#                  conf_lo=None, conf_hi=None, frac=None,
#                  gene_name=None, name=None):
#     def add_cds_region( self, cds_region, coding_sequence=None ):
#     def __hash__( self ):
#     def IB_key( self ):
#     def relative_pos( self, genome_coord ):
#     def genome_pos( self, trans_coord ):
#     def build_gtf_lines( self, meta_data, source='.'):
#         def build_lines_for_feature( exons, feature, is_CDS=False ):
#         def order(line):
#     def calc_length(self):
#     def build_tracking_line(self):
#     def find_promoter(self, inferred_promoter_length=50):
#     def find_polya_region(self, inferred_polya_region_length=20):
# class Gene( object ):
# class Transcript( object ):
# 
# Path: grit/config.py
# def log_statement(*args, **kwargs):
#     print args[0]
# 
# VERBOSE = None


import os, sys
import itertools
import tempfile
import gzip
import traceback
    import multiprocessing
from collections import namedtuple, defaultdict
from ..transcript import Gene, Transcript, GenomicInterval
from reads import clean_chr_name
from tracking import load_expression_tracking_data
from ..config import log_statement, VERBOSE
        gene_name = gene_data.meta_data['gene_name']
        gene_meta_data = gene_data.meta_data
    else:
        if VERBOSE: print >> sys.stderr, "Skipping '%s': multiple gene lines." % gene_id
        return None
    
    if gene_start != min(t.start for t in transcripts ) \
            or gene_stop != max(t.stop for t in transcripts ):
        if VERBOSE: print >> sys.stderr, "Skipping '%s': gene boundaries dont match the transcript boundaries." % gene_id
        return None
    
    return Gene( gene_id, gene_name, 
                 gene_chrm, gene_strand, gene_start, gene_stop,
                 transcripts, gene_meta_data )

class Annotation(object):
    """Store a collection of genes.

    Contains methods for comparing annotations.
    """
    def __init__(self):
        self._genes = []
        self._gene_map = {}
        self._gene_locs = defaultdict(list)
    
    def __len__(self):
        return len(self._genes)
    
    def append(self, gene):
        # make sure this is a gene object

# Path: grit/transcript.py
# VERBOSE = False
# def partition_coding_and_utr_segments( exons, cds_start, cds_stop ):
#     def mod_external_bndrys( exons, lower_bnd, upper_bnd ):
#     def __init__(self, id, name, 
#                  chrm, strand, start, stop, 
#                  transcripts, meta_data={}):
#     def find_nonoverlapping_boundaries( self ):
#     def write_to_file(self, ofname=None):
#     def find_transcribed_regions( self ):
#     def calc_bpkm(self, read_cov):
#     def extract_elements(self):
#     def __init__(self, trans_id, chrm, strand, exons, cds_region,
#                  gene_id, score=None, fpkm=None, fpk=None, 
#                  promoter=None, polya_region=None, coding_sequence=None,
#                  conf_lo=None, conf_hi=None, frac=None,
#                  gene_name=None, name=None):
#     def add_cds_region( self, cds_region, coding_sequence=None ):
#     def __hash__( self ):
#     def IB_key( self ):
#     def relative_pos( self, genome_coord ):
#     def genome_pos( self, trans_coord ):
#     def build_gtf_lines( self, meta_data, source='.'):
#         def build_lines_for_feature( exons, feature, is_CDS=False ):
#         def order(line):
#     def calc_length(self):
#     def build_tracking_line(self):
#     def find_promoter(self, inferred_promoter_length=50):
#     def find_polya_region(self, inferred_polya_region_length=20):
# class Gene( object ):
# class Transcript( object ):
# 
# Path: grit/config.py
# def log_statement(*args, **kwargs):
#     print args[0]
# 
# VERBOSE = None


# Path: grit/files/gtf.py
import os, sys
import itertools
import tempfile
import gzip
import traceback
    import multiprocessing
from collections import namedtuple, defaultdict
from ..transcript import Gene, Transcript, GenomicInterval
from reads import clean_chr_name
from tracking import load_expression_tracking_data
from ..config import log_statement, VERBOSE

        gene_name = gene_data.meta_data['gene_name']
        gene_meta_data = gene_data.meta_data
    else:
        if VERBOSE: print >> sys.stderr, "Skipping '%s': multiple gene lines." % gene_id
        return None
    
    if gene_start != min(t.start for t in transcripts ) \
            or gene_stop != max(t.stop for t in transcripts ):
        if VERBOSE: print >> sys.stderr, "Skipping '%s': gene boundaries dont match the transcript boundaries." % gene_id
        return None
    
    return Gene( gene_id, gene_name, 
                 gene_chrm, gene_strand, gene_start, gene_stop,
                 transcripts, gene_meta_data )

class Annotation(object):
    """Store a collection of genes.

    Contains methods for comparing annotations.
    """
    def __init__(self):
        self._genes = []
        self._gene_map = {}
        self._gene_locs = defaultdict(list)
    
    def __len__(self):
        return len(self._genes)
    
    def append(self, gene):
        # make sure this is a gene object

        assert isinstance(gene, Gene)