Skip to content

Commit

Permalink
main_lab
Browse files Browse the repository at this point in the history
  • Loading branch information
Chenjy0212 committed Sep 26, 2022
1 parent 946f9a7 commit a755ce5
Show file tree
Hide file tree
Showing 8 changed files with 495 additions and 513 deletions.
Empty file modified mdelta/Pvalue.py
100644 → 100755
Empty file.
12 changes: 7 additions & 5 deletions mdelta/ReadFile.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ def ReadTreeSeq(TreeSeqFilePath):
#print(content)
return content.replace(';', '')

def Scoredict(lllleaf, llllleaf, mv:float):
def Scoredict(lllleaf, llllleaf, mav:float, miv:float):
#如果是自动生成的话
#可以用到笛卡尔积
score_dict = {}
#for i in itertools.product(set(lllleaf), set(llllleaf)):
# score_dict[i[0].nodeobj+'_'+i[1].nodeobj] = float(random.randint(-2,2))
for i in itertools.product(set(lllleaf), set(llllleaf)):
score_dict[i[0].nodeobj+'_'+i[1].nodeobj] = float(miv)
#score_dict[i[0].nodeobj+'_'+i[1].nodeobj] = random.random()/10
#print(score_dict)

#或者用到相同节点才匹配
#score_dict = {}
for i in lllleaf + llllleaf:
score_dict[i.nodeobj+'_'+i.nodeobj] = mv
for i in lllleaf:
score_dict[i.nodeobj+'_'+i.nodeobj] = float(mav)
for i in llllleaf:
score_dict[i.nodeobj+'_'+i.nodeobj] = float(mav)
return score_dict

def reverseScore(Score, matchScore:float):
Expand Down
77 changes: 46 additions & 31 deletions mdelta/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -474,25 +474,30 @@ def scoremat(TreeSeqFile:str,
llll_label = [i.label for i in llll[0]],
merge = merge,)

def changemat(rac, tracemat, tracemat_value, mat, list_tmp1, list_tmp2):
for i in tracemat_value[tuple(rac)]:
if isinstance(i[0],int) and isinstance(i[1],int):
list_tmp1.append(tracemat.index[i[0]])
list_tmp2.append(tracemat.columns[i[1]])
elif not isinstance(i[0],int) and not isinstance(i[1],int):
list_tmp1.append(tracemat.index[rac[0]])
list_tmp2.append(tracemat.columns[rac[1]])
return
#print(i[0],i[0])
for i in tracemat_value[tuple(rac)]:
if isinstance(i[0],int) and isinstance(i[1],int):
#print(i[0],root1.leaf_count(), i[1],root2.leaf_count())
if i == [] or (i[0]<root1.leaf_count() and i[1] <root2.leaf_count()):
mat[tuple(i)] = -99999.
else:
mat[tuple(i)] = -99999.
#print(i)
changemat(i, tracemat,tracemat_value, mat, list_tmp1, list_tmp2)
def changemat(rac, tracemat, tracemat_value, mat, list_tmp1, list_tmp2, ttused):
for i in tracemat_value[tuple(rac)]:
if isinstance(i[0],int) and isinstance(i[1],int):
list_tmp1.append(tracemat.index[i[0]])
#print(tracemat.index[i[0]])
list_tmp2.append(tracemat.columns[i[1]])
#print(tracemat.index[i[1]])
elif not isinstance(i[0],int) and not isinstance(i[1],int):
list_tmp1.append(tracemat.index[rac[0]])
#print(tracemat.index[rac[0]])
list_tmp2.append(tracemat.columns[rac[1]])
return

#print(i[0],i[0])
for i in tracemat_value[tuple(rac)]:
ttused.append(str(i))
if isinstance(i[0],int) and isinstance(i[1],int):
#print(i[0],root1.leaf_count(), i[1],root2.leaf_count())
if i == [] or (i[0]<root1.leaf_count() and i[1] <root2.leaf_count()):
mat[tuple(i)] = -99999.
else:
mat[tuple(i)] = -99999.
#print(i)
changemat(i, tracemat,tracemat_value, mat, list_tmp1, list_tmp2, ttused)
#return mat
def getmatchtree(rac, lllnode_obj, llllnode_obj, tracemat_value, mat, tree_tmp1, tree_tmp2):
for i in tracemat_value[tuple(rac)]:
Expand Down Expand Up @@ -538,7 +543,8 @@ def where_prune(match_list:list, leaves_list:list):
list_tmp1 = []
list_tmp2 = []
mat_tmp[-1,-1] = -99999.
changemat([-1,-1],ttrace, trace_value,mat_tmp, list_tmp1, list_tmp2)
ttused = [str([root1.node_count()-1, root2.node_count()-1])]
changemat([-1,-1],ttrace, trace_value,mat_tmp, list_tmp1, list_tmp2, ttused)

mat_tmp2 = deepcopy(matrix_values)
tree_tmp1 = []
Expand Down Expand Up @@ -576,7 +582,9 @@ def where_prune(match_list:list, leaves_list:list):
'Root1_prune':where_prune(list_tmp1, list(map(lambda x:x.label,root1.leaves([])))),
'Root2_prune':where_prune(list_tmp2, list(map(lambda x:x.label,root2.leaves([])))),
'row':root1.node_count()-1,
'col':root2.node_count()-1})
'col':root2.node_count()-1,
'used':ttused
})

return({'matrix':mmatrix,
'tree1_leaves_nodename': oroot1_label2celltype[1],
Expand All @@ -603,7 +611,8 @@ def where_prune(match_list:list, leaves_list:list):
list_tmp1 = []
list_tmp2 = []
mat_tmp[del_i_index,del_j_index] = -99999.
changemat([del_i_index,del_j_index],ttrace, trace_value,mat_tmp, list_tmp1, list_tmp2)
ttused = [str([del_i_index, del_j_index])]
changemat([del_i_index,del_j_index],ttrace, trace_value,mat_tmp, list_tmp1, list_tmp2, ttused)

tree_tmp1 = []
tree_tmp2 = []
Expand All @@ -619,21 +628,22 @@ def where_prune(match_list:list, leaves_list:list):
# list_tmp1.insert(0,lllnode[del_i_index].label)
#if list_tmp2[0] != llllnode[del_j_index].label:
# list_tmp2.insert(0,llllnode[del_j_index].label)
if jjj > 0:
if len(scorelist[-1]['Root1_match']) == 0:
percent = 0
else:
percent = (len(list(set(list_tmp1) - set(scorelist[-1]['Root1_match'])) + list(set(scorelist[-1]['Root1_match']) - set(list_tmp1))) / len(scorelist[-1]['Root1_match']))*100.
if round(percent) < diff:
#print(round(percent))
if jjj > 0 and diff > 0:
for i in range(len(scorelist)):
percent = min(percent, len(set(scorelist[i]['used']) - set(ttused)) / len(scorelist[i]['used'])*100.)

while percent < float(diff):
maxscore = np.max(mat_tmp)
if (maxscore + 99999.) < 0.01:
break
del_i_index = np.where(mat_tmp==np.max(mat_tmp))[0][0]
del_j_index = np.where(mat_tmp==np.max(mat_tmp))[1][0]

list_tmp1 = []
list_tmp2 = []
mat_tmp[del_i_index,del_j_index] = -99999.
changemat([del_i_index,del_j_index],ttrace, trace_value,mat_tmp, list_tmp1, list_tmp2)
ttused = [str([del_i_index, del_j_index])]
changemat([del_i_index,del_j_index],ttrace, trace_value,mat_tmp, list_tmp1, list_tmp2, ttused)

tree_tmp1 = []
tree_tmp2 = []
Expand All @@ -644,6 +654,9 @@ def where_prune(match_list:list, leaves_list:list):
tree_tmp4 = []
mat_tmp3[del_i_index,del_j_index] = -99999.
getmatchtree([del_i_index,del_j_index],lllnode_label, llllnode_label, trace_value,mat_tmp3, tree_tmp3, tree_tmp4)
percent = 100
for i in range(len(scorelist)):
percent = min(percent, len(set(scorelist[i]['used']) - set(ttused)) / len(scorelist[i]['used'])*100.)

tree_tmp1.append(';')
tree_tmp2.append(';')
Expand All @@ -668,7 +681,9 @@ def where_prune(match_list:list, leaves_list:list):
'Root1_prune':where_prune(list_tmp1, list(map(lambda x:x.label,lllnode[del_i_index].leaves([])))),
'Root2_prune':where_prune(list_tmp2, list(map(lambda x:x.label,llllnode[del_j_index].leaves([])))),
'row':del_i_index,
'col':del_j_index})
'col':del_j_index,
'used':ttused
})

return({'matrix':mmatrix,
'tree1_leaves_nodename': oroot1_label2celltype[1],
Expand Down
5 changes: 0 additions & 5 deletions mdelta/__version__.py

This file was deleted.

Empty file modified mdelta/auxi.py
100644 → 100755
Empty file.
Loading

0 comments on commit a755ce5

Please sign in to comment.