Mercurial > repos > tduigou > sculpt_sequences
annotate sculpt_sequences.py @ 1:a0cd867780ec draft default tip
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
| author | tduigou |
|---|---|
| date | Thu, 17 Jul 2025 13:24:49 +0000 |
| parents | 0c7f75a2338b |
| children |
| rev | line source |
|---|---|
|
0
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
1 import argparse |
|
1
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
2 import json |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
3 import sys |
|
0
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
4 import os |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
5 import re |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
6 import dnacauldron |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
7 import dnachisel |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
8 from Bio import SeqIO |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
9 import proglog |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
10 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
11 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
12 def smart_number(val): |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
13 try: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
14 float_val = float(val) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
15 if float_val.is_integer(): |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
16 return int(float_val) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
17 else: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
18 return float_val |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
19 except ValueError: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
20 raise ValueError(f"Invalid number: {val}") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
21 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
22 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
23 def sculpt_sequances(files_to_sculpt, file_name_mapping, outdir_scul, outdir_unscul, use_file_names_as_id, |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
24 avoid_patterns, enforce_gc_content, DnaOptimizationProblemClass, |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
25 kmer_size,hairpin_constraints): |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
26 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
27 files_to_sculpt = files_to_sculpt.split(',') |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
28 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
29 records_to_sculpt = dnacauldron.biotools.load_records_from_files( |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
30 files=files_to_sculpt, |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
31 folder=None, |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
32 use_file_names_as_ids=use_file_names_as_id |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
33 ) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
34 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
35 constraint_list = [] |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
36 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
37 # avoid_patterns pearsing |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
38 for pattern in avoid_patterns: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
39 constraint_list.append(dnachisel.AvoidPattern(pattern)) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
40 print(f"AvoidPattern constraint: {pattern}") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
41 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
42 # gc_constraints pearsing |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
43 for constraint in enforce_gc_content: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
44 constraints = [c.strip() for c in constraint.split(' ') if c.strip()] |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
45 for line in constraints: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
46 if not line: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
47 continue |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
48 print(f"GC constraint: {line}") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
49 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
50 try: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
51 pairs = [kv.strip() for kv in line.split(',')] |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
52 params = {} |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
53 for pair in pairs: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
54 key, val = pair.split('=') |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
55 key = key.strip() |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
56 val = val.strip() |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
57 params[key] = smart_number(val) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
58 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
59 constraint_list.append(dnachisel.EnforceGCContent(**params)) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
60 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
61 except Exception as e: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
62 print(f"Skipping invalid gc_constraints: {line} ({e})") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
63 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
64 # hairpin_constraints pearsing |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
65 for constraint in hairpin_constraints: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
66 constraints = [c.strip() for c in constraint.split(' ') if c.strip()] |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
67 for line in constraints: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
68 if not line: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
69 continue |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
70 print(f"Hairpin constraint: {line}") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
71 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
72 try: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
73 pairs = [kv.strip() for kv in line.split(',')] |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
74 params = {} |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
75 for pair in pairs: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
76 key, val = pair.split('=') |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
77 key = key.strip() |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
78 val = val.strip() |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
79 params[key] = smart_number(val) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
80 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
81 constraint_list.append(dnachisel.AvoidHairpins(**params)) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
82 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
83 except Exception as e: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
84 print(f"Skipping invalid hairpin_constraints: {line} ({e})") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
85 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
86 # k_size pearsing |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
87 for k_size in kmer_size: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
88 try: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
89 constraint_list.append(dnachisel.UniquifyAllKmers(k=int(k_size))) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
90 print(f"k-mer size is: {k_size}") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
91 except ValueError: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
92 print(f"Skipping invalid k-mer size: {k_size}") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
93 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
94 # refine the real record name dict |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
95 if isinstance(file_name_mapping, str): |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
96 file_name_mapping = dict( |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
97 item.split(":") for item in file_name_mapping.split(",") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
98 ) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
99 real_names = { |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
100 os.path.splitext(os.path.basename(k))[0]: v.replace(".gb", "") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
101 for k, v in file_name_mapping.items() |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
102 } |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
103 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
104 counter = 0 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
105 # not_divisible_seqs = [] |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
106 for record in records_to_sculpt: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
107 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
108 # Look up the "real name" from the simplified dict (file_name_mapping) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
109 real_name = real_names.get(record.id, record.id) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
110 if real_name is None: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
111 raise ValueError(f"Error: {record.id} not found in the fragment names dictionary!") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
112 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
113 if DnaOptimizationProblemClass == 'DnaOptimizationProblem': |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
114 problem = dnachisel.DnaOptimizationProblem.from_record(record, extra_constraints=constraint_list) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
115 elif DnaOptimizationProblemClass == 'CircularDnaOptimizationProblem': |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
116 problem = dnachisel.CircularDnaOptimizationProblem.from_record(record, extra_constraints=constraint_list) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
117 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
118 if not problem.all_constraints_pass(): |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
119 counter += 1 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
120 print(real_name) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
121 len_seq = len(problem.sequence) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
122 print("Length:", len_seq) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
123 target_path = os.path.join(outdir_scul, real_name + ".zip") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
124 problem.optimize_with_report(target=target_path) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
125 print() |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
126 print(problem.constraints_text_summary()) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
127 print() |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
128 else: # just save the genbank |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
129 genbank_filename = real_name + ".gb" |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
130 with open(os.path.join(outdir_unscul, genbank_filename), "w") as output_handle: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
131 SeqIO.write(record, output_handle, "genbank") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
132 print() |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
133 print("Counter:", counter) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
134 # print("Contents of outdir_scul:") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
135 # for f in os.listdir(outdir_scul): |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
136 # print(" -", f) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
137 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
138 # Unzip all files in scul |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
139 import zipfile |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
140 for file in os.listdir(outdir_scul): |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
141 if file.endswith(".zip"): |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
142 zip_path = os.path.join(outdir_scul, file) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
143 extract_dir = os.path.join(outdir_scul, os.path.splitext(file)[0]) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
144 os.makedirs(extract_dir, exist_ok=True) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
145 with zipfile.ZipFile(zip_path, 'r') as zip_ref: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
146 zip_ref.extractall(extract_dir) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
147 # print("Contents of outdir_scul:") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
148 # for f in os.listdir(outdir_scul): |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
149 # print(" -", f) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
150 reports = os.listdir(outdir_scul) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
151 # print (f'report is {reports}') |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
152 from shutil import copyfile |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
153 for report in reports: |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
154 if report.endswith(".zip"): |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
155 continue |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
156 gb_file = os.path.join(outdir_scul, report, "final_sequence.gb") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
157 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
158 target_filename = report + ".gb" |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
159 target_file = os.path.join(outdir_unscul, target_filename) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
160 print(gb_file, target_file) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
161 copyfile(gb_file, target_file) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
162 # print("Contents of outdir_unscul:") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
163 # for f in os.listdir(outdir_unscul): |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
164 # print(" -", f) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
165 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
166 return outdir_scul, outdir_unscul |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
167 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
168 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
169 def parse_command_line_args(): |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
170 parser = argparse.ArgumentParser(description="Evaluate manufacturability of DNA sequences.") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
171 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
172 parser.add_argument("--files_to_sculpt", required=True, |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
173 help="List of GenBank files (Comma-separated)") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
174 parser.add_argument('--file_name_mapping', type=str, |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
175 help='Mapping of Galaxy filenames to original filenames') |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
176 parser.add_argument("--outdir_scul", required=True, help="scul file dir") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
177 parser.add_argument("--outdir_unscul", required=True, help="unscul file dir") |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
178 parser.add_argument("--use_file_names_as_id", type=lambda x: x.lower() == 'true', default=True, |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
179 help="Use file names as IDs (True/False)") |
|
1
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
180 parser.add_argument("--avoid_patterns", required=False, |
|
0
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
181 help="List of patterns to avoid (comma-separated, e.g., 'BsaI_site,BsmBI_site')") |
|
1
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
182 parser.add_argument("--gc_constraints", required=False, |
|
0
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
183 help="GC content constraints as 'min;max;window' (space-separated, e.g., '0.3;0.7;100 0.1;0.3;100')") |
|
1
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
184 parser.add_argument("--DnaOptimizationProblemClass", required=False, |
|
0
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
185 help="the class to use for DnaOptimizationProblem") |
|
1
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
186 parser.add_argument("--hairpin_constraints", required=False, |
|
0
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
187 help="Hairpin constraints as 'stem_size;window_size' (space-separated, e.g., '20;200 30;250')") |
|
1
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
188 parser.add_argument("--kmer_size", required = False, |
|
0
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
189 help="K-mer uniqueness size (e.g., '15')") |
|
1
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
190 parser.add_argument("--json_params", required=False, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
191 help="JSON params for the tool") |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
192 parser.add_argument("--use_json_param", required=True, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
193 help="If use JSON as param source") |
|
0
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
194 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
195 return parser.parse_args() |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
196 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
197 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
198 def extract_constraints_from_args(args): |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
199 """Extract constraints directly from the command-line arguments.""" |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
200 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
201 split_pattern = r'(?:__cn__|\s{2,})' |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
202 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
203 # 1. Avoid patterns (split by any whitespace) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
204 avoid_patterns = re.split(split_pattern, args.avoid_patterns.strip()) if args.avoid_patterns.strip() else [] |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
205 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
206 # 2. Hairpin constraint: one dictionary (print as string later) |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
207 hairpin_constraints = re.split(split_pattern,args.hairpin_constraints.strip()) if args.hairpin_constraints.strip() else [] |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
208 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
209 # 3. GC constraints: split by 2+ spaces or newlines |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
210 gc_constraints = re.split(split_pattern, args.gc_constraints.strip()) if args.gc_constraints.strip() else [] |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
211 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
212 # 4. k-mer size: single value or list |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
213 kmer_size = [int(k.strip()) for k in args.kmer_size.strip().split(',') if k.strip()] if args.kmer_size.strip() else [] |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
214 |
|
1
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
215 # 5. DnaOptimizationProblemClass (as string) |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
216 DnaOptimizationProblemClass = args.DnaOptimizationProblemClass if args.DnaOptimizationProblemClass else None |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
217 |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
218 return avoid_patterns, hairpin_constraints, gc_constraints, kmer_size, DnaOptimizationProblemClass |
|
0
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
219 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
220 |
|
1
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
221 def load_constraints_from_json(json_path): |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
222 with open(json_path, 'r') as f: |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
223 params = json.load(f) |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
224 |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
225 def split_lines(val): |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
226 if isinstance(val, str): |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
227 return [line.strip() for line in val.strip().split('\n') if line.strip()] |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
228 return val |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
229 |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
230 avoid_patterns = split_lines(params.get("avoid_patterns", "")) |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
231 hairpin_constraints = split_lines(params.get("hairpin_constraints", "")) |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
232 gc_constraints = split_lines(params.get("gc_constraints", "")) |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
233 kmer_size = [int(k.strip()) for k in str(params.get("kmer_size", "")).split(',') if k.strip()] |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
234 DnaOptimizationProblemClass = params.get("DnaOptimizationProblemClass", None) |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
235 |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
236 return { |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
237 "avoid_patterns": avoid_patterns, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
238 "hairpin_constraints": hairpin_constraints, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
239 "gc_constraints": gc_constraints, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
240 "kmer_size": kmer_size, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
241 "DnaOptimizationProblemClass": DnaOptimizationProblemClass |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
242 } |
|
0
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
243 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
244 if __name__ == "__main__": |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
245 args = parse_command_line_args() |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
246 |
|
1
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
247 avoid_patterns, hairpin_constraints, gc_constraints, kmer_size, DnaOptimizationProblemClass = extract_constraints_from_args(args) |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
248 |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
249 # Check if the flag --use_json_param is present and set to true |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
250 if "--use_json_param" in sys.argv: |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
251 use_json_index = sys.argv.index("--use_json_param") + 1 |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
252 use_json = sys.argv[use_json_index].lower() == "true" |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
253 else: |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
254 use_json = False |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
255 |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
256 # Now only check --json_params if use_json is True |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
257 if use_json: |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
258 if "--json_params" in sys.argv: |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
259 json_index = sys.argv.index("--json_params") + 1 |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
260 json_file = sys.argv[json_index] |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
261 if json_file.lower() != "none": |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
262 json_constraints = load_constraints_from_json(json_file) |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
263 avoid_patterns = json_constraints["avoid_patterns"] |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
264 hairpin_constraints = json_constraints["hairpin_constraints"] |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
265 gc_constraints = json_constraints["gc_constraints"] |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
266 kmer_size = json_constraints["kmer_size"] |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
267 DnaOptimizationProblemClass = json_constraints["DnaOptimizationProblemClass"] |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
268 |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
269 params = { |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
270 "files_to_sculpt": args.files_to_sculpt, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
271 "file_name_mapping": args.file_name_mapping, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
272 "outdir_unscul": args.outdir_unscul, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
273 "outdir_scul": args.outdir_scul, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
274 "use_file_names_as_id": args.use_file_names_as_id, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
275 "avoid_patterns": avoid_patterns, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
276 "hairpin_constraints": hairpin_constraints, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
277 "gc_constraints": gc_constraints, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
278 "kmer_size": kmer_size, |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
279 "DnaOptimizationProblemClass": DnaOptimizationProblemClass |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
280 } |
|
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
281 |
|
0
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
282 |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
283 sculpt_sequances( |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
284 args.files_to_sculpt, args.file_name_mapping, |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
285 args.outdir_scul, args.outdir_unscul, |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
286 args.use_file_names_as_id, avoid_patterns, |
|
1
a0cd867780ec
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit 6b6ce806b5d016b3c7f20318180eff2dbe64395a-dirty
tduigou
parents:
0
diff
changeset
|
287 gc_constraints, DnaOptimizationProblemClass, |
|
0
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
288 kmer_size, hairpin_constraints |
|
0c7f75a2338b
planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Examples/blob/master/templates/template1.ipynb commit fa4c85dd6ad48d404a28e21667f18b628bbdc702-dirty
tduigou
parents:
diff
changeset
|
289 ) |
