Mercurial > repos > galaxyp > fragpipe
comparison generate_manifest.py @ 8:012191b79fda draft default tip
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
author | galaxyp |
---|---|
date | Fri, 17 Oct 2025 16:22:03 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7:b4f6df8fa89b | 8:012191b79fda |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 # | |
4 # Generates a FragPipe Manifest file. | |
5 # | |
6 | |
7 import argparse | |
8 import csv | |
9 | |
10 # The three columns for each scanfile are "Experiment, Bioreplicate, and Data type | |
11 column_types = ('exp', 'bio', 'type') | |
12 output_filename = 'fp.manifest' | |
13 | |
14 | |
15 # Add column values to a list of rows for each scan file. | |
16 def add_column(column_type, args, rows): | |
17 nfiles = len(args.scanfiles) | |
18 | |
19 # Each scan file is numbered 1 through n in column | |
20 if getattr(args, f'{column_type}_consec'): | |
21 vals = range(1, nfiles + 1) | |
22 | |
23 # All scan files have same value in column | |
24 elif getattr(args, f'{column_type}_assign_all'): | |
25 vals = [getattr(args, f'{column_type}_assign_all')] * nfiles | |
26 | |
27 # Values are provided for scan files in a comma-delimited list | |
28 elif getattr(args, f'{column_type}_col'): | |
29 vals = getattr(args, f'{column_type}_col').split(',') | |
30 if len(vals) != nfiles: | |
31 raise ValueError((f'Incorrect number of values entered for column {column_type}. ' | |
32 'Exactly one value must be entered for each scan file.')) | |
33 | |
34 # Otherwise, this column remains empty. | |
35 else: | |
36 vals = [''] * nfiles | |
37 | |
38 for i, row in enumerate(rows): | |
39 row.append(vals[i]) | |
40 | |
41 | |
42 def main(): | |
43 parser = argparse.ArgumentParser() | |
44 | |
45 # Each column has the same methods for populating | |
46 for column_type in column_types: | |
47 parser.add_argument(f'--{column_type}-consec', action='store_true') | |
48 parser.add_argument(f'--{column_type}-assign-all') | |
49 parser.add_argument(f'--{column_type}-col') | |
50 | |
51 # Scanfile names, which should be identical to history identifiers | |
52 parser.add_argument('scanfiles', nargs='+') | |
53 | |
54 args = parser.parse_args() | |
55 | |
56 # Create and populate data structure for tabular output | |
57 rows = [[scanfile] for scanfile in args.scanfiles] | |
58 for column_type in column_types: | |
59 add_column(column_type, args, rows) | |
60 | |
61 # Write out manifest file. | |
62 # Use mode=a as the script will be called once for each scan group. | |
63 with open(output_filename, mode='a') as outf: | |
64 manifest_writer = csv.writer(outf, delimiter='\t') | |
65 for row in rows: | |
66 manifest_writer.writerow(row) | |
67 | |
68 | |
69 if __name__ == "__main__": | |
70 main() |