Mercurial > repos > bgruening > flexynesis
annotate index_to_name.py @ 7:9450286c42ab draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
author | bgruening |
---|---|
date | Fri, 04 Jul 2025 14:58:37 +0000 |
parents | |
children | 9c91d13827ef |
rev | line source |
---|---|
7
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
1 #!/usr/bin/env python |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
2 |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
3 import sys |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
4 |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
5 import pandas as pd |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
6 |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
7 |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
8 def get_column_name(file_path, index): |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
9 """ |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
10 Get the column name based on an index from a tabular file. |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
11 """ |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
12 data = pd.read_csv(file_path, sep=",") |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
13 index = index - 1 # Convert to zero-based index |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
14 if index < 0 or index >= len(data.columns): |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
15 print(f"Error: Index {index+1} is out of range. File has {len(data.columns)} columns (1-{len(data.columns)}).") |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
16 return None |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
17 return data.columns[index].strip() |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
18 |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
19 |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
20 if __name__ == "__main__": |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
21 |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
22 file_path = sys.argv[1] |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
23 index = int(sys.argv[2]) |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
24 |
9450286c42ab
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
bgruening
parents:
diff
changeset
|
25 print(get_column_name(file_path, index)) |