annotate lifelines_tool/lifelineskmcph.xml @ 2:dd5e65893cb8 draft default tip

add survival and collapsed life table outputs suggested by Wolfgang
author fubar
date Thu, 10 Aug 2023 22:52:45 +0000
parents 232b874046a7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
dd49a7040643 Initial commit
fubar
parents:
diff changeset
1 <tool name="lifelineskmcph" id="lifelineskmcph" version="0.01">
dd49a7040643 Initial commit
fubar
parents:
diff changeset
2 <!--Source in git at: https://github.com/fubar2/galaxy_tf_overlay-->
2
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
3 <!--Created by toolfactory@galaxy.org at 10/08/2023 21:59:53 using the Galaxy Tool Factory.-->
0
dd49a7040643 Initial commit
fubar
parents:
diff changeset
4 <description>Lifelines KM and optional Cox PH models</description>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
5 <requirements>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
6 <requirement version="1.5.3" type="package">pandas</requirement>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
7 <requirement version="3.7.2" type="package">matplotlib</requirement>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
8 <requirement version="0.27.7" type="package">lifelines</requirement>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
9 </requirements>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
10 <stdio>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
11 <exit_code range="1:" level="fatal"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
12 </stdio>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
13 <version_command><![CDATA[echo "0.01"]]></version_command>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
14 <command><![CDATA[python
dd49a7040643 Initial commit
fubar
parents:
diff changeset
15 $runme
dd49a7040643 Initial commit
fubar
parents:
diff changeset
16 --input_tab
dd49a7040643 Initial commit
fubar
parents:
diff changeset
17 $input_tab
dd49a7040643 Initial commit
fubar
parents:
diff changeset
18 --readme
dd49a7040643 Initial commit
fubar
parents:
diff changeset
19 $readme
dd49a7040643 Initial commit
fubar
parents:
diff changeset
20 --time
dd49a7040643 Initial commit
fubar
parents:
diff changeset
21 '$time'
dd49a7040643 Initial commit
fubar
parents:
diff changeset
22 --status
dd49a7040643 Initial commit
fubar
parents:
diff changeset
23 '$status'
dd49a7040643 Initial commit
fubar
parents:
diff changeset
24 --cphcols
dd49a7040643 Initial commit
fubar
parents:
diff changeset
25 '$CPHcovariatecolumnnames'
dd49a7040643 Initial commit
fubar
parents:
diff changeset
26 --title
dd49a7040643 Initial commit
fubar
parents:
diff changeset
27 '$title'
dd49a7040643 Initial commit
fubar
parents:
diff changeset
28 --header
dd49a7040643 Initial commit
fubar
parents:
diff changeset
29 '$header'
dd49a7040643 Initial commit
fubar
parents:
diff changeset
30 --group
dd49a7040643 Initial commit
fubar
parents:
diff changeset
31 '$group'
dd49a7040643 Initial commit
fubar
parents:
diff changeset
32 --image_type
dd49a7040643 Initial commit
fubar
parents:
diff changeset
33 '$image_type'
dd49a7040643 Initial commit
fubar
parents:
diff changeset
34 --image_dir
dd49a7040643 Initial commit
fubar
parents:
diff changeset
35 'image_dir']]></command>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
36 <configfiles>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
37 <configfile name="runme"><![CDATA[#raw
dd49a7040643 Initial commit
fubar
parents:
diff changeset
38
dd49a7040643 Initial commit
fubar
parents:
diff changeset
39 # script for a lifelines ToolFactory KM/CPH tool for Galaxy
dd49a7040643 Initial commit
fubar
parents:
diff changeset
40 # km models for https://github.com/galaxyproject/tools-iuc/issues/5393
dd49a7040643 Initial commit
fubar
parents:
diff changeset
41 # test as
dd49a7040643 Initial commit
fubar
parents:
diff changeset
42 # python plotlykm.py --input_tab rossi.tab --htmlout "testfoo" --time "week" --status "arrest" --title "test" --image_dir images --cphcol="prio,age,race,paro,mar,fin"
1
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
43 # Ross Lazarus July 2023
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
44 import argparse
0
dd49a7040643 Initial commit
fubar
parents:
diff changeset
45
dd49a7040643 Initial commit
fubar
parents:
diff changeset
46 import os
dd49a7040643 Initial commit
fubar
parents:
diff changeset
47 import sys
dd49a7040643 Initial commit
fubar
parents:
diff changeset
48
dd49a7040643 Initial commit
fubar
parents:
diff changeset
49 import lifelines
dd49a7040643 Initial commit
fubar
parents:
diff changeset
50
dd49a7040643 Initial commit
fubar
parents:
diff changeset
51 from matplotlib import pyplot as plt
dd49a7040643 Initial commit
fubar
parents:
diff changeset
52
dd49a7040643 Initial commit
fubar
parents:
diff changeset
53 import pandas as pd
dd49a7040643 Initial commit
fubar
parents:
diff changeset
54
dd49a7040643 Initial commit
fubar
parents:
diff changeset
55
1
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
56 def trimlegend(v):
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
57 """
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
58 for int64 quintiles - must be ints - otherwise get silly legends with long float values
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
59 """
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
60 for i, av in enumerate(v):
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
61 x = int(av)
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
62 v[i] = str(x)
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
63 return v
0
dd49a7040643 Initial commit
fubar
parents:
diff changeset
64
dd49a7040643 Initial commit
fubar
parents:
diff changeset
65 kmf = lifelines.KaplanMeierFitter()
dd49a7040643 Initial commit
fubar
parents:
diff changeset
66 cph = lifelines.CoxPHFitter()
dd49a7040643 Initial commit
fubar
parents:
diff changeset
67
dd49a7040643 Initial commit
fubar
parents:
diff changeset
68 parser = argparse.ArgumentParser()
dd49a7040643 Initial commit
fubar
parents:
diff changeset
69 a = parser.add_argument
1
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
70 a('--input_tab', default='rossi.tab', required=True)
0
dd49a7040643 Initial commit
fubar
parents:
diff changeset
71 a('--header', default='')
dd49a7040643 Initial commit
fubar
parents:
diff changeset
72 a('--htmlout', default="test_run.html")
dd49a7040643 Initial commit
fubar
parents:
diff changeset
73 a('--group', default='')
dd49a7040643 Initial commit
fubar
parents:
diff changeset
74 a('--time', default='', required=True)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
75 a('--status',default='', required=True)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
76 a('--cphcols',default='')
dd49a7040643 Initial commit
fubar
parents:
diff changeset
77 a('--title', default='Default plot title')
dd49a7040643 Initial commit
fubar
parents:
diff changeset
78 a('--image_type', default='png')
dd49a7040643 Initial commit
fubar
parents:
diff changeset
79 a('--image_dir', default='images')
dd49a7040643 Initial commit
fubar
parents:
diff changeset
80 a('--readme', default='run_log.txt')
dd49a7040643 Initial commit
fubar
parents:
diff changeset
81 args = parser.parse_args()
dd49a7040643 Initial commit
fubar
parents:
diff changeset
82 sys.stdout = open(args.readme, 'w')
dd49a7040643 Initial commit
fubar
parents:
diff changeset
83 df = pd.read_csv(args.input_tab, sep='\t')
dd49a7040643 Initial commit
fubar
parents:
diff changeset
84 NCOLS = df.columns.size
dd49a7040643 Initial commit
fubar
parents:
diff changeset
85 NROWS = len(df.index)
1
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
86 QVALS = [.2, .4, .6, .8] # for partial cox ph plots
0
dd49a7040643 Initial commit
fubar
parents:
diff changeset
87 defaultcols = ['col%d' % (x+1) for x in range(NCOLS)]
dd49a7040643 Initial commit
fubar
parents:
diff changeset
88 testcols = df.columns
dd49a7040643 Initial commit
fubar
parents:
diff changeset
89 if len(args.header.strip()) > 0:
dd49a7040643 Initial commit
fubar
parents:
diff changeset
90 newcols = args.header.split(',')
dd49a7040643 Initial commit
fubar
parents:
diff changeset
91 if len(newcols) == NCOLS:
dd49a7040643 Initial commit
fubar
parents:
diff changeset
92 if (args.time in newcols) and (args.status in newcols):
dd49a7040643 Initial commit
fubar
parents:
diff changeset
93 df.columns = newcols
dd49a7040643 Initial commit
fubar
parents:
diff changeset
94 else:
dd49a7040643 Initial commit
fubar
parents:
diff changeset
95 sys.stderr.write('## CRITICAL USAGE ERROR (not a bug!): time %s and/or status %s not found in supplied header parameter %s' % (args.time, args.status, args.header))
dd49a7040643 Initial commit
fubar
parents:
diff changeset
96 sys.exit(4)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
97 else:
dd49a7040643 Initial commit
fubar
parents:
diff changeset
98 sys.stderr.write('## CRITICAL USAGE ERROR (not a bug!): Supplied header %s has %d comma delimited header names - does not match the input tabular file %d columns' % (args.header, len(newcols), NCOLS))
dd49a7040643 Initial commit
fubar
parents:
diff changeset
99 sys.exit(5)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
100 else: # no header supplied - check for a real one that matches the x and y axis column names
dd49a7040643 Initial commit
fubar
parents:
diff changeset
101 colsok = (args.time in testcols) and (args.status in testcols) # if they match, probably ok...should use more code and logic..
dd49a7040643 Initial commit
fubar
parents:
diff changeset
102 if colsok:
dd49a7040643 Initial commit
fubar
parents:
diff changeset
103 df.columns = testcols # use actual header
dd49a7040643 Initial commit
fubar
parents:
diff changeset
104 else:
dd49a7040643 Initial commit
fubar
parents:
diff changeset
105 colsok = (args.time in defaultcols) and (args.status in defaultcols)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
106 if colsok:
2
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
107 print('Replacing first row of data derived header %s with %s' % (testcols, defaultcols))
0
dd49a7040643 Initial commit
fubar
parents:
diff changeset
108 df.columns = defaultcols
dd49a7040643 Initial commit
fubar
parents:
diff changeset
109 else:
dd49a7040643 Initial commit
fubar
parents:
diff changeset
110 sys.stderr.write('## CRITICAL USAGE ERROR (not a bug!): time %s and status %s do not match anything in the file header, supplied header or automatic default column names %s' % (args.time, args.status, defaultcols))
2
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
111 print('## Lifelines tool\nInput data header =', df.columns, 'time column =', args.time, 'status column =', args.status)
0
dd49a7040643 Initial commit
fubar
parents:
diff changeset
112 os.makedirs(args.image_dir, exist_ok=True)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
113 fig, ax = plt.subplots()
dd49a7040643 Initial commit
fubar
parents:
diff changeset
114 if args.group > '':
dd49a7040643 Initial commit
fubar
parents:
diff changeset
115 names = []
dd49a7040643 Initial commit
fubar
parents:
diff changeset
116 times = []
dd49a7040643 Initial commit
fubar
parents:
diff changeset
117 events = []
dd49a7040643 Initial commit
fubar
parents:
diff changeset
118 for name, grouped_df in df.groupby(args.group):
dd49a7040643 Initial commit
fubar
parents:
diff changeset
119 T = grouped_df[args.time]
dd49a7040643 Initial commit
fubar
parents:
diff changeset
120 E = grouped_df[args.status]
dd49a7040643 Initial commit
fubar
parents:
diff changeset
121 gfit = kmf.fit(T, E, label=name)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
122 kmf.plot_survival_function(ax=ax)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
123 names.append(str(name))
dd49a7040643 Initial commit
fubar
parents:
diff changeset
124 times.append(T)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
125 events.append(E)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
126 ax.set_title(args.title)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
127 fig.savefig(os.path.join(args.image_dir,'KM_%s.png' % args.title))
dd49a7040643 Initial commit
fubar
parents:
diff changeset
128 ngroup = len(names)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
129 if ngroup == 2: # run logrank test if 2 groups
dd49a7040643 Initial commit
fubar
parents:
diff changeset
130 results = lifelines.statistics.logrank_test(times[0], times[1], events[0], events[1], alpha=.99)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
131 print('Logrank test for %s - %s vs %s\n' % (args.group, names[0], names[1]))
dd49a7040643 Initial commit
fubar
parents:
diff changeset
132 results.print_summary()
dd49a7040643 Initial commit
fubar
parents:
diff changeset
133 else:
dd49a7040643 Initial commit
fubar
parents:
diff changeset
134 kmf.fit(df[args.time], df[args.status])
dd49a7040643 Initial commit
fubar
parents:
diff changeset
135 kmf.plot_survival_function(ax=ax)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
136 ax.set_title(args.title)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
137 fig.savefig(os.path.join(args.image_dir,'KM_%s.png' % args.title))
1
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
138 print('#### No grouping variable, so no log rank or other Kaplan-Meier statistical output is available')
2
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
139 survdf = lifelines.utils.survival_table_from_events(df[args.time], df[args.status])
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
140 lifedf = lifelines.utils.survival_table_from_events(df[args.time], df[args.status], collapse=True)
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
141 print("#### Survival table using time %s and event %s" % (args.time, args.status))
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
142 with pd.option_context('display.max_rows', None,
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
143 'display.max_columns', None,
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
144 'display.precision', 3,
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
145 ):
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
146 print(survdf)
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
147 print("#### Life table using time %s and event %s" % (args.time, args.status))
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
148 with pd.option_context('display.max_rows', None,
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
149 'display.max_columns', None,
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
150 'display.precision', 3,
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
151 ):
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
152 print(lifedf)
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
153 outpath = os.path.join(args.image_dir,'survival_table.tabular')
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
154 survdf.to_csv(outpath, sep='\t')
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
155 outpath = os.path.join(args.image_dir,'life_table.tabular')
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
156 lifedf.to_csv(outpath, sep='\t')
0
dd49a7040643 Initial commit
fubar
parents:
diff changeset
157 if len(args.cphcols) > 0:
dd49a7040643 Initial commit
fubar
parents:
diff changeset
158 fig, ax = plt.subplots()
1
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
159 ax.set_title('Cox-PH model: %s' % args.title)
0
dd49a7040643 Initial commit
fubar
parents:
diff changeset
160 cphcols = args.cphcols.strip().split(',')
dd49a7040643 Initial commit
fubar
parents:
diff changeset
161 cphcols = [x.strip() for x in cphcols]
dd49a7040643 Initial commit
fubar
parents:
diff changeset
162 notfound = sum([(x not in df.columns) for x in cphcols])
dd49a7040643 Initial commit
fubar
parents:
diff changeset
163 if notfound > 0:
dd49a7040643 Initial commit
fubar
parents:
diff changeset
164 sys.stderr.write('## CRITICAL USAGE ERROR (not a bug!): One or more requested Cox PH columns %s not found in supplied column header %s' % (args.cphcols, df.columns))
dd49a7040643 Initial commit
fubar
parents:
diff changeset
165 sys.exit(6)
1
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
166 colsdf = df[cphcols]
0
dd49a7040643 Initial commit
fubar
parents:
diff changeset
167 print('### Lifelines test of Proportional Hazards results with %s as covariates on %s' % (', '.join(cphcols), args.title))
1
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
168 cutcphcols = [args.time, args.status] + cphcols
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
169 cphdf = df[cutcphcols]
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
170 ucolcounts = colsdf.nunique(axis=0)
0
dd49a7040643 Initial commit
fubar
parents:
diff changeset
171 cph.fit(cphdf, duration_col=args.time, event_col=args.status)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
172 cph.print_summary()
1
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
173 for i, cov in enumerate(colsdf.columns):
2
dd5e65893cb8 add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents: 1
diff changeset
174 if ucolcounts[i] > 10: # a hack - assume categories are sparse - if not imaginary quintiles will have to do
1
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
175 v = pd.Series.tolist(cphdf[cov].quantile(QVALS))
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
176 vdt = df.dtypes[cov]
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
177 if vdt == 'int64':
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
178 v = trimlegend(v)
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
179 axp = cph.plot_partial_effects_on_outcome(cov, cmap='coolwarm', values=v)
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
180 axp.set_title('Cox-PH %s quintile partials: %s' % (cov,args.title))
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
181 figr = axp.get_figure()
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
182 oname = os.path.join(args.image_dir,'%s_CoxPH_%s.%s' % (args.title, cov, args.image_type))
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
183 figr.savefig(oname)
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
184 else:
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
185 v = pd.unique(cphdf[cov])
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
186 v = [str(x) for x in v]
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
187 try:
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
188 axp = cph.plot_partial_effects_on_outcome(cov, cmap='coolwarm', values=v)
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
189 axp.set_title('Cox-PH %s partials: %s' % (cov,args.title))
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
190 figr = axp.get_figure()
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
191 oname = os.path.join(args.image_dir,'%s_CoxPH_%s.%s' % (args.title, cov, args.image_type))
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
192 figr.savefig(oname)
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
193 except:
232b874046a7 Uploaded
fubar
parents: 0
diff changeset
194 pass
0
dd49a7040643 Initial commit
fubar
parents:
diff changeset
195 cphaxes = cph.check_assumptions(cphdf, p_value_threshold=0.01, show_plots=True)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
196 for i, ax in enumerate(cphaxes):
dd49a7040643 Initial commit
fubar
parents:
diff changeset
197 figr = ax[0].get_figure()
dd49a7040643 Initial commit
fubar
parents:
diff changeset
198 titl = figr._suptitle.get_text().replace(' ','_').replace("'","")
dd49a7040643 Initial commit
fubar
parents:
diff changeset
199 oname = os.path.join(args.image_dir,'CPH%s.%s' % (titl, args.image_type))
dd49a7040643 Initial commit
fubar
parents:
diff changeset
200 figr.savefig(oname)
dd49a7040643 Initial commit
fubar
parents:
diff changeset
201
dd49a7040643 Initial commit
fubar
parents:
diff changeset
202
dd49a7040643 Initial commit
fubar
parents:
diff changeset
203 #end raw]]></configfile>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
204 </configfiles>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
205 <inputs>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
206 <param name="input_tab" type="data" optional="false" label="Tabular input file for failure time testing." help="Must have a column with a measure of time and status (0,1) at observation." format="tabular" multiple="false"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
207 <param name="time" type="text" value="week" label="Name of column containing a time to observation" help="Use a column name from the file header if the data has one, or use one from the list supplied below, or use col1....colN otherwise to select the correct column"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
208 <param name="status" type="text" value="arrest" label="Status at observation. Typically 1=alive, 0=deceased for life-table observations" help="Use a column name from the header if the file has one, or use one from the list supplied below, or use col1....colN otherwise to select the correct column"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
209 <param name="CPHcovariatecolumnnames" type="text" value="prio,age,race,paro,mar,fin" label="Optional comma delimited column names to use as covariates in the Cox Proportional Hazards model" help="Leave blank for no Cox PH model tests "/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
210 <param name="title" type="text" value="KM and CPH in lifelines test" label="Title for this lifelines analysis" help="Special characters will probably be escaped so do not use them"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
211 <param name="header" type="text" value="" label="Optional comma delimited list of column names to use for this tabular file. Default is None when col1...coln will be used if no header row in the input data" help="The column names supplied for time, status and so on MUST match either this supplied list, or if none, the original file header if it exists, or col1...coln as the default of last resort."/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
212 <param name="group" type="text" value="race" label="Optional group column name for KM plot" help="If there are exactly 2 groups, a log-rank statistic will be generated as part of the Kaplan-Meier test."/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
213 <param name="image_type" type="select" label="Output format for all images" help="">
dd49a7040643 Initial commit
fubar
parents:
diff changeset
214 <option value="png">Portable Network Graphics .png format</option>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
215 <option value="jpg">JPEG</option>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
216 <option value="pdf">PDF</option>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
217 <option value="tiff">TIFF</option>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
218 </param>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
219 </inputs>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
220 <outputs>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
221 <collection name="image_dir" type="list" label="Images from $title on $input_tab.element_identifier">
dd49a7040643 Initial commit
fubar
parents:
diff changeset
222 <discover_datasets pattern="__name_and_ext__" directory="image_dir" visible="false"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
223 </collection>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
224 <data name="readme" format="txt" label="Lifelines_km_cph $title on $input_tab.element_identifier" hidden="false"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
225 </outputs>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
226 <tests>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
227 <test>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
228 <output_collection name="image_dir"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
229 <output name="readme" value="readme_sample" compare="sim_size" delta="1000"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
230 <param name="input_tab" value="input_tab_sample"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
231 <param name="time" value="week"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
232 <param name="status" value="arrest"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
233 <param name="CPHcovariatecolumnnames" value="prio,age,race,paro,mar,fin"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
234 <param name="title" value="KM and CPH in lifelines test"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
235 <param name="header" value=""/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
236 <param name="group" value="race"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
237 <param name="image_type" value="png"/>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
238 </test>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
239 </tests>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
240 <help><![CDATA[
dd49a7040643 Initial commit
fubar
parents:
diff changeset
241
dd49a7040643 Initial commit
fubar
parents:
diff changeset
242 This is a wrapper for some elementary life table analysis functions from the Lifelines package - see https://lifelines.readthedocs.io/en/latest for the full story
dd49a7040643 Initial commit
fubar
parents:
diff changeset
243
dd49a7040643 Initial commit
fubar
parents:
diff changeset
244
dd49a7040643 Initial commit
fubar
parents:
diff changeset
245
dd49a7040643 Initial commit
fubar
parents:
diff changeset
246 Given a Galaxy tabular dataset with suitable indicators for time and status at observation, this tool can perform some simple life-table analyses and produce some useful plots. Kaplan-Meier is the default. Cox Proportional Hazards model will be tested if covariates to include are provided.
dd49a7040643 Initial commit
fubar
parents:
diff changeset
247
dd49a7040643 Initial commit
fubar
parents:
diff changeset
248
dd49a7040643 Initial commit
fubar
parents:
diff changeset
249
dd49a7040643 Initial commit
fubar
parents:
diff changeset
250 1. Kaplan-Meier survival analysis - see https://lifelines.readthedocs.io/en/latest/Survival%20analysis%20with%20lifelines.html
dd49a7040643 Initial commit
fubar
parents:
diff changeset
251
dd49a7040643 Initial commit
fubar
parents:
diff changeset
252 This is always performed and a survival curve is plotted.
dd49a7040643 Initial commit
fubar
parents:
diff changeset
253
dd49a7040643 Initial commit
fubar
parents:
diff changeset
254 If there is an optional "group" column, the plot will show each group separately. If there are *exactly* two groups, a log-rank test for difference is performed and reported
dd49a7040643 Initial commit
fubar
parents:
diff changeset
255
dd49a7040643 Initial commit
fubar
parents:
diff changeset
256
dd49a7040643 Initial commit
fubar
parents:
diff changeset
257
dd49a7040643 Initial commit
fubar
parents:
diff changeset
258 2. The Cox Proportional Hazards model can be tested, if a comma separated list of covariate column names is supplied on the tool form.
dd49a7040643 Initial commit
fubar
parents:
diff changeset
259
dd49a7040643 Initial commit
fubar
parents:
diff changeset
260 These are used in as covariates.
dd49a7040643 Initial commit
fubar
parents:
diff changeset
261
dd49a7040643 Initial commit
fubar
parents:
diff changeset
262 Although not usually a real problem, some diagnostics and advice about the assumption of proportional hazards are are also provided as outputs - see https://lifelines.readthedocs.io/en/latest/Survival%20Regression.html
dd49a7040643 Initial commit
fubar
parents:
diff changeset
263
dd49a7040643 Initial commit
fubar
parents:
diff changeset
264
dd49a7040643 Initial commit
fubar
parents:
diff changeset
265
dd49a7040643 Initial commit
fubar
parents:
diff changeset
266 A big shout out to the lifelines authors - no R code needed - nice job, thanks!
dd49a7040643 Initial commit
fubar
parents:
diff changeset
267
dd49a7040643 Initial commit
fubar
parents:
diff changeset
268 ]]></help>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
269 <citations>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
270 <citation type="doi">10.1093/bioinformatics/bts573</citation>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
271 </citations>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
272 </tool>
dd49a7040643 Initial commit
fubar
parents:
diff changeset
273