Skip to content

Commit

Permalink
Introduced .html ouput file, various bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
clinte14 committed Sep 6, 2023
1 parent 4a15772 commit 9116347
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 9 deletions.
Binary file added __pycache__/blast_parse.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/blast_parse.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/correlation_calcs.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/correlation_calcs.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/create_visuals.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/create_visuals.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/housekeeping.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/housekeeping.cpython-39.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions correlation_calcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def correlation_calcs(flag_values):

#need print statement here to console
return Wij_df

def calc_mrs(Wij_df, flag_values):
Wij_outerDict = {}
gene_names = Wij_df.dtypes.index
Expand Down
31 changes: 27 additions & 4 deletions create_visuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import os
import numpy as np
import graphviz
import networkx as nx
from pyvis.network import Network

#https://towardsdatascience.com/visualising-stocks-correlations-with-networkx-88f2ee25362e
#https://www.cl.cam.ac.uk/teaching/1314/L109/tutorial.pdf
Expand All @@ -14,27 +16,48 @@
#https://stackoverflow.com/questions/32303217/how-to-use-pearson-correlation-as-distance-metric-in-scikit-learn-agglomerative
#https://stats.stackexchange.com/questions/275720/does-any-other-clustering-algorithms-take-correlation-as-distance-metric-apart
#https://online.stat.psu.edu/stat555/node/85/
def create_network_map(Wij_df, flag_values, network_list):

def create_network_map(flag_values, network_list):
#breakpoint()
for count, value in enumerate(network_list):
network_list[count][2] = '{:.4f}'.format(value[2])
r
# Create 'dot' engine style graphviz network visual
network = graphviz.Digraph('Maximum_Related_Networks_dot', engine='dot', comment='')

for i in network_list:
edge_thickness = str(i[2]*5)
correlog_score = '{:.4f}'.format(i[2])
correlog_score = i[2]
network.edge(i[0], i[1], penwidth=edge_thickness, xlabel=correlog_score)

network.render(directory=os.path.join(flag_values['output'], '05_final_outputs'))

# Create 'circl' engine style graphviz network visual
#DG = nx.DiGraph()
#DG.add_weighted_edges_from(network_list)
nx_graph = nx.DiGraph()
for item in network_list:
nx_graph.add_node(item[0])
for item in network_list:
nx_graph.add_edge(item[0],item[1],label=item[2])

nt = Network('800px', '1080px')
nt.from_nx(nx_graph)
nt.toggle_physics(True)
nt.show_buttons(True)
os.chdir(os.path.join(flag_values['output'], '05_final_outputs'))
nt.write_html("MSR_network.html",notebook=False)

# Create 'circo' engine style graphviz network visual
network = graphviz.Digraph('Maximum_Related_Networks_circo', engine='circo', comment='')

for i in network_list:
edge_thickness = str(i[2]*5)
correlog_score = '{:.4f}'.format(i[2])
correlog_score = correlog_score = i[2]
network.edge(i[0], i[1], penwidth=edge_thickness, xlabel=correlog_score)

network.render(directory=os.path.join(flag_values['output'], '05_final_outputs'))


#need print statement here to console

def create_heatmap(Wij_df, flag_values):
Expand Down
14 changes: 10 additions & 4 deletions housekeeping.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os.path
import argparse, datetime, json
import pandas as pd
import sys
def create_folders(dir_path):
dirs = ['00_log',
'01_blast_input',
Expand Down Expand Up @@ -43,9 +44,14 @@ def parse_flags():
arg_dict=vars(args)

# Convert relative paths (eg './' in BASH) to absolute paths
arg_dict['input'] = os.path.abspath(arg_dict['input'])
arg_dict['output'] = os.path.abspath(arg_dict['output'])
arg_dict['common_name'] = os.path.abspath(arg_dict['common_name'])
if arg_dict['input']!=None:
arg_dict['input'] = os.path.abspath(arg_dict['input'])

if arg_dict['output']!=None:
arg_dict['output'] = os.path.abspath(arg_dict['output'])

if arg_dict['common_name']!=None:
arg_dict['common_name'] = os.path.abspath(arg_dict['common_name'])

print("dir_path: " + str(dir_path))
return arg_dict
Expand Down Expand Up @@ -107,7 +113,7 @@ def convert_protID_to_common_names(flag_values, hits):
# Rename keys that are protein IDs with common gene names. Using lists from comment above.
for k in common_name_list:
for hit in hits_list:
if k in hit:
if k == hit:
print("Common name:'{}' is in hit name: '{}'".format(k,hit))
hits[common_name[k]] = hits[hit]
del hits[hit]
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def main():
Wij_df= correlation_calcs(flag_values)
network_list = calc_mrs(Wij_df, flag_values)

create_network_map(Wij_df, flag_values, network_list)
create_network_map(flag_values, network_list)
create_heatmap(Wij_df, flag_values)

if __name__ == "__main__":
Expand Down

0 comments on commit 9116347

Please sign in to comment.