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