annotate ml_visualization_ex.py @ 15:b94babda32e4 draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit f031d8ddfb73cec24572648666ac44ee47f08aad
author bgruening
date Thu, 11 Aug 2022 09:11:27 +0000
parents b8378d4791b7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
1 import argparse
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
2 import json
11
2b679bb676be "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 10
diff changeset
3 import os
2b679bb676be "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 10
diff changeset
4 import warnings
2b679bb676be "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 10
diff changeset
5
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
6 import matplotlib
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
7 import matplotlib.pyplot as plt
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
8 import numpy as np
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
9 import pandas as pd
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
10 import plotly
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
11 import plotly.graph_objs as go
11
2b679bb676be "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 10
diff changeset
12 from galaxy_ml.utils import load_model, read_columns, SafeEval
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
13 from keras.models import model_from_json
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
14 from keras.utils import plot_model
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
15 from sklearn.feature_selection.base import SelectorMixin
12
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
16 from sklearn.metrics import (auc, average_precision_score, confusion_matrix,
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
17 precision_recall_curve, roc_curve)
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
18 from sklearn.pipeline import Pipeline
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
19
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
20 safe_eval = SafeEval()
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
21
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
22 # plotly default colors
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
23 default_colors = [
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
24 "#1f77b4", # muted blue
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
25 "#ff7f0e", # safety orange
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
26 "#2ca02c", # cooked asparagus green
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
27 "#d62728", # brick red
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
28 "#9467bd", # muted purple
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
29 "#8c564b", # chestnut brown
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
30 "#e377c2", # raspberry yogurt pink
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
31 "#7f7f7f", # middle gray
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
32 "#bcbd22", # curry yellow-green
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
33 "#17becf", # blue-teal
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
34 ]
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
35
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
36
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
37 def visualize_pr_curve_plotly(df1, df2, pos_label, title=None):
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
38 """output pr-curve in html using plotly
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
39
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
40 df1 : pandas.DataFrame
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
41 Containing y_true
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
42 df2 : pandas.DataFrame
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
43 Containing y_score
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
44 pos_label : None
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
45 The label of positive class
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
46 title : str
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
47 Plot title
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
48 """
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
49 data = []
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
50 for idx in range(df1.shape[1]):
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
51 y_true = df1.iloc[:, idx].values
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
52 y_score = df2.iloc[:, idx].values
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
53
12
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
54 precision, recall, _ = precision_recall_curve(
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
55 y_true, y_score, pos_label=pos_label
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
56 )
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
57 ap = average_precision_score(y_true, y_score, pos_label=pos_label or 1)
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
58
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
59 trace = go.Scatter(
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
60 x=recall,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
61 y=precision,
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
62 mode="lines",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
63 marker=dict(color=default_colors[idx % len(default_colors)]),
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
64 name="%s (area = %.3f)" % (idx, ap),
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
65 )
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
66 data.append(trace)
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
67
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
68 layout = go.Layout(
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
69 xaxis=dict(title="Recall", linecolor="lightslategray", linewidth=1),
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
70 yaxis=dict(title="Precision", linecolor="lightslategray", linewidth=1),
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
71 title=dict(
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
72 text=title or "Precision-Recall Curve",
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
73 x=0.5,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
74 y=0.92,
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
75 xanchor="center",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
76 yanchor="top",
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
77 ),
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
78 font=dict(family="sans-serif", size=11),
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
79 # control backgroud colors
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
80 plot_bgcolor="rgba(255,255,255,0)",
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
81 )
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
82 """
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
83 legend=dict(
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
84 x=0.95,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
85 y=0,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
86 traceorder="normal",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
87 font=dict(
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
88 family="sans-serif",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
89 size=9,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
90 color="black"
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
91 ),
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
92 bgcolor="LightSteelBlue",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
93 bordercolor="Black",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
94 borderwidth=2
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
95 ),"""
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
96
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
97 fig = go.Figure(data=data, layout=layout)
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
98
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
99 plotly.offline.plot(fig, filename="output.html", auto_open=False)
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
100 # to be discovered by `from_work_dir`
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
101 os.rename("output.html", "output")
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
102
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
103
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
104 def visualize_pr_curve_matplotlib(df1, df2, pos_label, title=None):
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
105 """visualize pr-curve using matplotlib and output svg image"""
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
106 backend = matplotlib.get_backend()
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
107 if "inline" not in backend:
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
108 matplotlib.use("SVG")
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
109 plt.style.use("seaborn-colorblind")
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
110 plt.figure()
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
111
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
112 for idx in range(df1.shape[1]):
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
113 y_true = df1.iloc[:, idx].values
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
114 y_score = df2.iloc[:, idx].values
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
115
12
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
116 precision, recall, _ = precision_recall_curve(
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
117 y_true, y_score, pos_label=pos_label
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
118 )
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
119 ap = average_precision_score(y_true, y_score, pos_label=pos_label or 1)
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
120
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
121 plt.step(
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
122 recall,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
123 precision,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
124 "r-",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
125 color="black",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
126 alpha=0.3,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
127 lw=1,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
128 where="post",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
129 label="%s (area = %.3f)" % (idx, ap),
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
130 )
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
131
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
132 plt.xlim([0.0, 1.0])
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
133 plt.ylim([0.0, 1.05])
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
134 plt.xlabel("Recall")
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
135 plt.ylabel("Precision")
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
136 title = title or "Precision-Recall Curve"
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
137 plt.title(title)
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
138 folder = os.getcwd()
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
139 plt.savefig(os.path.join(folder, "output.svg"), format="svg")
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
140 os.rename(os.path.join(folder, "output.svg"), os.path.join(folder, "output"))
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
141
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
142
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
143 def visualize_roc_curve_plotly(df1, df2, pos_label, drop_intermediate=True, title=None):
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
144 """output roc-curve in html using plotly
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
145
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
146 df1 : pandas.DataFrame
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
147 Containing y_true
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
148 df2 : pandas.DataFrame
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
149 Containing y_score
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
150 pos_label : None
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
151 The label of positive class
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
152 drop_intermediate : bool
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
153 Whether to drop some suboptimal thresholds
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
154 title : str
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
155 Plot title
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
156 """
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
157 data = []
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
158 for idx in range(df1.shape[1]):
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
159 y_true = df1.iloc[:, idx].values
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
160 y_score = df2.iloc[:, idx].values
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
161
12
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
162 fpr, tpr, _ = roc_curve(
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
163 y_true, y_score, pos_label=pos_label, drop_intermediate=drop_intermediate
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
164 )
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
165 roc_auc = auc(fpr, tpr)
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
166
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
167 trace = go.Scatter(
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
168 x=fpr,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
169 y=tpr,
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
170 mode="lines",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
171 marker=dict(color=default_colors[idx % len(default_colors)]),
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
172 name="%s (area = %.3f)" % (idx, roc_auc),
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
173 )
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
174 data.append(trace)
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
175
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
176 layout = go.Layout(
12
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
177 xaxis=dict(
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
178 title="False Positive Rate", linecolor="lightslategray", linewidth=1
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
179 ),
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
180 yaxis=dict(title="True Positive Rate", linecolor="lightslategray", linewidth=1),
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
181 title=dict(
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
182 text=title or "Receiver Operating Characteristic (ROC) Curve",
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
183 x=0.5,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
184 y=0.92,
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
185 xanchor="center",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
186 yanchor="top",
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
187 ),
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
188 font=dict(family="sans-serif", size=11),
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
189 # control backgroud colors
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
190 plot_bgcolor="rgba(255,255,255,0)",
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
191 )
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
192 """
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
193 # legend=dict(
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
194 # x=0.95,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
195 # y=0,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
196 # traceorder="normal",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
197 # font=dict(
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
198 # family="sans-serif",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
199 # size=9,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
200 # color="black"
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
201 # ),
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
202 # bgcolor="LightSteelBlue",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
203 # bordercolor="Black",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
204 # borderwidth=2
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
205 # ),
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
206 """
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
207
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
208 fig = go.Figure(data=data, layout=layout)
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
209
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
210 plotly.offline.plot(fig, filename="output.html", auto_open=False)
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
211 # to be discovered by `from_work_dir`
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
212 os.rename("output.html", "output")
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
213
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
214
12
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
215 def visualize_roc_curve_matplotlib(
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
216 df1, df2, pos_label, drop_intermediate=True, title=None
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
217 ):
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
218 """visualize roc-curve using matplotlib and output svg image"""
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
219 backend = matplotlib.get_backend()
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
220 if "inline" not in backend:
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
221 matplotlib.use("SVG")
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
222 plt.style.use("seaborn-colorblind")
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
223 plt.figure()
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
224
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
225 for idx in range(df1.shape[1]):
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
226 y_true = df1.iloc[:, idx].values
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
227 y_score = df2.iloc[:, idx].values
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
228
12
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
229 fpr, tpr, _ = roc_curve(
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
230 y_true, y_score, pos_label=pos_label, drop_intermediate=drop_intermediate
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
231 )
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
232 roc_auc = auc(fpr, tpr)
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
233
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
234 plt.step(
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
235 fpr,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
236 tpr,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
237 "r-",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
238 color="black",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
239 alpha=0.3,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
240 lw=1,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
241 where="post",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
242 label="%s (area = %.3f)" % (idx, roc_auc),
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
243 )
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
244
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
245 plt.xlim([0.0, 1.0])
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
246 plt.ylim([0.0, 1.05])
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
247 plt.xlabel("False Positive Rate")
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
248 plt.ylabel("True Positive Rate")
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
249 title = title or "Receiver Operating Characteristic (ROC) Curve"
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
250 plt.title(title)
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
251 folder = os.getcwd()
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
252 plt.savefig(os.path.join(folder, "output.svg"), format="svg")
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
253 os.rename(os.path.join(folder, "output.svg"), os.path.join(folder, "output"))
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
254
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
255
9
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
256 def get_dataframe(file_path, plot_selection, header_name, column_name):
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
257 header = "infer" if plot_selection[header_name] else None
9
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
258 column_option = plot_selection[column_name]["selected_column_selector_option"]
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
259 if column_option in [
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
260 "by_index_number",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
261 "all_but_by_index_number",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
262 "by_header_name",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
263 "all_but_by_header_name",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
264 ]:
9
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
265 col = plot_selection[column_name]["col1"]
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
266 else:
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
267 col = None
12
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
268 _, input_df = read_columns(
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
269 file_path,
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
270 c=col,
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
271 c_option=column_option,
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
272 return_df=True,
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
273 sep="\t",
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
274 header=header,
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
275 parse_dates=True,
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
276 )
9
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
277 return input_df
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
278
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
279
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
280 def main(
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
281 inputs,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
282 infile_estimator=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
283 infile1=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
284 infile2=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
285 outfile_result=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
286 outfile_object=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
287 groups=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
288 ref_seq=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
289 intervals=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
290 targets=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
291 fasta_path=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
292 model_config=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
293 true_labels=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
294 predicted_labels=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
295 plot_color=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
296 title=None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
297 ):
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
298 """
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
299 Parameter
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
300 ---------
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
301 inputs : str
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
302 File path to galaxy tool parameter
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
303
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
304 infile_estimator : str, default is None
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
305 File path to estimator
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
306
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
307 infile1 : str, default is None
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
308 File path to dataset containing features or true labels.
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
309
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
310 infile2 : str, default is None
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
311 File path to dataset containing target values or predicted
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
312 probabilities.
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
313
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
314 outfile_result : str, default is None
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
315 File path to save the results, either cv_results or test result
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
316
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
317 outfile_object : str, default is None
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
318 File path to save searchCV object
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
319
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
320 groups : str, default is None
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
321 File path to dataset containing groups labels
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
322
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
323 ref_seq : str, default is None
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
324 File path to dataset containing genome sequence file
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
325
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
326 intervals : str, default is None
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
327 File path to dataset containing interval file
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
328
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
329 targets : str, default is None
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
330 File path to dataset compressed target bed file
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
331
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
332 fasta_path : str, default is None
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
333 File path to dataset containing fasta file
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
334
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
335 model_config : str, default is None
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
336 File path to dataset containing JSON config for neural networks
9
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
337
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
338 true_labels : str, default is None
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
339 File path to dataset containing true labels
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
340
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
341 predicted_labels : str, default is None
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
342 File path to dataset containing true predicted labels
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
343
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
344 plot_color : str, default is None
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
345 Color of the confusion matrix heatmap
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
346
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
347 title : str, default is None
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
348 Title of the confusion matrix heatmap
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
349 """
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
350 warnings.simplefilter("ignore")
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
351
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
352 with open(inputs, "r") as param_handler:
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
353 params = json.load(param_handler)
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
354
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
355 title = params["plotting_selection"]["title"].strip()
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
356 plot_type = params["plotting_selection"]["plot_type"]
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
357 plot_format = params["plotting_selection"]["plot_format"]
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
358
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
359 if plot_type == "feature_importances":
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
360 with open(infile_estimator, "rb") as estimator_handler:
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
361 estimator = load_model(estimator_handler)
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
362
12
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
363 column_option = params["plotting_selection"]["column_selector_options"][
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
364 "selected_column_selector_option"
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
365 ]
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
366 if column_option in [
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
367 "by_index_number",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
368 "all_but_by_index_number",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
369 "by_header_name",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
370 "all_but_by_header_name",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
371 ]:
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
372 c = params["plotting_selection"]["column_selector_options"]["col1"]
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
373 else:
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
374 c = None
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
375
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
376 _, input_df = read_columns(
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
377 infile1,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
378 c=c,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
379 c_option=column_option,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
380 return_df=True,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
381 sep="\t",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
382 header="infer",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
383 parse_dates=True,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
384 )
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
385
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
386 feature_names = input_df.columns.values
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
387
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
388 if isinstance(estimator, Pipeline):
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
389 for st in estimator.steps[:-1]:
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
390 if isinstance(st[-1], SelectorMixin):
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
391 mask = st[-1].get_support()
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
392 feature_names = feature_names[mask]
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
393 estimator = estimator.steps[-1][-1]
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
394
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
395 if hasattr(estimator, "coef_"):
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
396 coefs = estimator.coef_
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
397 else:
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
398 coefs = getattr(estimator, "feature_importances_", None)
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
399 if coefs is None:
12
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
400 raise RuntimeError(
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
401 "The classifier does not expose "
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
402 '"coef_" or "feature_importances_" '
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
403 "attributes"
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
404 )
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
405
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
406 threshold = params["plotting_selection"]["threshold"]
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
407 if threshold is not None:
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
408 mask = (coefs > threshold) | (coefs < -threshold)
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
409 coefs = coefs[mask]
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
410 feature_names = feature_names[mask]
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
411
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
412 # sort
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
413 indices = np.argsort(coefs)[::-1]
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
414
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
415 trace = go.Bar(x=feature_names[indices], y=coefs[indices])
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
416 layout = go.Layout(title=title or "Feature Importances")
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
417 fig = go.Figure(data=[trace], layout=layout)
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
418
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
419 plotly.offline.plot(fig, filename="output.html", auto_open=False)
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
420 # to be discovered by `from_work_dir`
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
421 os.rename("output.html", "output")
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
422
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
423 return 0
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
424
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
425 elif plot_type in ("pr_curve", "roc_curve"):
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
426 df1 = pd.read_csv(infile1, sep="\t", header="infer")
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
427 df2 = pd.read_csv(infile2, sep="\t", header="infer").astype(np.float32)
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
428
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
429 minimum = params["plotting_selection"]["report_minimum_n_positives"]
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
430 # filter out columns whose n_positives is beblow the threhold
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
431 if minimum:
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
432 mask = df1.sum(axis=0) >= minimum
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
433 df1 = df1.loc[:, mask]
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
434 df2 = df2.loc[:, mask]
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
435
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
436 pos_label = params["plotting_selection"]["pos_label"].strip() or None
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
437
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
438 if plot_type == "pr_curve":
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
439 if plot_format == "plotly_html":
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
440 visualize_pr_curve_plotly(df1, df2, pos_label, title=title)
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
441 else:
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
442 visualize_pr_curve_matplotlib(df1, df2, pos_label, title)
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
443 else: # 'roc_curve'
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
444 drop_intermediate = params["plotting_selection"]["drop_intermediate"]
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
445 if plot_format == "plotly_html":
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
446 visualize_roc_curve_plotly(
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
447 df1,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
448 df2,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
449 pos_label,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
450 drop_intermediate=drop_intermediate,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
451 title=title,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
452 )
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
453 else:
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
454 visualize_roc_curve_matplotlib(
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
455 df1,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
456 df2,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
457 pos_label,
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
458 drop_intermediate=drop_intermediate,
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
459 title=title,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
460 )
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
461
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
462 return 0
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
463
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
464 elif plot_type == "rfecv_gridscores":
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
465 input_df = pd.read_csv(infile1, sep="\t", header="infer")
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
466 scores = input_df.iloc[:, 0]
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
467 steps = params["plotting_selection"]["steps"].strip()
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
468 steps = safe_eval(steps)
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
469
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
470 data = go.Scatter(
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
471 x=list(range(len(scores))),
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
472 y=scores,
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
473 text=[str(_) for _ in steps] if steps else None,
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
474 mode="lines",
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
475 )
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
476 layout = go.Layout(
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
477 xaxis=dict(title="Number of features selected"),
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
478 yaxis=dict(title="Cross validation score"),
12
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
479 title=dict(
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
480 text=title or None, x=0.5, y=0.92, xanchor="center", yanchor="top"
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
481 ),
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
482 font=dict(family="sans-serif", size=11),
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
483 # control backgroud colors
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
484 plot_bgcolor="rgba(255,255,255,0)",
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
485 )
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
486 """
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
487 # legend=dict(
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
488 # x=0.95,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
489 # y=0,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
490 # traceorder="normal",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
491 # font=dict(
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
492 # family="sans-serif",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
493 # size=9,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
494 # color="black"
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
495 # ),
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
496 # bgcolor="LightSteelBlue",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
497 # bordercolor="Black",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
498 # borderwidth=2
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
499 # ),
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
500 """
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
501
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
502 fig = go.Figure(data=[data], layout=layout)
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
503 plotly.offline.plot(fig, filename="output.html", auto_open=False)
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
504 # to be discovered by `from_work_dir`
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
505 os.rename("output.html", "output")
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
506
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
507 return 0
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
508
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
509 elif plot_type == "learning_curve":
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
510 input_df = pd.read_csv(infile1, sep="\t", header="infer")
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
511 plot_std_err = params["plotting_selection"]["plot_std_err"]
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
512 data1 = go.Scatter(
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
513 x=input_df["train_sizes_abs"],
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
514 y=input_df["mean_train_scores"],
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
515 error_y=dict(array=input_df["std_train_scores"]) if plot_std_err else None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
516 mode="lines",
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
517 name="Train Scores",
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
518 )
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
519 data2 = go.Scatter(
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
520 x=input_df["train_sizes_abs"],
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
521 y=input_df["mean_test_scores"],
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
522 error_y=dict(array=input_df["std_test_scores"]) if plot_std_err else None,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
523 mode="lines",
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
524 name="Test Scores",
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
525 )
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
526 layout = dict(
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
527 xaxis=dict(title="No. of samples"),
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
528 yaxis=dict(title="Performance Score"),
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
529 # modify these configurations to customize image
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
530 title=dict(
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
531 text=title or "Learning Curve",
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
532 x=0.5,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
533 y=0.92,
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
534 xanchor="center",
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
535 yanchor="top",
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
536 ),
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
537 font=dict(family="sans-serif", size=11),
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
538 # control backgroud colors
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
539 plot_bgcolor="rgba(255,255,255,0)",
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
540 )
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
541 """
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
542 # legend=dict(
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
543 # x=0.95,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
544 # y=0,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
545 # traceorder="normal",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
546 # font=dict(
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
547 # family="sans-serif",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
548 # size=9,
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
549 # color="black"
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
550 # ),
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
551 # bgcolor="LightSteelBlue",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
552 # bordercolor="Black",
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
553 # borderwidth=2
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
554 # ),
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
555 """
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
556
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
557 fig = go.Figure(data=[data1, data2], layout=layout)
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
558 plotly.offline.plot(fig, filename="output.html", auto_open=False)
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
559 # to be discovered by `from_work_dir`
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
560 os.rename("output.html", "output")
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
561
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
562 return 0
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
563
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
564 elif plot_type == "keras_plot_model":
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
565 with open(model_config, "r") as f:
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
566 model_str = f.read()
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
567 model = model_from_json(model_str)
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
568 plot_model(model, to_file="output.png")
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
569 os.rename("output.png", "output")
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
570
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
571 return 0
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
572
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
573 elif plot_type == "classification_confusion_matrix":
9
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
574 plot_selection = params["plotting_selection"]
12
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
575 input_true = get_dataframe(
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
576 true_labels, plot_selection, "header_true", "column_selector_options_true"
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
577 )
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
578 header_predicted = "infer" if plot_selection["header_predicted"] else None
12
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
579 input_predicted = pd.read_csv(
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
580 predicted_labels, sep="\t", parse_dates=True, header=header_predicted
b8378d4791b7 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 11
diff changeset
581 )
9
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
582 true_classes = input_true.iloc[:, -1].copy()
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
583 predicted_classes = input_predicted.iloc[:, -1].copy()
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
584 axis_labels = list(set(true_classes))
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
585 c_matrix = confusion_matrix(true_classes, predicted_classes)
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
586 fig, ax = plt.subplots(figsize=(7, 7))
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
587 im = plt.imshow(c_matrix, cmap=plot_color)
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
588 for i in range(len(c_matrix)):
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
589 for j in range(len(c_matrix)):
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
590 ax.text(j, i, c_matrix[i, j], ha="center", va="center", color="k")
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
591 ax.set_ylabel("True class labels")
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
592 ax.set_xlabel("Predicted class labels")
9
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
593 ax.set_title(title)
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
594 ax.set_xticks(axis_labels)
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
595 ax.set_yticks(axis_labels)
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
596 fig.colorbar(im, ax=ax)
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
597 fig.tight_layout()
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
598 plt.savefig("output.png", dpi=125)
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
599 os.rename("output.png", "output")
9
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
600
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
601 return 0
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
602
7
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
603 # save pdf file to disk
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
604 # fig.write_image("image.pdf", format='pdf')
a2e4a45c6083 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 6bb8bb56f44769dcba665de057c35d74ac89e196"
bgruening
parents: 4
diff changeset
605 # fig.write_image("image.pdf", format='pdf', width=340*2, height=226*2)
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
606
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
607
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
608 if __name__ == "__main__":
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
609 aparser = argparse.ArgumentParser()
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
610 aparser.add_argument("-i", "--inputs", dest="inputs", required=True)
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
611 aparser.add_argument("-e", "--estimator", dest="infile_estimator")
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
612 aparser.add_argument("-X", "--infile1", dest="infile1")
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
613 aparser.add_argument("-y", "--infile2", dest="infile2")
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
614 aparser.add_argument("-O", "--outfile_result", dest="outfile_result")
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
615 aparser.add_argument("-o", "--outfile_object", dest="outfile_object")
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
616 aparser.add_argument("-g", "--groups", dest="groups")
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
617 aparser.add_argument("-r", "--ref_seq", dest="ref_seq")
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
618 aparser.add_argument("-b", "--intervals", dest="intervals")
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
619 aparser.add_argument("-t", "--targets", dest="targets")
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
620 aparser.add_argument("-f", "--fasta_path", dest="fasta_path")
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
621 aparser.add_argument("-c", "--model_config", dest="model_config")
9
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
622 aparser.add_argument("-tl", "--true_labels", dest="true_labels")
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
623 aparser.add_argument("-pl", "--predicted_labels", dest="predicted_labels")
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
624 aparser.add_argument("-pc", "--plot_color", dest="plot_color")
b78007bf1cb8 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 2afb24f3c81d625312186750a714d702363012b5"
bgruening
parents: 7
diff changeset
625 aparser.add_argument("-pt", "--title", dest="title")
3
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
626 args = aparser.parse_args()
0e20520a63ee "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
diff changeset
627
10
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
628 main(
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
629 args.inputs,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
630 args.infile_estimator,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
631 args.infile1,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
632 args.infile2,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
633 args.outfile_result,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
634 outfile_object=args.outfile_object,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
635 groups=args.groups,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
636 ref_seq=args.ref_seq,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
637 intervals=args.intervals,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
638 targets=args.targets,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
639 fasta_path=args.fasta_path,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
640 model_config=args.model_config,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
641 true_labels=args.true_labels,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
642 predicted_labels=args.predicted_labels,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
643 plot_color=args.plot_color,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
644 title=args.title,
ac40a2fe5750 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 9
diff changeset
645 )