diff formatter.py @ 3:574c6331e9db draft

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 38a5028a7abe99794086e9b1374ab4bb8bfa68de
author recetox
date Wed, 21 Sep 2022 15:29:51 +0000
parents 60f34912b3de
children 966b4134ad12
line wrap: on
line diff
--- a/formatter.py	Thu Sep 08 14:49:19 2022 +0000
+++ b/formatter.py	Wed Sep 21 15:29:51 2022 +0000
@@ -1,5 +1,5 @@
 import click
-from pandas import DataFrame, read_csv
+from pandas import DataFrame, read_csv, to_numeric
 
 
 def create_long_table(data: DataFrame, value_id: str) -> DataFrame:
@@ -73,8 +73,8 @@
     Returns:
         DataFrame: Joined dataframe on compounds containing scores an matches in long format.
     """
-    matches = read_csv(matches_filename, sep=None, index_col=0)
-    scores = read_csv(scores_filename, sep=None, index_col=0)
+    matches = read_csv(matches_filename, sep="\t", index_col=0, header=0).apply(to_numeric)
+    scores = read_csv(scores_filename, sep="\t", index_col=0, header=0).apply(to_numeric)
 
     scores_long = create_long_table(scores, 'score')
     matches_long = create_long_table(matches, 'matches')
@@ -113,11 +113,8 @@
 
 @cli.resultcallback()
 def write_output(result: DataFrame, scores_filename, matches_filename, output_filename):
-    input_file = read_csv(scores_filename, sep=None, iterator=True)
-    sep = input_file._engine.data.dialect.delimiter
-
     result = result.reset_index().rename(columns={'level_0': 'query', 'compound': 'reference'})
-    result.to_csv(output_filename, sep=sep, index=False)
+    result.to_csv(output_filename, sep="\t", index=False)
 
 
 if __name__ == '__main__':