Esempio n. 1
0
def venn_runner(dataset,outputfilename='vennrunner.txt',vennengine='',outputdir=''):
    outputdir = os.path.abspath(outputdir)
    outputfilename=os.path.join(outputdir,outputfilename)

    logger.info('#########\nvenn run started#########\n')
    
    if isinstance(dataset,list):
        datadic=dict(dataset)

    uniqueinfo=[]
    commoninfo=[]
    for i in range(0,len(datadic)):
        for v in itertools.combinations(datadic.keys(),i+1):
            combo=[set(datadic[x]) for x in v ]
            tmp=combo[0]
            excl=combo[0]
            for ele in combo[1:]:
                tmp=tmp&ele
                excl=excl-ele
            commoninfo.append((v,tmp))
            uniqueinfo.append((v,excl))
    tabinfo=[]
    for name,ele in commoninfo:
        logger.info('total in {name}: {lenset}'.format(name=' & '.join(name),lenset=len(ele)))
        tabinfo.append(['_&_'.join(name)]+list(ele))
    
    for name,ele in uniqueinfo:
        logger.info('total in {name}: {lenset}'.format(name=' not '.join(name),lenset=len(ele)))
        tabinfo.append([' not '.join(name)]+list(ele))
        
    tabinfotrsp=fhutils.transpose(tabinfo,'')
    out=open(outputfilename,'w')
    for ele in tabinfotrsp:
        out.write('\t'.join([str(x) for x in ele])+'\n')
        
    out.close()
    
    if vennengine=='evenn':
        logger.error('NOT WORKING EVENN')
        pyevenn(dataset,figurename=fhutils.renamefilename(outputfilename,midtag='_'+vennengine,suffix='png'),outputdir =outputdir)
    elif vennengine=='rvenn':
        pyrvenn(dataset,figurename=fhutils.renamefilename(outputfilename,midtag='_'+vennengine,suffix='tiff'),outputdir = outputdir)
    elif vennengine=='venneuler':
        pyvenneuler(dataset,figurename=fhutils.renamefilename(outputfilename,midtag='_'+vennengine,suffix='pdf'),outputdir=outputdir)
    elif vennengine=='rvennerable':
        logger.error('NOT WORKING rvennerable')
        pyrvennerable(dataset,figurename=fhutils.renamefilename(outputfilename,midtag='_'+vennengine,suffix='pdf'),outputdir=outputdir)
    else:
        print 'no venn pdf'
Esempio n. 2
0
def pynormtest(valuelis, numericvars=list(), filename='normtest_data.txt', gformat='pdf'):
    rconsole = rpystatinit()
    rnormcheck = rconsole("rnormcheck")
    dataframe = pyobj2dataframe(valuelis)

    from rpy2.robjects.packages import importr
    grdevices = importr('grDevices')
    grdevices.pdf(file=fhutils.renamefilename(filename, suffix=gformat))
    data = rnormcheck(data=dataframe, numericvars=robjects.vectors.StrVector(tuple(numericvars)))
    grdevices.dev_off()

    out = open(filename, 'w')
    out.write('\n'.join(
        ['######## glvma fit results ########', str(data[0]), '######## LM-fit results ########', str(data[1])]))
    out.close()
Esempio n. 3
0
def pyanova(table, formula, term, filename='anovaimage', gformat='pdf'):
    
    from rpy2.robjects.packages import importr
    rconsole=rpystatinit()
    ranova = rconsole("ranova")

    grdevices = importr('grDevices')
    grdevices.pdf(file=fhutils.renamefilename(filename, suffix=gformat))

    dataframe = pyobj2dataframe(table)
    results = ranova(data=dataframe, formulastring=formula, term=term)
    aovw = dataframe2pyobj(results[0])
    tukey = dataframe2pyobj(results[1])

    grdevices.dev_off()

    return aovw, tukey
Esempio n. 4
0
def pynlsfit(valuelis, formulastr='', startvalues=list(), filename='nlsfit.txt', gformat='pdf'):
    """
    nonlinear fit of function to data
    """
    rconsole = rpystatinit()
    rnonlinfit = rconsole("rnonlinfit")
    dataframe = pyobj2dataframe(valuelis)

    from rpy2.robjects.packages import importr

    grdevices = importr('grDevices')
    graphplotfile = fhutils.renamefilename(filename, suffix=gformat)
    grdevices.pdf(file=graphplotfile)
    nlfit = rnonlinfit(data=dataframe, formulastr=formulastr, startvalues=robjects.ListVector(dict(startvalues)))
    grdevices.dev_off()

    nlfit = rlisttodic(nlfit)
    return nlfit
Esempio n. 5
0
def simpleheatmap(tabdata, figname='defaultheatplot.pdf', main='title',
                  colormode='jet', gformat='pdf', scale='none', dendrogram='both'):
    """
    scale:  none, row, both, col
    """

    rconsole = rpy2.robjects.r
    rsimpleheatmap = rconsole("rsimpleheatmap")
    dopdfgraph = rconsole("dopdfgraph")
    rdataframe = pyobj2dataframe(tabdata, rownames=True, columnames=True)

    from rpy2.robjects.packages import importr

    grdevices = importr('grDevices')
    grdevices.pdf(file=fhutils.renamefilename(figname, suffix=gformat))

    roworder = {'both': True, 'row': True, 'column': False}[dendrogram]
    colorder = {'both': True, 'row': False, 'column': True}[dendrogram]

    rsimpleheatmap(tabdata=rdataframe, scale=scale, dendros=dendrogram, roworder=roworder, colorder=colorder)
    grdevices.dev_off()
Esempio n. 6
0
def statoverview(valuelis, group='NA', filename='overview_data.txt', gformat='pdf'):
    """
    overview statistics
    R psych::describe which shows:
    item name ,item number, nvalid, mean, sd, 
    median, mad, min, max, skew, kurtosis, se
    """
    rconsole = rpystatinit()
    
    rgeneralstats = rconsole("rgeneralstats")
    dataframe = pyobj2dataframe(valuelis)
    from rpy2.robjects.packages import importr

    grdevices = importr('grDevices')
    grdevices.pdf(file=fhutils.renamefilename(filename, suffix=gformat))

    gdic = {'NA': rinterface.NARealType()}
    group = gdic.get(group, group)

    data = rgeneralstats(data=dataframe, group=group)
    grdevices.dev_off()
    out = open(filename, 'w')
    out.write(str(data))
    out.close()
Esempio n. 7
0
def venn_runner(dataset,
                outputfilename='vennrunner.txt',
                vennengine='',
                outputdir=''):
    outputdir = os.path.abspath(outputdir)
    outputfilename = os.path.join(outputdir, outputfilename)

    logger.info('#########\nvenn run started#########\n')

    if isinstance(dataset, list):
        datadic = dict(dataset)

    uniqueinfo = []
    commoninfo = []
    for i in range(0, len(datadic)):
        for v in itertools.combinations(datadic.keys(), i + 1):
            combo = [set(datadic[x]) for x in v]
            tmp = combo[0]
            excl = combo[0]
            for ele in combo[1:]:
                tmp = tmp & ele
                excl = excl - ele
            commoninfo.append((v, tmp))
            uniqueinfo.append((v, excl))
    tabinfo = []
    for name, ele in commoninfo:
        logger.info('total in {name}: {lenset}'.format(name=' & '.join(name),
                                                       lenset=len(ele)))
        tabinfo.append(['_&_'.join(name)] + list(ele))

    for name, ele in uniqueinfo:
        logger.info('total in {name}: {lenset}'.format(name=' not '.join(name),
                                                       lenset=len(ele)))
        tabinfo.append([' not '.join(name)] + list(ele))

    tabinfotrsp = fhutils.transpose(tabinfo, '')
    out = open(outputfilename, 'w')
    for ele in tabinfotrsp:
        out.write('\t'.join([str(x) for x in ele]) + '\n')

    out.close()

    if vennengine == 'evenn':
        logger.error('NOT WORKING EVENN')
        pyevenn(dataset,
                figurename=fhutils.renamefilename(outputfilename,
                                                  midtag='_' + vennengine,
                                                  suffix='png'),
                outputdir=outputdir)
    elif vennengine == 'rvenn':
        pyrvenn(dataset,
                figurename=fhutils.renamefilename(outputfilename,
                                                  midtag='_' + vennengine,
                                                  suffix='tiff'),
                outputdir=outputdir)
    elif vennengine == 'venneuler':
        pyvenneuler(dataset,
                    figurename=fhutils.renamefilename(outputfilename,
                                                      midtag='_' + vennengine,
                                                      suffix='pdf'),
                    outputdir=outputdir)
    elif vennengine == 'rvennerable':
        logger.error('NOT WORKING rvennerable')
        pyrvennerable(dataset,
                      figurename=fhutils.renamefilename(outputfilename,
                                                        midtag='_' +
                                                        vennengine,
                                                        suffix='pdf'),
                      outputdir=outputdir)
    else:
        print 'no venn pdf'