annotate cloning_simulation.py @ 8:07e902da89ad draft

planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
author tduigou
date Mon, 26 May 2025 09:23:51 +0000
parents 044d36066cb3
children eaff3028ba07
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
1 import os
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
2 import dnacauldron
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
3 from Bio import SeqIO
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
4 import pandas
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
5 import argparse
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
6 import zipfile
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
7
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
8 def cloning_simulation(files_to_assembly, domesticated_list,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
9 csv_file, assembly_type, topology,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
10 file_name_mapping, file_name_mapping_dom,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
11 use_file_names_as_id,
2
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
12 outdir_simulation, output_simulation,enzyme,outdir_gb):
0
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
13
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
14 files_to_assembly = files_to_assembly.split(',')
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
15
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
16 repository = dnacauldron.SequenceRepository()
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
17 repository.import_records(files=files_to_assembly,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
18 use_file_names_as_ids=use_file_names_as_id,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
19 topology=topology)
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
20 if domesticated_list:
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
21 domesticated_files = domesticated_list.split(',')
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
22 repository.import_records(files=domesticated_files,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
23 use_file_names_as_ids=use_file_names_as_id,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
24 topology=topology)
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
25
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
26 #refine the real record name dict
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
27 if isinstance(file_name_mapping, str):
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
28 file_name_mapping = dict(
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
29 item.split(":") for item in file_name_mapping.split(",")
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
30 )
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
31 real_names = {
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
32 os.path.splitext(os.path.basename(k))[0]: v.replace(".gb", "")
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
33 for k, v in file_name_mapping.items()
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
34 }
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
35
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
36 #refine the real record name dict_dom
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
37 if file_name_mapping_dom == "":
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
38 file_name_mapping_dom={}
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
39 else:
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
40 if isinstance(file_name_mapping_dom, str):
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
41 file_name_mapping_dom = dict(
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
42 item.split(":") for item in file_name_mapping_dom.split(",")
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
43 )
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
44 dom_real_names = {
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
45 os.path.splitext(os.path.basename(k))[0]: v.replace(".gb", "")
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
46 for k, v in file_name_mapping_dom.items()
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
47 }
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
48 real_names.update(dom_real_names)
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
49
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
50 #update the records
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
51
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
52 for key, record in list(repository.collections["parts"].items()):
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
53 current_id = record.id
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
54 if current_id in real_names:
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
55 new_id = real_names[current_id]
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
56 record.id = new_id
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
57 record.name = new_id
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
58 record.description = new_id
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
59 repository.collections["parts"][new_id] = repository.collections["parts"].pop(key)
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
60 ########################################################
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
61 #print (f"repo: {vars(repository)}")
8
07e902da89ad planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 3
diff changeset
62 #any(pandas.read_csv(csv_file, index_col=0, header=None).duplicated())
07e902da89ad planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 3
diff changeset
63 df=pandas.read_csv(csv_file, index_col=0, header=None)
07e902da89ad planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 3
diff changeset
64 if df.duplicated().any():
07e902da89ad planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 3
diff changeset
65 raise ValueError("Duplicate rows found in the data!")
0
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
66
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
67 if assembly_type == "Type2sRestrictionAssembly":
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
68 assembly_class = dnacauldron.Type2sRestrictionAssembly
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
69 elif assembly_type == "GibsonAssembly":
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
70 assembly_class = dnacauldron.GibsonAssembly
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
71 elif assembly_type == "BASICAssembly":
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
72 assembly_class = dnacauldron.BASICAssembly
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
73 elif assembly_type == "BioBrickStandardAssembly":
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
74 assembly_class = dnacauldron.BioBrickStandardAssembly
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
75 elif assembly_type == "OligoPairAnnealin":
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
76 assembly_class = dnacauldron.OligoPairAnnealin
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
77 elif assembly_type == "LigaseCyclingReactionAssembly":
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
78 assembly_class = dnacauldron.LigaseCyclingReactionAssembly
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
79 else:
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
80 raise ValueError(f"Unsupported assembly type: {assembly_type}")
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
81
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
82 new_csvname = "assambly.csv"
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
83 os.rename(csv_file, new_csvname)
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
84
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
85 assembly_plan = dnacauldron.AssemblyPlan.from_spreadsheet(
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
86 name="auto_from_filename",
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
87 path=new_csvname,
8
07e902da89ad planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 3
diff changeset
88 header=[0],
0
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
89 assembly_class=assembly_class
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
90 )
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
91 if enzyme != 'auto':
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
92 for assembly in assembly_plan.assemblies:
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
93 assembly.enzyme = enzyme
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
94
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
95 simulation = assembly_plan.simulate(sequence_repository=repository)
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
96 stats = simulation.compute_stats()
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
97 print(stats)
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
98
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
99 report_writer = dnacauldron.AssemblyReportWriter(
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
100 include_mix_graphs=True,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
101 include_assembly_plots=True,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
102 show_overhangs_in_graph=True,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
103 annotate_parts_homologies=True,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
104 include_pdf_report=True,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
105 )
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
106 simulation.write_report(outdir_simulation, assembly_report_writer=report_writer)
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
107
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
108 # Append report files to .dat (ZIP)
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
109 with zipfile.ZipFile(output_simulation, mode='a', compression=zipfile.ZIP_DEFLATED) as zipf:
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
110 for root, dirs, files in os.walk(outdir_simulation):
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
111 for file in files:
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
112 full_path = os.path.join(root, file)
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
113 arcname = os.path.relpath(full_path, outdir_simulation)
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
114 zipf.write(full_path, arcname)
2
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
115 #print("Files in the zip archive:")
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
116 #for info in zipf.infolist():
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
117 #print(info.filename)
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
118 for member in zipf.namelist():
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
119 # Only extract actual files inside 'all_construct_records/' (not subfolders)
3
044d36066cb3 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 2
diff changeset
120 if member.startswith("assambly_simulation/all_construct_records/") and not member.endswith("/"):
2
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
121 # Get the file name only (strip folder path)
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
122 filename = os.path.basename(member)
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
123 if not filename:
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
124 continue # skip any edge cases
0
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
125
2
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
126 # Destination path directly in outdir_dir
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
127 target_path = os.path.join(outdir_gb, filename)
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
128
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
129 # Write the file content
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
130 with zipf.open(member) as source, open(target_path, "wb") as target:
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
131 target.write(source.read())
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
132
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
133 return output_simulation, outdir_gb
0
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
134
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
135
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
136 def parse_command_line_args():
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
137 parser = argparse.ArgumentParser(description="Domestication")
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
138
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
139 parser.add_argument("--parts_files", required=True,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
140 help="List of GenBank files (Comma-separated)")
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
141 parser.add_argument("--domesticated_seq", required=True,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
142 help="output of domestication (ganbank list)")
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
143 parser.add_argument("--assembly_csv", required=True,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
144 help="csv assembly")
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
145 parser.add_argument('--assembly_plan_name', type=str,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
146 help='type of assembly')
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
147 parser.add_argument('--topology', type=str,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
148 help='"circular" or "linear"')
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
149 parser.add_argument('--file_name_mapping', type=str,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
150 help='Mapping of Galaxy filenames to original filenames')
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
151 parser.add_argument('--file_name_mapping_dom', type=str,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
152 help='Mapping of Galaxy filenames to original domestication filenames')
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
153 parser.add_argument("--use_file_names_as_id", type=lambda x: x.lower() == 'true', default=True,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
154 help="Use file names as IDs (True/False)")
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
155 parser.add_argument("--outdir_simulation", required=True,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
156 help="dir output for cloning simulation results")
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
157 parser.add_argument("--output_simulation", required=True,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
158 help="zip output for cloning simulation results")
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
159 parser.add_argument('--enzyme', type=str,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
160 help='enzyme to use')
2
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
161 parser.add_argument("--outdir_gb", required=True,
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
162 help="dir output constructs gb files")
0
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
163
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
164 return parser.parse_args()
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
165
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
166 if __name__ == "__main__":
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
167 args = parse_command_line_args()
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
168
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
169 cloning_simulation(
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
170 args.parts_files, args.domesticated_seq,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
171 args.assembly_csv, args.assembly_plan_name, args.topology,
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
172 args.file_name_mapping, args.file_name_mapping_dom,
2
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
173 args.use_file_names_as_id, args.outdir_simulation,
3171db614963 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents: 0
diff changeset
174 args.output_simulation, args.enzyme, args.outdir_gb
0
dc450979fcd4 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/DnaCauldron/tree/master commit 6ae809b563b40bcdb6be2e74fe2a84ddad5484ae
tduigou
parents:
diff changeset
175 )