Last active
March 8, 2019 07:12
-
-
Save crazyhottommy/67179a5f2925794a09d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env python | |
| import sys | |
| import scipy.stats as stats | |
| #The result will be | |
| # a p-value where by random chance number of genes with both condition A and B will be <= to your number with condition A and B | |
| # a p-value where by random chance number of genes with both condition A and B will be >= to your number with condition A and B | |
| # The second p-value is probably what you want. | |
| if len(sys.argv) < 5: | |
| print '''use it by: python gene_sets_hypergeomtric_test.py [total number of genes in the list] [total number of genes in the list with condition A] [total number of genes in the list with condition B] [number of genes with both condition A and B]''' | |
| sys.exit() | |
| print 'total number in population: ' + sys.argv[1] | |
| print 'total number with condition in population: ' + sys.argv[2] | |
| print 'number in subset: ' + sys.argv[3] | |
| print 'number with condition in subset: ' + sys.argv[4] | |
| print 'p-value <= ' + sys.argv[4] + ': ' + str(stats.hypergeom.cdf(int(sys.argv[4]) + 1,int(sys.argv[1]),int(sys.argv[2]),int(sys.argv[3]))) | |
| print 'p-value >= ' + sys.argv[4] + ': ' + str(stats.hypergeom.sf(int(sys.argv[4]) - 1,int(sys.argv[1]),int(sys.argv[2]),int(sys.argv[3]))) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # phyper(overlap-1,list1,PopSize-list1,list2,lower.tail = FALSE, log.p = FALSE) | |
| phyper(100-1, 3000, 15000-3000, 400,lower.tail = FALSE, log.p = FALSE) | |
| #0.00784 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I foudn thsi extremely helpful for converting hypergeometric.r to python. Thank you!