annotate model_prediction.py @ 15:b7d104ede67e draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
author bgruening
date Sun, 05 Nov 2023 15:41:30 +0000
parents 364234f65507
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
1 import argparse
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
2 import json
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
3 import warnings
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
4
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
5 import numpy as np
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
6 import pandas as pd
9
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
7 from galaxy_ml.model_persist import load_model_from_h5
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
8 from galaxy_ml.utils import (clean_params, get_module, read_columns,
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
9 try_get_attr)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
10 from scipy.io import mmread
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
11
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
12 N_JOBS = int(__import__("os").environ.get("GALAXY_SLOTS", 1))
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
13
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
14
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
15 def main(
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
16 inputs,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
17 infile_estimator,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
18 outfile_predict,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
19 infile1=None,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
20 fasta_path=None,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
21 ref_seq=None,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
22 vcf_path=None,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
23 ):
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
24 """
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
25 Parameter
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
26 ---------
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
27 inputs : str
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
28 File path to galaxy tool parameter
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
29
9
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
30 infile_estimator : str
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
31 File path to trained estimator input
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
32
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
33 outfile_predict : str
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
34 File path to save the prediction results, tabular
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
35
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
36 infile1 : str
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
37 File path to dataset containing features
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
38
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
39 fasta_path : str
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
40 File path to dataset containing fasta file
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
41
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
42 ref_seq : str
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
43 File path to dataset containing the reference genome sequence.
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
44
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
45 vcf_path : str
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
46 File path to dataset containing variants info.
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
47 """
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
48 warnings.filterwarnings("ignore")
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
49
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
50 with open(inputs, "r") as param_handler:
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
51 params = json.load(param_handler)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
52
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
53 # load model
9
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
54 estimator = load_model_from_h5(infile_estimator)
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
55 estimator = clean_params(estimator)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
56
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
57 # handle data input
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
58 input_type = params["input_options"]["selected_input"]
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
59 # tabular input
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
60 if input_type == "tabular":
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
61 header = "infer" if params["input_options"]["header1"] else None
5
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
62 column_option = params["input_options"]["column_selector_options_1"][
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
63 "selected_column_selector_option"
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
64 ]
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
65 if column_option in [
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
66 "by_index_number",
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
67 "all_but_by_index_number",
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
68 "by_header_name",
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
69 "all_but_by_header_name",
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
70 ]:
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
71 c = params["input_options"]["column_selector_options_1"]["col1"]
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
72 else:
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
73 c = None
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
74
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
75 df = pd.read_csv(infile1, sep="\t", header=header, parse_dates=True)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
76
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
77 X = read_columns(df, c=c, c_option=column_option).astype(float)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
78
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
79 if params["method"] == "predict":
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
80 preds = estimator.predict(X)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
81 else:
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
82 preds = estimator.predict_proba(X)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
83
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
84 # sparse input
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
85 elif input_type == "sparse":
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
86 X = mmread(open(infile1, "r"))
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
87 if params["method"] == "predict":
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
88 preds = estimator.predict(X)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
89 else:
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
90 preds = estimator.predict_proba(X)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
91
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
92 # fasta input
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
93 elif input_type == "seq_fasta":
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
94 if not hasattr(estimator, "data_batch_generator"):
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
95 raise ValueError(
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
96 "To do prediction on sequences in fasta input, "
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
97 "the estimator must be a `KerasGBatchClassifier`"
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
98 "equipped with data_batch_generator!"
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
99 )
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
100 pyfaidx = get_module("pyfaidx")
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
101 sequences = pyfaidx.Fasta(fasta_path)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
102 n_seqs = len(sequences.keys())
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
103 X = np.arange(n_seqs)[:, np.newaxis]
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
104 seq_length = estimator.data_batch_generator.seq_length
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
105 batch_size = getattr(estimator, "batch_size", 32)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
106 steps = (n_seqs + batch_size - 1) // batch_size
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
107
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
108 seq_type = params["input_options"]["seq_type"]
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
109 klass = try_get_attr("galaxy_ml.preprocessors", seq_type)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
110
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
111 pred_data_generator = klass(fasta_path, seq_length=seq_length)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
112
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
113 if params["method"] == "predict":
5
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
114 preds = estimator.predict(
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
115 X, data_generator=pred_data_generator, steps=steps
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
116 )
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
117 else:
5
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
118 preds = estimator.predict_proba(
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
119 X, data_generator=pred_data_generator, steps=steps
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
120 )
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
121
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
122 # vcf input
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
123 elif input_type == "variant_effect":
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
124 klass = try_get_attr("galaxy_ml.preprocessors", "GenomicVariantBatchGenerator")
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
125
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
126 options = params["input_options"]
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
127 options.pop("selected_input")
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
128 if options["blacklist_regions"] == "none":
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
129 options["blacklist_regions"] = None
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
130
5
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
131 pred_data_generator = klass(
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
132 ref_genome_path=ref_seq, vcf_path=vcf_path, **options
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
133 )
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
134
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
135 pred_data_generator.set_processing_attrs()
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
136
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
137 variants = pred_data_generator.variants
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
138
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
139 # predict 1600 sample at once then write to file
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
140 gen_flow = pred_data_generator.flow(batch_size=1600)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
141
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
142 file_writer = open(outfile_predict, "w")
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
143 header_row = "\t".join(["chrom", "pos", "name", "ref", "alt", "strand"])
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
144 file_writer.write(header_row)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
145 header_done = False
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
146
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
147 steps_done = 0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
148
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
149 # TODO: multiple threading
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
150 try:
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
151 while steps_done < len(gen_flow):
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
152 index_array = next(gen_flow.index_generator)
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
153 batch_X = gen_flow._get_batches_of_transformed_samples(index_array)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
154
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
155 if params["method"] == "predict":
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
156 batch_preds = estimator.predict(
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
157 batch_X,
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
158 # The presence of `pred_data_generator` below is to
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
159 # override model carrying data_generator if there
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
160 # is any.
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
161 data_generator=pred_data_generator,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
162 )
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
163 else:
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
164 batch_preds = estimator.predict_proba(
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
165 batch_X,
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
166 # The presence of `pred_data_generator` below is to
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
167 # override model carrying data_generator if there
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
168 # is any.
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
169 data_generator=pred_data_generator,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
170 )
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
171
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
172 if batch_preds.ndim == 1:
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
173 batch_preds = batch_preds[:, np.newaxis]
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
174
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
175 batch_meta = variants[index_array]
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
176 batch_out = np.column_stack([batch_meta, batch_preds])
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
177
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
178 if not header_done:
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
179 heads = np.arange(batch_preds.shape[-1]).astype(str)
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
180 heads_str = "\t".join(heads)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
181 file_writer.write("\t%s\n" % heads_str)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
182 header_done = True
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
183
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
184 for row in batch_out:
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
185 row_str = "\t".join(row)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
186 file_writer.write("%s\n" % row_str)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
187
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
188 steps_done += 1
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
189
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
190 finally:
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
191 file_writer.close()
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
192 # TODO: make api `pred_data_generator.close()`
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
193 pred_data_generator.close()
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
194 return 0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
195 # end input
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
196
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
197 # output
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
198 if len(preds.shape) == 1:
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
199 rval = pd.DataFrame(preds, columns=["Predicted"])
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
200 else:
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
201 rval = pd.DataFrame(preds)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
202
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
203 rval.to_csv(outfile_predict, sep="\t", header=True, index=False)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
204
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
205
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
206 if __name__ == "__main__":
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
207 aparser = argparse.ArgumentParser()
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
208 aparser.add_argument("-i", "--inputs", dest="inputs", required=True)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
209 aparser.add_argument("-e", "--infile_estimator", dest="infile_estimator")
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
210 aparser.add_argument("-X", "--infile1", dest="infile1")
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
211 aparser.add_argument("-O", "--outfile_predict", dest="outfile_predict")
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
212 aparser.add_argument("-f", "--fasta_path", dest="fasta_path")
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
213 aparser.add_argument("-r", "--ref_seq", dest="ref_seq")
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
214 aparser.add_argument("-v", "--vcf_path", dest="vcf_path")
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
215 args = aparser.parse_args()
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
216
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
217 main(
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
218 args.inputs,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
219 args.infile_estimator,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
220 args.outfile_predict,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
221 infile1=args.infile1,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
222 fasta_path=args.fasta_path,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
223 ref_seq=args.ref_seq,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
224 vcf_path=args.vcf_path,
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
225 )