i have following input file (input.xls):
mouse no_neigh_mouse human no_neigh_hum intersection totalgenetested gm20645 1 lnc3 2 1 8 gm20645 1 lnc2 1 0 8 gm20645 1 lnc1 2 1 8 gm26549 2 lnc3 2 1 8 gm26549 2 lnc2 1 1 8 gm26549 2 lnc1 2 1 8
i to:
- calculate hypergeom p-value each row (done successfully)
- then calculate fdr (which same bh) p-value corrections
- add adjusted p-value last column.
my expected output file have 4 columns. first value of "mouse", second value of "human", third "hypergeom-pvalue", fourth "adjusted-pvalue". able generate first 3 columns using following code:
output=open("hypergeom.xls", "w") output.write("mouse\thuman\thypergeom-pvalue\tadjusted-pvalue\n") input = pd.read_table("input.xls", sep="\t") in range (0, len(input.index)): hyperg= scipy.stats.hypergeom.sf(input.ix[i,4], input.ix[i,5], input.ix[i,1], input.ix[i,3],1) #calculates hypergeom p value without problem newline = input.ix[i,0], input.ix[i,2], str(hyper) output.write('\t'.join(newline)+'\n') output.close()
till here, scripts works fine , following output file ("hypergeom.xls"):
mouse human hypergeom-pvalue adjusted-pvalue gm20645 lnc3 0.25 gm20645 lnc2 1 gm20645 lnc1 0.25 gm26549 lnc3 0.464285714 gm26549 lnc2 0.25 gm26549 lnc1 0.464285714
i aimed @ reopening output file input , calculate fdr based on command suggested 1 of users utilizes r: how implement r's p.adjust in python
my code then:
import rpy2.robjects r pvaluefile = pd.read_table("hypergeom.xls", sep="\t") pvalue_list = pvaluefile.ix[:,2].tolist() #converts value column series list #now, try apply command link above p_adjusted = r['p.adjust'](r.floatvector(pvalue_list),method='bh') v in p_adjusted: print v
i error @ step p_adjusted = r [...]. error is: typeerror: 'module' object has no attribute 'getitem'
hence, have 2 problems:
- i cant figure out how calculate fdr overcoming error
- how can add fdr column @ end of file fourth column?
Comments
Post a Comment