@files( ((importProbeset2Transcript, TARGET_PROBESET),) )
def exportProbesetLocations( infile, outfile ):
    '''export probeset locations.
    
    Probeset locations map the range of a transcript onto
    a probeset.
    '''

    dbhandle = sqlite3.connect( PARAMS["database"] )
    cc = dbhandle.cursor()
    # statement = "SELECT contig, COUNT(DISTINCT contig), min(start), max(end), t.strand, e.probeset, COUNT(DISTINCT t.transcript_id) FROM transcripts AS t, expression as e WHERE t.transcript_id = e.mrna_id GROUP BY t.strand, e.probeset" 
    statement = "SELECT contig, 1, start, end, strand, cluster_id, transcript_id, gene_id, COUNT(DISTINCT gene_id) FROM probeset2transcript GROUP BY cluster_id, transcript_id"
    cc.execute( statement )

    gff = GTF.Entry()
    gff.source = "cluster_id"
    gff.feature = "exon"

    outs = open(outfile, "w")
    noutput, nskipped = 0,0
    max_len = int(PARAMS["max_probeset_length"])
    for contig, ncontigs, start, end, strand, cluster_id, transcript_id, gene_id, ngenes in cc:
        if ncontigs > 1:
            E.warn( "cluster_id %s: multiple contigs" % cluster_id)
            nskipped += 1
            continue
        if ngenes > 1:
            E.warn( "cluster_id %s: multiple genes" % cluster_id)
            nskipped += 1
            continue
        if start - end > max_len:
            E.warn( "cluster_id %s: range (%s:%i..%i) larger than cutoff (%i>%i)" % \
                        (cluster_id, contig, start, end, end-start, max_len))
            nskipped += 1
            continue
            
        gff.contig = contig
        gff.start = start 
        gff.end = end
        gff.strand = strand
        gff.gene_id = transcript_id
        gff.transcript_id = cluster_id
        outs.write( str(gff) + "\n" )
        noutput += 1
    outs.close()

    E.info( "%i cluster_ids exported: %i skipped" %(noutput, nskipped) )

############################################################
############################################################
############################################################
## OBSOLETE
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_vitaminD.py/exportProbesetLocations/swapped operands of `-`