comparison formatter.py @ 1:364976b9aba6 draft

"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 67040e686204e86c07ec46ca90129e50e40eb737"
author recetox
date Tue, 11 Jan 2022 15:13:57 +0000
parents 0a08bed94964
children 4ca9807c56e6
comparison
equal deleted inserted replaced
0:0a08bed94964 1:364976b9aba6
71 matches_filename (str): Path to matches table. 71 matches_filename (str): Path to matches table.
72 72
73 Returns: 73 Returns:
74 DataFrame: Joined dataframe on compounds containing scores an matches in long format. 74 DataFrame: Joined dataframe on compounds containing scores an matches in long format.
75 """ 75 """
76 matches = read_csv(matches_filename, sep='\t', index_col=0) 76 matches = read_csv(matches_filename, sep=None, index_col=0)
77 scores = read_csv(scores_filename, sep='\t', index_col=0) 77 scores = read_csv(scores_filename, sep=None, index_col=0)
78 78
79 scores_long = create_long_table(scores, 'score') 79 scores_long = create_long_table(scores, 'score')
80 matches_long = create_long_table(matches, 'matches') 80 matches_long = create_long_table(matches, 'matches')
81 81
82 combined = join_df(matches_long, scores_long, on=['compound'], how='inner') 82 combined = join_df(matches_long, scores_long, on=['compound'], how='inner')
111 return result 111 return result
112 112
113 113
114 @cli.resultcallback() 114 @cli.resultcallback()
115 def write_output(result: DataFrame, scores_filename, matches_filename, output_filename): 115 def write_output(result: DataFrame, scores_filename, matches_filename, output_filename):
116 input_file = read_csv(scores_filename, sep=None, iterator=True)
117 sep = input_file._engine.data.dialect.delimiter
118
116 result = result.reset_index().rename(columns={'level_0': 'query', 'compound': 'reference'}) 119 result = result.reset_index().rename(columns={'level_0': 'query', 'compound': 'reference'})
117 result.to_csv(output_filename, sep="\t", index=False) 120 result.to_csv(output_filename, sep=sep, index=False)
118 121
119 122
120 if __name__ == '__main__': 123 if __name__ == '__main__':
121 cli(obj={}) 124 cli(obj={})