annotate generate_manifest.py @ 8:da1531027506 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:52 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
da1531027506 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
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
2
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
3 #
da1531027506 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.
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
5 #
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
6
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
7 import argparse
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
8 import csv
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
9
da1531027506 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
da1531027506 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')
da1531027506 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'
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
13
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
14
da1531027506 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.
da1531027506 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):
da1531027506 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)
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
18
da1531027506 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
da1531027506 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'):
da1531027506 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)
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
22
da1531027506 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
da1531027506 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'):
da1531027506 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
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
26
da1531027506 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
da1531027506 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'):
da1531027506 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(',')
da1531027506 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:
da1531027506 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}. '
da1531027506 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.'))
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
33
da1531027506 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.
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
35 else:
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
36 vals = [''] * nfiles
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
37
da1531027506 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):
da1531027506 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])
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
40
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
41
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
42 def main():
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
43 parser = argparse.ArgumentParser()
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
44
da1531027506 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
da1531027506 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:
da1531027506 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')
da1531027506 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')
da1531027506 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')
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
50
da1531027506 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
da1531027506 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='+')
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
53
da1531027506 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()
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
55
da1531027506 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
da1531027506 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]
da1531027506 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:
da1531027506 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)
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
60
da1531027506 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.
da1531027506 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.
da1531027506 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:
da1531027506 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')
da1531027506 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:
da1531027506 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)
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
67
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
68
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
69 if __name__ == "__main__":
da1531027506 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/fragpipe commit 6413a461059c4a421a7812a08f244c224cde8ee2
galaxyp
parents:
diff changeset
70 main()