comparison Python/Heatmap.py @ 3:e42d30da7a74 draft

Uploaded
author dereeper
date Thu, 30 May 2024 11:52:25 +0000
parents
children
comparison
equal deleted inserted replaced
2:97e4e3e818b6 3:e42d30da7a74
1 import numpy as np
2 import pandas as pd
3 import seaborn as sns
4 import plotly.express as px
5 import xarray as xr
6
7 import sys, getopt
8
9 np.bool = np.bool_
10
11
12 def main(argv):
13 inputfile = ''
14 outputfile = ''
15 try:
16 opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
17 except getopt.GetoptError:
18 print ('Heatmap.py -i <inputfile> -o <outputfile>')
19 sys.exit(2)
20 for opt, arg in opts:
21 if opt == '-h':
22 print ('Heatmap.py -i <inputfile> -o <outputfile>')
23 sys.exit()
24 elif opt in ("-i", "--ifile"):
25 inputfile = arg
26 elif opt in ("-o", "--ofile"):
27 outputfile = arg
28 print ('Input file is "', inputfile)
29 print ('Output file is "', outputfile)
30
31 data = pd.read_csv(inputfile, sep='\t')
32
33 #data.drop(columns=data.columns[0], axis=1, inplace=True)
34
35 data2 = pd.read_csv(inputfile, sep='\t', header=None)
36 data2.drop(index=data2.index[0], axis=0, inplace=True)
37 data3 = data2[data2.columns[1:]]
38 data3_transposed = data3.T
39
40 myList = list(data.columns)
41 del myList[0]
42
43 myClusters = list(data['ClutserID'])
44
45 fig = px.imshow(data3_transposed,
46 x=myClusters,
47 y=myList,
48 labels=dict(y="Strains", x="Clusters"),
49 height = 900,width = 900,
50 color_continuous_scale=["lightgrey", "red","green"]
51 )
52
53 fig.update_traces(hovertemplate="<br>".join(["Cluster: %{x}","Strain: %{y}"]))
54 fig.update_coloraxes(showscale=False)
55 fig.update_layout(xaxis_scaleanchor="x")
56 fig.write_html(outputfile)
57
58 if __name__ == "__main__":
59 main(sys.argv[1:])