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