Mercurial > repos > immport-devteam > generate_mfi
comparison 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 |
comparison
equal
deleted
inserted
replaced
0:2f6dcda6e74e | 1:91e856e5ec7a |
---|---|
1 #!/usr/bin/env python | |
2 ###################################################################### | |
3 # Copyright (c) 2016 Northrop Grumman. | |
4 # All rights reserved. | |
5 ###################################################################### | |
6 import sys | |
7 from argparse import ArgumentParser | |
8 import pandas as pd | |
9 from scipy.stats import gmean | |
10 | |
11 | |
12 def generate_MFI(input_file_name, output_file_name, mfi_calc): | |
13 flock_df = pd.read_table(input_file_name) | |
14 if mfi_calc == "mfi": | |
15 MFIs = flock_df.groupby('Population').mean().round(decimals=2) | |
16 elif mfi_calc == "gmfi": | |
17 MFIs = flock_df.groupby('Population').agg(lambda x: gmean(list(x))).round(decimals=2) | |
18 else: | |
19 MFIs = flock_df.groupby('Population').median().round(decimals=2) | |
20 | |
21 with open(output_file_name, "w") as outf: | |
22 MFIs.to_csv(outf, sep="\t", float_format='%.0f') | |
23 return | |
24 | |
25 | |
26 if __name__ == "__main__": | |
27 parser = ArgumentParser( | |
28 prog="removeColumns", | |
29 description="Generate MFI from Flow Result file.") | |
30 | |
31 parser.add_argument( | |
32 '-i', | |
33 dest="input_file", | |
34 required=True, | |
35 help="File location for the Flow Result file.") | |
36 | |
37 parser.add_argument( | |
38 '-M', | |
39 dest="mfi_calc", | |
40 required=True, | |
41 help="what to calculate for centroids.") | |
42 | |
43 parser.add_argument( | |
44 '-o', | |
45 dest="output_file", | |
46 required=True, | |
47 help="File location for the MFI output file.") | |
48 | |
49 args = parser.parse_args() | |
50 generate_MFI(args.input_file, args.output_file, args.mfi_calc) |