Mercurial > repos > immport-devteam > flowclr_summary
annotate flowclrstats.py @ 1:7a889f2f2e15 draft default tip
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
author | azomics |
---|---|
date | Mon, 22 Jun 2020 19:55:57 -0400 |
parents | |
children |
rev | line source |
---|---|
1
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
1 #!/usr/bin/env python |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
2 |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
3 ###################################################################### |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
4 # Copyright (c) 2016 Northrop Grumman. |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
5 # All rights reserved. |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
6 ###################################################################### |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
7 |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
8 from __future__ import print_function |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
9 from argparse import ArgumentParser |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
10 import pandas as pd |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
11 |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
12 |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
13 def get_FLOCK_stats(input_file, output_file, out_file2): |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
14 df = pd.read_table(input_file) |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
15 summary = df.groupby('Population').describe().round(1) |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
16 counts = df['Population'].value_counts() |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
17 percent = (df['Population'].value_counts(normalize=True) * 100).round(decimals=2) |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
18 tot_count = len(df['Population']) |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
19 |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
20 to_rm = summary.loc(axis=0)[:, ['count']].index.tolist() |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
21 df1 = summary[~summary.index.isin(to_rm)] |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
22 df1.to_csv(out_file2, sep="\t") |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
23 |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
24 with open(output_file, "w") as outf: |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
25 outf.write("Population\tCount\tPercentage\n") |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
26 for pops in set(df.Population): |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
27 outf.write("\t".join([str(pops), str(counts.loc[pops]), str(percent.loc[pops])]) + "\n") |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
28 outf.write("Total\t" + str(tot_count) + "\t \n") |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
29 return |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
30 |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
31 |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
32 if __name__ == '__main__': |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
33 parser = ArgumentParser( |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
34 prog="flowstats", |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
35 description="Gets statistics on FLOCK run") |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
36 |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
37 parser.add_argument( |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
38 '-i', |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
39 dest="input_file", |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
40 required=True, |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
41 help="File locations for flow clr file.") |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
42 |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
43 parser.add_argument( |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
44 '-o', |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
45 dest="out_file", |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
46 required=True, |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
47 help="Path to the directory for the output file.") |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
48 |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
49 parser.add_argument( |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
50 '-p', |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
51 dest="out_file2", |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
52 required=True, |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
53 help="Path to the directory for the output file.") |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
54 args = parser.parse_args() |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
55 |
7a889f2f2e15
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flowclr_summary commit ce895377ed593ace77016bd019a7998e13e470cc"
azomics
parents:
diff
changeset
|
56 get_FLOCK_stats(args.input_file, args.out_file, args.out_file2) |