diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/generateMFI.py	Wed Jul 22 15:41:56 2020 -0400
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+######################################################################
+#                  Copyright (c) 2016 Northrop Grumman.
+#                          All rights reserved.
+######################################################################
+import sys
+from argparse import ArgumentParser
+import pandas as pd
+from scipy.stats import gmean
+
+
+def generate_MFI(input_file_name, output_file_name, mfi_calc):
+    flock_df = pd.read_table(input_file_name)
+    if mfi_calc == "mfi":
+        MFIs = flock_df.groupby('Population').mean().round(decimals=2)
+    elif mfi_calc == "gmfi":
+        MFIs = flock_df.groupby('Population').agg(lambda x: gmean(list(x))).round(decimals=2)
+    else:
+        MFIs = flock_df.groupby('Population').median().round(decimals=2)
+
+    with open(output_file_name, "w") as outf:
+        MFIs.to_csv(outf, sep="\t", float_format='%.0f')
+    return
+
+
+if __name__ == "__main__":
+    parser = ArgumentParser(
+             prog="removeColumns",
+             description="Generate MFI from Flow Result file.")
+
+    parser.add_argument(
+            '-i',
+            dest="input_file",
+            required=True,
+            help="File location for the Flow Result file.")
+
+    parser.add_argument(
+            '-M',
+            dest="mfi_calc",
+            required=True,
+            help="what to calculate for centroids.")
+
+    parser.add_argument(
+            '-o',
+            dest="output_file",
+            required=True,
+            help="File location for the MFI output file.")
+
+    args = parser.parse_args()
+    generate_MFI(args.input_file, args.output_file, args.mfi_calc)