Mercurial > repos > recetox > aplcms_to_ramclustr_converter
annotate aplcms_to_ramclustr_converter.py @ 0:c6c0f6027e34 draft default tip
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
author | recetox |
---|---|
date | Tue, 22 Mar 2022 16:06:28 +0000 |
parents | |
children |
rev | line source |
---|---|
0
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
1 #!/usr/bin/env python |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
2 |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
3 import argparse |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
4 import sys |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
5 |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
6 import pandas as pd |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
7 |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
8 |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
9 parser = argparse.ArgumentParser() |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
10 parser.add_argument("--dataframe", help="Parquet dataframe") |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
11 parser.add_argument('output') |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
12 args = parser.parse_args() |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
13 |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
14 |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
15 def main(): |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
16 featureTable = pd.read_parquet(args.dataframe) |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
17 |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
18 # Concatenate "mz" and "rt" columns; select relevant columns; pivot the table |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
19 featureTable["mz_rt"] = featureTable["mz"].astype(str) + "_" + featureTable["rt"].astype(str) |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
20 featureTable = featureTable[["sample", "mz_rt", "sample_intensity"]] |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
21 featureTable = pd.pivot_table(featureTable, columns="mz_rt", index="sample", values="sample_intensity") |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
22 |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
23 try: |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
24 featureTable.to_csv(args.output, sep=',') |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
25 msg = f"Dataset of {len(featureTable)} samples is converted to a feature-by-sample table" |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
26 print(msg, file=sys.stdout) |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
27 return 0 |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
28 except Exception: |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
29 print("Could not write the data", file=sys.stdout) |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
30 return 1 |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
31 |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
32 |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
33 if __name__ == "__main__": |
c6c0f6027e34
"planemo upload for repository https://github.com/RECETOX/galaxytools/tools/aplcms_to_ramclustr_converter/ commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
recetox
parents:
diff
changeset
|
34 main() |