def deseqPlotPCA(outfile, vsd, max_genes=500):
    '''plot a PCA

    Use variance stabilized data in object vsd.
    Should be 'blind', as then the transform is
    not informed by the experimental design.
    '''
    R.png(outfile)
    #  if there are more than 500 genes (after filtering)
    #  use the 500 most variable in the PCA
    #  else use the number of genes
    R('''ntop = ifelse(as.integer(dim(vsd))[1] >= %(max_genes)i,
    %(max_genes)i,
    as.integer(dim(vsd))[1])''' % locals())
    try:
        R('''plotPCA(vsd)''')
    except rpy2.rinterface.RRuntimeError, msg:
        E.warn("can not plot PCA: %s" % msg)
    R['dev.off']()
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Expression.py/deseqPlotPCA/original