annotate generateMFI.py @ 1:91e856e5ec7a draft default tip

"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
author azomics
date Wed, 22 Jul 2020 15:41:56 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
1 #!/usr/bin/env python
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
2 ######################################################################
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
3 # Copyright (c) 2016 Northrop Grumman.
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
4 # All rights reserved.
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
5 ######################################################################
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
6 import sys
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
7 from argparse import ArgumentParser
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
8 import pandas as pd
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
9 from scipy.stats import gmean
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
10
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
11
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
12 def generate_MFI(input_file_name, output_file_name, mfi_calc):
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
13 flock_df = pd.read_table(input_file_name)
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
14 if mfi_calc == "mfi":
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
15 MFIs = flock_df.groupby('Population').mean().round(decimals=2)
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
16 elif mfi_calc == "gmfi":
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
17 MFIs = flock_df.groupby('Population').agg(lambda x: gmean(list(x))).round(decimals=2)
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
18 else:
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
19 MFIs = flock_df.groupby('Population').median().round(decimals=2)
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
20
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
21 with open(output_file_name, "w") as outf:
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
22 MFIs.to_csv(outf, sep="\t", float_format='%.0f')
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
23 return
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
24
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
25
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
26 if __name__ == "__main__":
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
27 parser = ArgumentParser(
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
28 prog="removeColumns",
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
29 description="Generate MFI from Flow Result file.")
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
30
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
31 parser.add_argument(
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
32 '-i',
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
33 dest="input_file",
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
34 required=True,
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
35 help="File location for the Flow Result file.")
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
36
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
37 parser.add_argument(
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
38 '-M',
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
39 dest="mfi_calc",
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
40 required=True,
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
41 help="what to calculate for centroids.")
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
42
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
43 parser.add_argument(
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
44 '-o',
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
45 dest="output_file",
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
46 required=True,
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
47 help="File location for the MFI output file.")
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
48
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
49 args = parser.parse_args()
91e856e5ec7a "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/generate_mfi commit a1f464ea7fe4a5d1b71664ef924544010036522a"
azomics
parents:
diff changeset
50 generate_MFI(args.input_file, args.output_file, args.mfi_calc)