Commit 8e6f0088 authored by boussau's avatar boussau
Browse files

calc_multinomial.py can now handle gaps and X in the alignments (it ignores...

calc_multinomial.py can now handle gaps and X in the alignments (it ignores them), and outputs 1-LRT instead of LRT.
parent 37368a9e
......@@ -228,6 +228,8 @@ orderedAA["T"] = 16
orderedAA["V"] = 17
orderedAA["W"] = 18
orderedAA["Y"] = 19
orderedAA["X"] = 20
orderedAA["-"] = 20
# Alanine Ala A
# Cysteine Cys C
# Aspartic AciD Asp D
......@@ -288,16 +290,16 @@ def multinomial_lrt (vector1, vector2, vectorAll):
return lr, lrt
def applyMultinomialLRT(x, orderedAA):
cond1 = x['AA'][x['condition']==1]
cond0 = x['AA'][x['condition']==0]
cond1 = x['AA'][x['condition']==1] # all the amino acids of species with condition 1
cond0 = x['AA'][x['condition']==0] # all the amino acids of species with condition 0
vec0 = [0]*20
vec1 = [0]*20
for i in range (len (cond0)):
#print(cond0.iloc[i])
vec0[orderedAA[cond0.iloc[i]]] = vec0[orderedAA[cond0.iloc[i]]] + 1
if orderedAA[cond0.iloc[i]] != 20:
vec0[orderedAA[cond0.iloc[i]]] = vec0[orderedAA[cond0.iloc[i]]] + 1
for i in range (len (cond1)):
#print(cond1.iloc[i])
vec1[orderedAA[cond1.iloc[i]]] = vec1[orderedAA[cond1.iloc[i]]] + 1
if orderedAA[cond1.iloc[i]] != 20:
vec1[orderedAA[cond1.iloc[i]]] = vec1[orderedAA[cond1.iloc[i]]] + 1
#print(vec1)
vecAll = [sum(x) for x in zip(vec0, vec1)]
return multinomial_lrt(vec0, vec1, vecAll)
......@@ -313,9 +315,9 @@ LRTs = []
for i in range(1, df_leaves_grouped.shape[0]+1):
sites.append(i)
LRs.append(df_leaves_grouped[i][0])
LRTs.append(df_leaves_grouped[i][1])
LRTs.append(1-df_leaves_grouped[i][1])
df_final = pd.DataFrame({'Sites':sites, 'LikelihoodRatio':LRs, 'LRT':LRTs})
df_final = pd.DataFrame({'Sites':sites, 'LikelihoodRatio':LRs, '1MinusLRT':LRTs})
logger.info("Final dataframe built")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment