Mercurial > repos > bgruening > flexynesis_cbioportal_import
annotate convert.py @ 8:461b8e2d79d5 draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit bcee55468e70cd025cc5359bef5e9991e893eca9
| author | bgruening |
|---|---|
| date | Thu, 16 Oct 2025 20:15:31 +0000 |
| parents | 693011647a67 |
| children |
| rev | line source |
|---|---|
|
6
3f7481deaff1
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
1 #!/usr/bin/env python |
|
3f7481deaff1
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
2 |
|
3f7481deaff1
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
3 import sys |
|
3f7481deaff1
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
4 |
|
3f7481deaff1
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
5 import pandas as pd |
|
3f7481deaff1
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
6 |
|
3f7481deaff1
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
7 |
|
3f7481deaff1
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): |
|
3f7481deaff1
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""" |
|
3f7481deaff1
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") |
|
7
693011647a67
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 6b520305ec30e6dc37eba92c67a5368cea0fc5ad
bgruening
parents:
6
diff
changeset
|
11 if data.columns[0] == '' or data.columns[0].startswith('Unnamed:'): |
|
693011647a67
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 6b520305ec30e6dc37eba92c67a5368cea0fc5ad
bgruening
parents:
6
diff
changeset
|
12 data.columns = ['ID'] + list(data.columns[1:]) |
|
6
3f7481deaff1
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) |
|
3f7481deaff1
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
14 |
|
3f7481deaff1
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
15 |
|
3f7481deaff1
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): |
|
3f7481deaff1
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)""" |
|
3f7481deaff1
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) |
|
7
693011647a67
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 6b520305ec30e6dc37eba92c67a5368cea0fc5ad
bgruening
parents:
6
diff
changeset
|
19 if data.columns[0] == '' or data.columns[0].startswith('Unnamed:'): |
|
693011647a67
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 6b520305ec30e6dc37eba92c67a5368cea0fc5ad
bgruening
parents:
6
diff
changeset
|
20 data.columns = ['ID'] + list(data.columns[1:]) |
|
6
3f7481deaff1
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) |
|
3f7481deaff1
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
22 |
|
3f7481deaff1
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
23 |
|
3f7481deaff1
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
24 if __name__ == "__main__": |
|
3f7481deaff1
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] |
|
3f7481deaff1
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] |
|
3f7481deaff1
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
27 |
|
3f7481deaff1
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'): |
|
3f7481deaff1
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) |
|
3f7481deaff1
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
30 else: |
|
3f7481deaff1
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) |
