def loadSpliceGraph(jun03, cluster_t, exon_t, splice_t, genomic_seq_t,
                    mrna_seq_t=None, protein_seq_t=None, loadAll=True):
    """
    Build a splice graph from the specified SQL tables representing gene
    clusters, exon forms, and splices. Each table must be specified
    as a DB.TABLENAME string.
    These tables are loaded into memory.
    The splice graph is built based on exact match of exon and splice ends.
    In addition, also builds alt5Graph (exons that match at start but differ
    at end) and alt3Graph (exons that match at end but differ at start).

    Loads all cluster, exon and splice data if loadAll is True.

    Returns tuple: clusters, exons, splices, spliceGraph, alt5Graph, alt3Graph
    """

    # CREATE OUR GRAPHS
    clusterExons = dictGraph()
    clusterSplices = dictGraph()
    spliceGraph = dictGraph()
    alt5 = dictGraph()
    alt3 = dictGraph()

    class YiGenomicSequence(DNASQLSequence):

        def __len__(self):
            return self._select('length(seq)')  # USE SEQ LENGTH FROM DATABASE

    g = jun03[genomic_seq_t]
    # Force genomic seq table to use transparent access
    g.objclass(YiGenomicSequence)

    # Only process this if provided an mRNA table by the user.
    if mrna_seq_t is not None:
        mrna = jun03[mrna_seq_t]
        # Force mRNA seq table to use transparent access.
        mrna.objclass(SQLSequence)
    else:
        mrna = None

    # Only process this if provided a protein table by the user.
    if protein_seq_t is not None:

        class YiProteinSQLSequence(ProteinSQLSequence):

            def __len__(self):
                return self.protein_length # USE SEQ LENGTH FROM DATABASE

        protein = jun03[protein_seq_t]
        # Force protein seq table to use transparent access
        protein.objclass(YiProteinSQLSequence)
        # Alias 'protein_seq' to appear as 'seq'
        protein.addAttrAlias(seq='protein_seq')
    else:
        protein = None

    exon_forms = jun03[exon_t]
    ExonForm.__class_schema__ = SchemaDict(((spliceGraph, 'next'),
                                            (alt5, 'alt5'), (alt3, 'alt3')))
    # Bind this class to container as the one to use as "row objects".
    exon_forms.objclass(ExonForm)

    if loadAll:
        print 'Loading %s...' % exon_forms
        exon_forms.load(ExonForm)

    clusters = jun03[cluster_t]

    class Cluster(TupleO):
        __class_schema__ = SchemaDict(((clusterExons, 'exons'),
                                       (clusterSplices, 'splices')))
    # Bind this class to container as the one to use as "row objects".
    clusters.objclass(Cluster)
    if loadAll:
        print 'Loading %s...' % clusters
        clusters.load(Cluster)

    splices = jun03[splice_t]
    # Bind this class to container as the one to use as "row objects".
    splices.objclass(Splice)
    if loadAll:
        print 'Loading %s...' % splices
        splices.load(Splice)

##     print 'Saving alignment of protein to mrna isoforms...'
##     mrna_protein=PathMapping2()
##     for form_id in protein:
##         p=protein[form_id]
##         m=mrna[form_id]
##         start=3*(p.mRNA_start-1)+int(p.reading_frame)
##         end=start+3*p.protein_length
##         mrna_protein[p]=m[start:end]

        print 'Adding clusters to graph...'
        for c in clusters.values(): # ADD CLUSTERS AS NODES TO GRAPH
            clusterExons+=c
            clusterSplices+=c

        print 'Adding exons to graph...'
        for e in exon_forms.values():
            c=clusters[e.cluster_id]
            try:
                c.exons+=e
                spliceGraph+=e
            except __HOLE__:
                pass # BAD EXON: EMPTY SEQUENCE INTERVAL... IGNORE IT

        print 'Adding splices to graph...'
        for s in splices.values():
            try:
                c=clusters[s.cluster_id]
            except KeyError: # WIERD, ONE SPLICE WITH BLANK (NOT NULL) VALUE!
                pass
            else:
                c.splices+=s

        print 'Building splice graph...'
        for c in clusters.values():
            buildClusterSpliceGraph(c, alt5, alt3)

    return clusters, exon_forms, splices, g, spliceGraph, alt5, alt3, mrna,\
            protein, clusterExons, clusterSplices
dataset/ETHPy150Open cjlee112/pygr/pygr/apps/splicegraph.py/loadSpliceGraph