Mercurial > repos > tduigou > cloning_simulation
comparison cloning_simulation.py @ 2:3171db614963 draft
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
author | tduigou |
---|---|
date | Fri, 16 May 2025 11:32:06 +0000 |
parents | dc450979fcd4 |
children | 044d36066cb3 |
comparison
equal
deleted
inserted
replaced
1:32e44a646b68 | 2:3171db614963 |
---|---|
7 | 7 |
8 def cloning_simulation(files_to_assembly, domesticated_list, | 8 def cloning_simulation(files_to_assembly, domesticated_list, |
9 csv_file, assembly_type, topology, | 9 csv_file, assembly_type, topology, |
10 file_name_mapping, file_name_mapping_dom, | 10 file_name_mapping, file_name_mapping_dom, |
11 use_file_names_as_id, | 11 use_file_names_as_id, |
12 outdir_simulation, output_simulation,enzyme): | 12 outdir_simulation, output_simulation,enzyme,outdir_gb): |
13 | 13 |
14 files_to_assembly = files_to_assembly.split(',') | 14 files_to_assembly = files_to_assembly.split(',') |
15 | 15 |
16 repository = dnacauldron.SequenceRepository() | 16 repository = dnacauldron.SequenceRepository() |
17 repository.import_records(files=files_to_assembly, | 17 repository.import_records(files=files_to_assembly, |
106 for root, dirs, files in os.walk(outdir_simulation): | 106 for root, dirs, files in os.walk(outdir_simulation): |
107 for file in files: | 107 for file in files: |
108 full_path = os.path.join(root, file) | 108 full_path = os.path.join(root, file) |
109 arcname = os.path.relpath(full_path, outdir_simulation) | 109 arcname = os.path.relpath(full_path, outdir_simulation) |
110 zipf.write(full_path, arcname) | 110 zipf.write(full_path, arcname) |
111 print("Files in the zip archive:") | 111 #print("Files in the zip archive:") |
112 for info in zipf.infolist(): | 112 #for info in zipf.infolist(): |
113 print(info.filename) | 113 #print(info.filename) |
114 with zipfile.ZipFile(output_simulation, 'r') as zipf: | |
115 for member in zipf.namelist(): | |
116 # Only extract actual files inside 'all_construct_records/' (not subfolders) | |
117 if member.startswith("all_construct_records/") and not member.endswith("/"): | |
118 # Get the file name only (strip folder path) | |
119 filename = os.path.basename(member) | |
120 if not filename: | |
121 continue # skip any edge cases | |
114 | 122 |
115 return output_simulation | 123 # Destination path directly in outdir_dir |
124 target_path = os.path.join(outdir_gb, filename) | |
125 | |
126 # Write the file content | |
127 with zipf.open(member) as source, open(target_path, "wb") as target: | |
128 target.write(source.read()) | |
129 | |
130 return output_simulation, outdir_gb | |
116 | 131 |
117 | 132 |
118 def parse_command_line_args(): | 133 def parse_command_line_args(): |
119 parser = argparse.ArgumentParser(description="Domestication") | 134 parser = argparse.ArgumentParser(description="Domestication") |
120 | 135 |
138 help="dir output for cloning simulation results") | 153 help="dir output for cloning simulation results") |
139 parser.add_argument("--output_simulation", required=True, | 154 parser.add_argument("--output_simulation", required=True, |
140 help="zip output for cloning simulation results") | 155 help="zip output for cloning simulation results") |
141 parser.add_argument('--enzyme', type=str, | 156 parser.add_argument('--enzyme', type=str, |
142 help='enzyme to use') | 157 help='enzyme to use') |
158 parser.add_argument("--outdir_gb", required=True, | |
159 help="dir output constructs gb files") | |
143 | 160 |
144 return parser.parse_args() | 161 return parser.parse_args() |
145 | 162 |
146 if __name__ == "__main__": | 163 if __name__ == "__main__": |
147 args = parse_command_line_args() | 164 args = parse_command_line_args() |
148 | 165 |
149 cloning_simulation( | 166 cloning_simulation( |
150 args.parts_files, args.domesticated_seq, | 167 args.parts_files, args.domesticated_seq, |
151 args.assembly_csv, args.assembly_plan_name, args.topology, | 168 args.assembly_csv, args.assembly_plan_name, args.topology, |
152 args.file_name_mapping, args.file_name_mapping_dom, | 169 args.file_name_mapping, args.file_name_mapping_dom, |
153 args.use_file_names_as_id, | 170 args.use_file_names_as_id, args.outdir_simulation, |
154 args.outdir_simulation,args.output_simulation, args.enzyme | 171 args.output_simulation, args.enzyme, args.outdir_gb |
155 ) | 172 ) |