@transform( importExpressionDifferences,
            suffix("_expdiff.import"), 
            "_expdiff.export")
def exportDifferentiallyExpressedGenes( infile, outfile ):
    '''import expression differences.
    '''

    dbhandle = sqlite3.connect( PARAMS["database"] )

    track = infile[:-len("_expdiff.import")]
    if track.endswith( ".sam" ):
        field = "qvalue"
        cutoff = float(PARAMS['expression_sam_export_qvalue_cutoff'])
    elif track.endswith( ".ttest" ):
        field = "pvalue"
        cutoff = float(PARAMS['expression_ttest_export_pvalue_cutoff'])

    outs = open(outfile, "w" )

    track, method, control = PExpression.getExpressionMatch( track + ".expdiff" )

    if track == control:
        outs.close()
        return

    tablename = "%s_vs_%s_%s" % (track,control,method)

    statement = '''SELECT d.cluster_id, genesymbol, fold, pvalue, qvalue, ee.description 
                    FROM %(tablename)s as d, expression as ee on ee.cluster_id = d.cluster_id where %(field)s < %(cutoff)f''' % locals()
    cc = dbhandle.cursor()
    cc.execute( statement )

    outs.write( "cluster_id\tgenesymbol\tfold\tpvalue\tqvalue\tdescription\n" )
    for x in cc:
        outs.write( "\t".join( map(str, x) ) + "\n" )
        
    outs.close()

############################################################
############################################################
############################################################
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_vitaminD.py/exportDifferentiallyExpressedGenes/original