comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:c6c0f6027e34
1 #!/usr/bin/env python
2
3 import argparse
4 import sys
5
6 import pandas as pd
7
8
9 parser = argparse.ArgumentParser()
10 parser.add_argument("--dataframe", help="Parquet dataframe")
11 parser.add_argument('output')
12 args = parser.parse_args()
13
14
15 def main():
16 featureTable = pd.read_parquet(args.dataframe)
17
18 # Concatenate "mz" and "rt" columns; select relevant columns; pivot the table
19 featureTable["mz_rt"] = featureTable["mz"].astype(str) + "_" + featureTable["rt"].astype(str)
20 featureTable = featureTable[["sample", "mz_rt", "sample_intensity"]]
21 featureTable = pd.pivot_table(featureTable, columns="mz_rt", index="sample", values="sample_intensity")
22
23 try:
24 featureTable.to_csv(args.output, sep=',')
25 msg = f"Dataset of {len(featureTable)} samples is converted to a feature-by-sample table"
26 print(msg, file=sys.stdout)
27 return 0
28 except Exception:
29 print("Could not write the data", file=sys.stdout)
30 return 1
31
32
33 if __name__ == "__main__":
34 main()