Skip to content

Commit

Permalink
Merge pull request #122 from lorenzoamir/main
Browse files Browse the repository at this point in the history
fix #119
  • Loading branch information
nargesr authored Oct 9, 2024
2 parents b4c4d27 + d7f65c3 commit d0c6c18
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions PyWGCNA/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def calculateFraction(self):
list2 = self.geneModules[network2].index[
self.geneModules[network2].moduleColors == module2].tolist()
num = np.intersect1d(list1, list2)
fraction.loc[f"{network1}:{module1}", f"{network2}:{module2}"] = len(num) / len(list2) * 100
fraction.loc[f"{network1}:{module1}", f"{network2}:{module2}"] = len(num) / len(list2)
else:
modules = self.geneModules[network1].moduleColors.unique().tolist()
for module in modules:
Expand All @@ -123,11 +123,13 @@ def calculateFraction(self):

return fraction

def calculatePvalue(self):
def calculatePvalue(self, alternative='greater'):
"""
Calculate pvalue of fraction along multiple networks
:return: dataframe containing pvalue between all modules in all netwroks
Calculate pvalue of modules overlap along multiple networks using fisher exact test
:param alternative: {'two-sided', 'less', 'greater'}, alternative hypothesis, use 'greater' to detect overlapping modules, 'less' to detect mutually exclusive modules, 'two-sided' to detect both (default: greater)
:type alternative: str
:return: dataframe containing pvalue between all modules in all networks
:rtype: pandas dataframe
"""

Expand Down Expand Up @@ -158,11 +160,11 @@ def calculatePvalue(self):
list2 = self.geneModules[network2].index[
self.geneModules[network2].moduleColors == module2].tolist()
number = self.fraction.loc[f"{network1}:{module1}", f"{network2}:{module2}"] * len(
list2) / 100
list2)
table = np.array(
[[nGenes - len(list1) - len(list2) + number, len(list1) - number],
[len(list2) - number, number]])
oddsr, p = fisher_exact(table, alternative='two-sided')
oddsr, p = fisher_exact(table, alternative=alternative)
pvalue.loc[f"{network1}:{module1}", f"{network2}:{module2}"] = p
self.P_value = pvalue

Expand Down

0 comments on commit d0c6c18

Please sign in to comment.