Mercurial > repos > bgruening > flexynesis_utils
annotate convert.py @ 3:f413f828ef30 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:50:03 +0000 | 
| parents | e5ecfffcfe45 | 
| children | 
| rev | line source | 
|---|---|
| 2 
e5ecfffcfe45
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
 bgruening parents: diff
changeset | 1 #!/usr/bin/env python | 
| 
e5ecfffcfe45
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
 bgruening parents: diff
changeset | 2 | 
| 
e5ecfffcfe45
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
 bgruening parents: diff
changeset | 3 import sys | 
| 
e5ecfffcfe45
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
 bgruening parents: diff
changeset | 4 | 
| 
e5ecfffcfe45
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
 bgruening parents: diff
changeset | 5 import pandas as pd | 
| 
e5ecfffcfe45
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
 bgruening parents: diff
changeset | 6 | 
| 
e5ecfffcfe45
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
 bgruening parents: diff
changeset | 7 | 
| 
e5ecfffcfe45
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): | 
| 
e5ecfffcfe45
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""" | 
| 
e5ecfffcfe45
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 
f413f828ef30
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 6b520305ec30e6dc37eba92c67a5368cea0fc5ad
 bgruening parents: 
2diff
changeset | 11 if data.columns[0] == '' or data.columns[0].startswith('Unnamed:'): | 
| 
f413f828ef30
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 6b520305ec30e6dc37eba92c67a5368cea0fc5ad
 bgruening parents: 
2diff
changeset | 12 data.columns = ['ID'] + list(data.columns[1:]) | 
| 2 
e5ecfffcfe45
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) | 
| 
e5ecfffcfe45
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
 bgruening parents: diff
changeset | 14 | 
| 
e5ecfffcfe45
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
 bgruening parents: diff
changeset | 15 | 
| 
e5ecfffcfe45
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): | 
| 
e5ecfffcfe45
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)""" | 
| 
e5ecfffcfe45
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 
f413f828ef30
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 6b520305ec30e6dc37eba92c67a5368cea0fc5ad
 bgruening parents: 
2diff
changeset | 19 if data.columns[0] == '' or data.columns[0].startswith('Unnamed:'): | 
| 
f413f828ef30
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 6b520305ec30e6dc37eba92c67a5368cea0fc5ad
 bgruening parents: 
2diff
changeset | 20 data.columns = ['ID'] + list(data.columns[1:]) | 
| 2 
e5ecfffcfe45
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) | 
| 
e5ecfffcfe45
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
 bgruening parents: diff
changeset | 22 | 
| 
e5ecfffcfe45
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
 bgruening parents: diff
changeset | 23 | 
| 
e5ecfffcfe45
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
 bgruening parents: diff
changeset | 24 if __name__ == "__main__": | 
| 
e5ecfffcfe45
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] | 
| 
e5ecfffcfe45
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] | 
| 
e5ecfffcfe45
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
 bgruening parents: diff
changeset | 27 | 
| 
e5ecfffcfe45
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'): | 
| 
e5ecfffcfe45
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) | 
| 
e5ecfffcfe45
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
 bgruening parents: diff
changeset | 30 else: | 
| 
e5ecfffcfe45
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) | 
