annotate convert.py @ 3:52b6f2ac38c7 draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 6b520305ec30e6dc37eba92c67a5368cea0fc5ad
author bgruening
date Wed, 23 Jul 2025 07:49:52 +0000
parents 3c5d82bf6e8a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
1 #!/usr/bin/env python
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
2
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
3 import sys
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
4
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
5 import pandas as pd
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
6
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
7
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
8 def tabular_to_csv(tabular_file, csv_file):
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
9 """Convert tabular (TSV) to CSV"""
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
10 data = pd.read_csv(tabular_file, sep="\t")
3
52b6f2ac38c7 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 6b520305ec30e6dc37eba92c67a5368cea0fc5ad
bgruening
parents: 2
diff changeset
11 if data.columns[0] == '' or data.columns[0].startswith('Unnamed:'):
52b6f2ac38c7 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 6b520305ec30e6dc37eba92c67a5368cea0fc5ad
bgruening
parents: 2
diff changeset
12 data.columns = ['ID'] + list(data.columns[1:])
2
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
13 data.to_csv(csv_file, index=False)
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
14
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
15
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
16 def csv_to_tabular(csv_file, tabular_file):
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
17 """Convert CSV to tabular (TSV)"""
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
18 data = pd.read_csv(csv_file)
3
52b6f2ac38c7 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 6b520305ec30e6dc37eba92c67a5368cea0fc5ad
bgruening
parents: 2
diff changeset
19 if data.columns[0] == '' or data.columns[0].startswith('Unnamed:'):
52b6f2ac38c7 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 6b520305ec30e6dc37eba92c67a5368cea0fc5ad
bgruening
parents: 2
diff changeset
20 data.columns = ['ID'] + list(data.columns[1:])
2
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
21 data.to_csv(tabular_file, sep="\t", index=False)
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
22
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
23
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
24 if __name__ == "__main__":
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
25 input_file = sys.argv[1]
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
26 output_file = sys.argv[2]
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
27
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
28 if input_file.endswith('.csv'):
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
29 csv_to_tabular(input_file, output_file)
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
30 else:
3c5d82bf6e8a planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff changeset
31 tabular_to_csv(input_file, output_file)