annotate collapse_pops.py @ 1:a3ae90eb1232 draft default tip

"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
author azomics
date Mon, 22 Jun 2020 16:34:35 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
1 #!/usr/bin/env python
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
2 ######################################################################
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
3 # Copyright (c) 2016 Northrop Grumman.
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
4 # All rights reserved.
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
5 ######################################################################
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
6
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
7 from __future__ import print_function
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
8 import sys
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
9 import pandas as pd
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
10
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
11 from argparse import ArgumentParser
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
12
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
13
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
14 def is_int(s):
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
15 try:
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
16 int(s)
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
17 return True
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
18 except ValueError:
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
19 return False
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
20
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
21
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
22 def collapse_populations(in_file, out_file, populations, collapse_in, exit_code):
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
23 df = pd.read_table(in_file, dtype={'Population': object})
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
24 df['new_population'] = df.Population
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
25
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
26 for i, sets_pop in enumerate(populations):
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
27 df.loc[df['Population'].isin(sets_pop), ['new_population']] = collapse_in[i]
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
28
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
29 df.Population = df.new_population
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
30 df.drop(['new_population'], inplace=True, axis=1)
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
31
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
32 df.to_csv(out_file, sep="\t", index=False)
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
33
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
34 sys.exit(exit_code)
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
35
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
36
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
37 if __name__ == "__main__":
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
38 parser = ArgumentParser(
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
39 prog="ExtractPop",
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
40 description="Extract events associated to given population numbers.")
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
41
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
42 parser.add_argument(
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
43 '-i',
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
44 dest="input_file",
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
45 required=True,
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
46 help="File location for the text file.")
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
47
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
48 parser.add_argument(
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
49 '-p',
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
50 dest="pops",
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
51 required=True,
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
52 action='append',
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
53 help="List of populations to collapse.")
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
54
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
55 parser.add_argument(
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
56 '-o',
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
57 dest="output_file",
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
58 required=True,
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
59 help="Name of the output file.")
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
60
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
61 parser.add_argument(
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
62 '-c',
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
63 dest="collapse_pop",
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
64 required=True,
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
65 action='append',
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
66 help="What to collapse the populations in.")
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
67
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
68 args = parser.parse_args()
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
69
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
70 # check populations
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
71 default_values_pop = ["i.e.:2,3,11,25", "default", "Default"]
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
72 default_values_col = ["i.e.:4", "default", "Default"]
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
73 pops = [p for p in args.pops]
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
74 popc = [pc.strip() for pc in args.collapse_pop]
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
75 exit_code = 0
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
76 # Check sets of pops to collapse
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
77 populations = []
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
78 total_pops = []
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
79 for pop_set in pops:
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
80 if pop_set not in default_values_pop:
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
81 tmp_pops = pop_set.split(",")
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
82 for popn in tmp_pops:
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
83 if not is_int(popn):
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
84 sys.exit(6)
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
85 else:
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
86 total_pops.append(int(popn))
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
87 strp_pops = [p.strip() for p in tmp_pops]
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
88 populations.append(strp_pops)
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
89 else:
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
90 sys.exit(4)
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
91 if len(total_pops) != len(set(total_pops)):
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
92 sys.exit(7)
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
93 # Check pops to collapse in
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
94 collapse_in = []
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
95 for col_pop in popc:
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
96 if col_pop not in default_values_col:
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
97 if not is_int(col_pop):
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
98 sys.exit(6)
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
99 else:
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
100 if int(col_pop) > 40:
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
101 exit_code = 2
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
102 collapse_in.append(col_pop)
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
103 else:
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
104 sys.exit(6)
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
105 if len(collapse_in) != len(set(collapse_in)):
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
106 exit_code += 3
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
107
a3ae90eb1232 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/collapse_pop commit 1e75b0df5680c0cdd8b2b3e5d4c1f8077b430944"
azomics
parents:
diff changeset
108 collapse_populations(args.input_file, args.output_file, populations, collapse_in, exit_code)