annotate CreateAssemblyPicklists_script.py @ 0:4bde3e90ee98 draft

planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
author tduigou
date Wed, 06 Aug 2025 08:02:58 +0000
parents
children 196e13c09881
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
1 #!/usr/bin/env python
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
2 # coding: utf-8
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
3 # Code copied from CUBA backend tools.py and create_assembly_picklists/CreateAssemblyPicklistsView.py
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
4 # Code modified for running in a script in Galaxy.
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
5 ##############################################################################
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
6 ##############################################################################
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
7 # App code
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
8 ## EGF Galaxy Create assembly picklists -- script
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
9
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
10 ##############################################################################
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
11 # IMPORTS
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
12 import argparse
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
13 import os
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
14 from io import StringIO, BytesIO
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
15 import re
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
16 from base64 import b64encode, b64decode
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
17 from copy import deepcopy
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
18 import sys
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
19
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
20 from collections import OrderedDict
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
21 from fuzzywuzzy import process
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
22 import matplotlib.pyplot as plt
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
23 from matplotlib.backends.backend_pdf import PdfPages
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
24 import pandas
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
25
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
26 from Bio import SeqIO
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
27 from Bio.SeqRecord import SeqRecord
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
28 from Bio.Seq import Seq
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
29
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
30 import bandwagon as bw
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
31 import crazydoc
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
32 from dnachisel.biotools import sequence_to_biopython_record
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
33 import dnacauldron
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
34 import flametree
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
35 from plateo import AssemblyPlan
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
36 from plateo.parsers import plate_from_content_spreadsheet
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
37 from plateo.containers import Plate4ti0960
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
38 from plateo.exporters import AssemblyPicklistGenerator, picklist_to_assembly_mix_report
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
39 from plateo.exporters import (
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
40 picklist_to_labcyte_echo_picklist_file,
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
41 picklist_to_tecan_evo_picklist_file,
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
42 plate_to_platemap_spreadsheet,
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
43 PlateTextPlotter,
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
44 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
45 from plateo.tools import human_volume
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
46 from snapgene_reader import snapgene_file_to_seqrecord
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
47
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
48
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
49 ##############################################################################
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
50 # FUNCTIONS
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
51
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
52 def fix_and_rename_paths(paths):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
53 fixed_paths = []
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
54 for path in paths:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
55 new_path = path.replace("__sq__", "'")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
56 if new_path != path:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
57 os.rename(path, new_path)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
58 fixed_paths.append(new_path)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
59 return fixed_paths
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
60
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
61
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
62 def did_you_mean(name, other_names, limit=5, min_score=50): # test
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
63 results = process.extract(name, list(other_names), limit=limit)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
64 return [e for (e, score) in results if score >= min_score]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
65
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
66
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
67 def fix_ice_genbank(genbank_txt):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
68 lines = genbank_txt.splitlines()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
69 lines[0] += max(0, 80 - len(lines[0])) * " "
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
70 return "\n".join(lines)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
71
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
72
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
73 def write_record(record, target, fmt="genbank"):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
74 """Write a record as genbank, fasta, etc. via Biopython, with fixes"""
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
75 record = deepcopy(record)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
76 if fmt == "genbank":
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
77 if isinstance(record, (list, tuple)):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
78 for r in record:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
79 r.name = r.name[:20]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
80 else:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
81 record.name = record.name[:20]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
82 if hasattr(target, "open"):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
83 target = target.open("w")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
84 SeqIO.write(record, target, fmt)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
85
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
86
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
87 def autoname_genbank_file(record):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
88 return record.id.replace(".", "_") + ".gb"
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
89
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
90
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
91 def string_to_records(string):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
92 """Convert a string of a fasta, genbank... into a simple ATGC string.
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
93
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
94 Can also be used to detect a format.
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
95 """
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
96 matches = re.match("([ATGC][ATGC]*)", string)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
97 # print("============", len(matches.groups()[0]), len(string))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
98 # print (matches.groups()[0] == string)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
99 if (matches is not None) and (matches.groups()[0] == string):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
100 return [SeqRecord(Seq(string))], "ATGC"
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
101
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
102 for fmt in ("fasta", "genbank"):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
103 if fmt == "genbank":
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
104 string = fix_ice_genbank(string)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
105 try:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
106 stringio = StringIO(string)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
107 records = list(SeqIO.parse(stringio, fmt))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
108 if len(records) > 0:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
109 return (records, fmt)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
110 except:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
111 pass
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
112 try:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
113 record = snapgene_file_to_seqrecord(filecontent=StringIO(string))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
114 return [record]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
115 except:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
116 pass
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
117 raise ValueError("Invalid sequence format")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
118
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
119
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
120 def file_to_filelike_object(file_, type="byte"):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
121 content = file_.content.split("base64,")[1]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
122 filelike = BytesIO if (type == "byte") else StringIO
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
123 return filelike(b64decode(content))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
124
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
125
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
126 def spreadsheet_file_to_dataframe(filedict, header="infer"):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
127 filelike = file_to_filelike_object(filedict)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
128 if filedict.name.endswith(".csv"):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
129 return pandas.read_csv(filelike, header=header)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
130 else:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
131 return pandas.read_excel(filelike, header=header)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
132
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
133
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
134 def records_from_zip_file(zip_file, use_file_names_as_ids=False):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
135 zip_name = zip_file.name
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
136 zip_file = flametree.file_tree(file_to_filelike_object(zip_file))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
137 records = []
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
138 for f in zip_file._all_files:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
139 ext = f._extension.lower()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
140 if ext in ["gb", "gbk", "fa", "dna"]:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
141 try:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
142 new_records, fmt = string_to_records(f.read())
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
143 if not isinstance(new_records, list):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
144 new_records = [new_records]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
145 except:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
146 content_stream = BytesIO(f.read("rb"))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
147 try:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
148 record = snapgene_file_to_seqrecord(fileobject=content_stream)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
149 new_records, fmt = [record], "snapgene"
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
150 except:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
151 try:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
152 parser = crazydoc.CrazydocParser(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
153 ["highlight_color", "bold", "underline"]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
154 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
155 new_records = parser.parse_doc_file(content_stream)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
156 fmt = "doc"
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
157 except:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
158 raise ValueError("Format not recognized for file " + f._path)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
159
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
160 single_record = len(new_records) == 1
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
161 for i, record in enumerate(new_records):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
162 name = record.id
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
163 if name in [
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
164 None,
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
165 "",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
166 "<unknown id>",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
167 ".",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
168 " ",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
169 "<unknown name>",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
170 ]:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
171 number = "" if single_record else ("%04d" % i)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
172 name = f._name_no_extension.replace(" ", "_") + number
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
173 record.id = name
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
174 record.name = name
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
175 record.file_name = f._name_no_extension
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
176 record.zip_file_name = zip_name
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
177 if use_file_names_as_ids and single_record:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
178 basename = os.path.basename(record.file_name)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
179 basename_no_extension = os.path.splitext(basename)[0]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
180 record.id = basename_no_extension
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
181 records += new_records
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
182 return records
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
183
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
184
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
185 def records_from_data_file(data_file):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
186 content = b64decode(data_file.content.split("base64,")[1])
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
187 try:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
188 records, fmt = string_to_records(content.decode("utf-8"))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
189 except:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
190 try:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
191 record = snapgene_file_to_seqrecord(fileobject=BytesIO(content))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
192 records, fmt = [record], "snapgene"
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
193 except:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
194 try:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
195 parser = crazydoc.CrazydocParser(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
196 ["highlight_color", "bold", "underline"]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
197 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
198 records = parser.parse_doc_file(BytesIO(content))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
199 fmt = "doc"
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
200 except:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
201 try:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
202 df = spreadsheet_file_to_dataframe(data_file, header=None)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
203 records = [
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
204 sequence_to_biopython_record(sequence=seq, id=name, name=name)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
205 for name, seq in df.values
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
206 ]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
207 fmt = "spreadsheet"
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
208 except:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
209 raise ValueError("Format not recognized for file " + data_file.name)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
210 if not isinstance(records, list):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
211 records = [records]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
212 return records, fmt
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
213
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
214
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
215 def record_to_formated_string(record, fmt="genbank", remove_descr=False):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
216 if remove_descr:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
217 record = deepcopy(record)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
218 if isinstance(record, (list, tuple)):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
219 for r in record:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
220 r.description = ""
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
221 else:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
222 record.description = ""
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
223 fileobject = StringIO()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
224 write_record(record, fileobject, fmt)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
225 return fileobject.getvalue().encode("utf-8")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
226
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
227
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
228 def records_from_data_files(data_files, use_file_names_as_ids=False):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
229 records = []
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
230 for file_ in data_files:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
231 circular = ("circular" not in file_) or file_.circular
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
232 if file_.name.lower().endswith("zip"):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
233 records += records_from_zip_file(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
234 file_, use_file_names_as_ids=use_file_names_as_ids
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
235 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
236 continue
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
237 recs, fmt = records_from_data_file(file_)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
238 single_record = len(recs) == 1
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
239 for i, record in enumerate(recs):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
240 record.circular = circular
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
241 record.linear = not circular
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
242 name_no_extension = "".join(file_.name.split(".")[:-1])
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
243 name = name_no_extension + ("" if single_record else ("%04d" % i))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
244 name = name.replace(" ", "_")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
245 UNKNOWN_IDS = [
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
246 "None",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
247 "",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
248 "<unknown id>",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
249 ".",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
250 "EXPORTED",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
251 "<unknown name>",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
252 "Exported",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
253 ]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
254 # Sorry for this parts, it took a lot of "whatever works".
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
255 # keep your part names under 20c and pointless, and everything
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
256 # will be good
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
257 if str(record.id).strip() in UNKNOWN_IDS:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
258 record.id = name
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
259 if str(record.name).strip() in UNKNOWN_IDS:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
260 record.name = name
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
261 record.file_name = name_no_extension
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
262 if use_file_names_as_ids and single_record:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
263 basename = os.path.basename(record.source_file)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
264 basename_no_extension = os.path.splitext(basename)[0]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
265 record.id = basename_no_extension
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
266 records += recs
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
267 return records
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
268
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
269
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
270 def data_to_html_data(data, datatype, filename=None):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
271 """Data types: zip, genbank, fasta, pdf"""
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
272 datatype = {
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
273 "zip": "application/zip",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
274 "genbank": "application/genbank",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
275 "fasta": "application/fasta",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
276 "pdf": "application/pdf",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
277 "xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
278 }.get(datatype, datatype)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
279 datatype = "data:%s;" % datatype
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
280 data64 = "base64,%s" % b64encode(data).decode("utf-8")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
281 headers = ""
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
282 if filename is not None:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
283 headers += "headers=filename%3D" + filename + ";"
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
284 return datatype + headers + data64
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
285
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
286
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
287 def zip_data_to_html_data(data):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
288 return data_to_html_data(data, "application/zip")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
289
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
290
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
291 LADDERS = {"100_to_4k": bw.ladders.LADDER_100_to_4k}
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
292
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
293
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
294 def matplotlib_figure_to_svg_base64_data(fig, **kwargs):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
295 """Return a string of the form 'data:image/svg+xml;base64,XXX' where XXX
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
296 is the base64-encoded svg version of the figure."""
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
297 output = BytesIO()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
298 fig.savefig(output, format="svg", **kwargs)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
299 svg_txt = output.getvalue().decode("utf-8")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
300 svg_txt = "\n".join(svg_txt.split("\n")[4:])
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
301 svg_txt = "".join(svg_txt.split("\n"))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
302
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
303 content = b64encode(svg_txt.encode("utf-8"))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
304 result = (b"data:image/svg+xml;base64," + content).decode("utf-8")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
305
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
306 return result
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
307
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
308
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
309 def matplotlib_figure_to_bitmap_base64_data(fig, fmt="png", **kwargs):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
310 """Return a string of the form 'data:image/png;base64,XXX' where XXX
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
311 is the base64-encoded svg version of the figure."""
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
312 output = BytesIO()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
313 fig.savefig(output, format=fmt, **kwargs)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
314 bitmap = output.getvalue()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
315 content = b64encode(bitmap)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
316 result = (b"data:image/%s;base64,%s" % (fmt.encode("utf-8"), content)).decode(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
317 "utf-8"
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
318 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
319 return result
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
320
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
321
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
322 def figures_to_pdf_report_data(figures, filename="report.pdf"):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
323 pdf_io = BytesIO()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
324 with PdfPages(pdf_io) as pdf:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
325 for fig in figures:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
326 pdf.savefig(fig, bbox_inches="tight")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
327 return {
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
328 "data": (
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
329 "data:application/pdf;base64,"
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
330 + b64encode(pdf_io.getvalue()).decode("utf-8")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
331 ),
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
332 "name": filename,
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
333 "mimetype": "application/pdf",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
334 }
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
335
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
336
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
337 def csv_to_list(csv_string, sep=","):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
338 return [
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
339 element.strip()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
340 for line in csv_string.split("\n")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
341 for element in line.split(sep)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
342 if len(element.strip())
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
343 ]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
344
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
345
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
346 def set_record_topology(record, topology):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
347 """Set the Biopython record's topology, possibly passing if already set.
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
348
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
349 This actually sets the ``record.annotations['topology']``.The ``topology``
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
350 parameter can be "circular", "linear", "default_to_circular" (will default
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
351 to circular if ``annotations['topology']`` is not already set) or
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
352 "default_to_linear".
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
353 """
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
354 valid_topologies = [
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
355 "circular",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
356 "linear",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
357 "default_to_circular",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
358 "default_to_linear",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
359 ]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
360 if topology not in valid_topologies:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
361 raise ValueError(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
362 "topology (%s) should be one of %s."
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
363 % (topology, ", ".join(valid_topologies))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
364 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
365 annotations = record.annotations
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
366 default_prefix = "default_to_"
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
367 if topology.startswith(default_prefix):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
368 if "topology" not in annotations:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
369 annotations["topology"] = topology[len(default_prefix) :]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
370 else:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
371 annotations["topology"] = topology
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
372
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
373
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
374 ##############################################################################
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
375 def main():
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
376
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
377 parser = argparse.ArgumentParser(description="Generate picklist for DNA assembly.")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
378 parser.add_argument("--parts_files", help="Directory with parts data or file with part sizes")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
379 parser.add_argument("--picklist", type=str, help="Path to the assembly plan CSV or Excel file")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
380 parser.add_argument("--source_plate", help="Source plate file (CSV or Excel)")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
381 parser.add_argument("--backbone_name", help="Name of the backbone")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
382 parser.add_argument("--result_zip", help="Name of the output zip file")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
383 parser.add_argument("--part_backbone_ratio", type=float, help="Part to backbone molar ratio")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
384 parser.add_argument("--quantity_unit", choices=["fmol", "nM", "ng"], help="Quantity unit")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
385 parser.add_argument("--part_quantity", type=float, help="Quantity of each part")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
386 parser.add_argument("--buffer_volume", type=float, help="Buffer volume in µL")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
387 parser.add_argument("--total_volume", type=float, help="Total reaction volume in µL")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
388 parser.add_argument("--dispenser", choices=["labcyte_echo", "tecan_evo"], help="Dispenser machine")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
389
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
390 args = parser.parse_args()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
391
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
392 # Parameters:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
393 picklist = args.picklist # assembly plan
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
394 # directory or can be a csv/Excel with part sizes
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
395 if isinstance(args.parts_files, str):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
396 args.parts_files = args.parts_files.split(",")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
397 parts_dir = fix_and_rename_paths(args.parts_files)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
398 source_plate_path = args.source_plate
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
399 backbone_name = args.backbone_name
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
400 part_backbone_ratio = args.part_backbone_ratio
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
401 result_zip_file = args.result_zip # output file name "picklist.zip"
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
402 ##############################################################################
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
403 # Defaults:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
404 destination_plate = None
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
405 destination_type = "new" # this parameter is not actually used
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
406 destination_size = 96 # this parameter is not actually used
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
407 fill_by = "column" # this parameter is not actually used
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
408 quantity_unit = args.quantity_unit
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
409 part_quantity = args.part_quantity # 1.3
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
410 buffer_volume = args.buffer_volume # 0.3 # (µL)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
411 total_volume = args.total_volume # 1 # (µL)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
412 dispenser_machine = args.dispenser
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
413 dispenser_min_volume = 0.5 # (nL), this parameter is not actually used
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
414 dispenser_max_volume = 5 # (µL), this parameter is not actually used
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
415 dispenser_resolution = 2.5 # (nL), this parameter is not actually used
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
416 dispenser_dead_volume = 8 # (µL), this parameter is not actually used
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
417 use_file_names_as_ids = True
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
418
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
419 # CODE
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
420 if picklist.endswith(".csv"):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
421 csv = picklist.read().decode()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
422 rows = [line.split(",") for line in csv.split("\n") if len(line)]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
423 else:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
424 dataframe = pandas.read_excel(picklist)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
425 rows = [row for i, row in dataframe.iterrows()]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
426
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
427 assembly_plan = AssemblyPlan(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
428 OrderedDict(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
429 [
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
430 (
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
431 row[0],
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
432 [
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
433 str(e).strip()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
434 for e in row[1:]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
435 if str(e).strip() not in ["-", "nan", ""]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
436 ],
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
437 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
438 for row in rows
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
439 if row[0] not in ["nan", "Construct name", "constructs", "construct"]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
440 ]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
441 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
442 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
443 for assembly, parts in assembly_plan.assemblies.items():
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
444 assembly_plan.assemblies[assembly] = [part.replace(" ", "_") for part in parts]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
445
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
446 # Reading part infos
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
447 if not isinstance(parts_dir, list):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
448 if parts_dir.endswith((".csv", ".xls", ".xlsx")): # part sizes specified in table
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
449 if parts_dir.endswith(".csv"):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
450 dataframe = pandas.read_csv(parts_dir)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
451 else:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
452 dataframe = pandas.read_excel(parts_dir)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
453 parts_data = {row.part: {"size": row["size"]} for i, row in dataframe.iterrows()}
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
454 else: # input records
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
455 records = dnacauldron.biotools.load_records_from_files(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
456 files=parts_dir, use_file_names_as_ids=use_file_names_as_ids
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
457 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
458 parts_data = {rec.id.replace(" ", "_").lower(): {"record": rec} for rec in records}
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
459 #parts_data = process_parts_with_mapping(records, args.file_name_mapping)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
460 assembly_plan.parts_data = parts_data
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
461 parts_without_data = assembly_plan.parts_without_data()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
462 if len(parts_without_data):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
463 print("success: False")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
464 print("message: Some parts have no provided record or data.")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
465 print("missing_parts: ", parts_without_data)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
466 sys.exit()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
467 # Reading protocol
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
468 if quantity_unit == "fmol":
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
469 part_mol = part_quantity * 1e-15
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
470 part_g = None
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
471 if quantity_unit == "nM":
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
472 part_mol = part_quantity * total_volume * 1e-15
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
473 part_g = None
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
474 if quantity_unit == "ng":
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
475 part_mol = None
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
476 part_g = part_quantity * 1e-9
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
477 # Backbone:part molar ratio calculation is not performed in this case.
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
478 # This ensures no change regardless of form input:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
479 part_backbone_ratio = 1
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
480 print("Generating picklist")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
481 picklist_generator = AssemblyPicklistGenerator(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
482 part_mol=part_mol,
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
483 part_g=part_g,
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
484 complement_to=total_volume * 1e-6, # convert uL to L
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
485 buffer_volume=buffer_volume * 1e-6,
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
486 volume_rounding=2.5e-9, # not using parameter from form
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
487 minimal_dispense_volume=5e-9, # Echo machine's minimum dispense -
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
488 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
489 backbone_name_list = backbone_name.split(",")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
490 source_plate = plate_from_content_spreadsheet(source_plate_path)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
491
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
492 for well in source_plate.iter_wells():
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
493 if well.is_empty:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
494 continue
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
495 quantities = well.content.quantities
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
496 part, quantity = list(quantities.items())[0]
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
497 quantities.pop(part)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
498 quantities[part.replace(" ", "_")] = quantity
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
499
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
500 if part in backbone_name_list:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
501 # This section multiplies the backbone concentration with the
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
502 # part:backbone molar ratio. This tricks the calculator into making
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
503 # a picklist with the desired ratio.
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
504 # For example, a part:backbone = 2:1 will multiply the
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
505 # backbone concentration by 2, therefore half as much of it will be
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
506 # added to the well.
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
507 quantities[part.replace(" ", "_")] = quantity * part_backbone_ratio
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
508 else:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
509 quantities[part.replace(" ", "_")] = quantity
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
510
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
511 source_plate.name = "Source"
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
512 if destination_plate:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
513 dest_filelike = file_to_filelike_object(destination_plate)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
514 destination_plate = plate_from_content_spreadsheet(destination_plate)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
515 else:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
516 destination_plate = Plate4ti0960("Mixplate")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
517 destination_wells = (
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
518 well for well in destination_plate.iter_wells(direction="column") if well.is_empty
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
519 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
520 picklist, picklist_data = picklist_generator.make_picklist(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
521 assembly_plan,
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
522 source_wells=source_plate.iter_wells(),
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
523 destination_wells=destination_wells,
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
524 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
525 if picklist is None:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
526 print("success: False")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
527 print("message: Some parts in the assembly plan have no corresponding well.")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
528 print("picklist_data: ", picklist_data)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
529 print("missing_parts:", picklist_data.get("missing_parts", None))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
530 sys.exit()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
531
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
532 future_plates = picklist.simulate(inplace=False)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
533
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
534
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
535 def text(w):
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
536 txt = human_volume(w.content.volume)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
537 if "construct" in w.data:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
538 txt = "\n".join([w.data["construct"], txt])
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
539 return txt
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
540
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
541
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
542 plotter = PlateTextPlotter(text)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
543 ax, _ = plotter.plot_plate(future_plates[destination_plate], figsize=(20, 8))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
544
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
545 ziproot = flametree.file_tree(result_zip_file, replace=True)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
546
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
547 # MIXPLATE MAP PLOT
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
548 ax.figure.savefig(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
549 ziproot._file("final_mixplate.pdf").open("wb"),
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
550 format="pdf",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
551 bbox_inches="tight",
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
552 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
553 plt.close(ax.figure)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
554 plate_to_platemap_spreadsheet(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
555 future_plates[destination_plate],
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
556 lambda w: w.data.get("construct", ""),
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
557 filepath=ziproot._file("final_mixplate.xls").open("wb"),
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
558 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
559
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
560 # ASSEMBLY REPORT
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
561 print("Writing report...")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
562 picklist_to_assembly_mix_report(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
563 picklist,
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
564 ziproot._file("assembly_mix_picklist_report.pdf").open("wb"),
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
565 data=picklist_data,
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
566 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
567 assembly_plan.write_report(ziproot._file("assembly_plan_summary.pdf").open("wb"))
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
568
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
569 # MACHINE PICKLIST
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
570
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
571 if dispenser_machine == "labcyte_echo":
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
572 picklist_to_labcyte_echo_picklist_file(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
573 picklist, ziproot._file("ECHO_picklist.csv").open("w")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
574 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
575 else:
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
576 picklist_to_tecan_evo_picklist_file(
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
577 picklist, ziproot._file("EVO_picklist.gwl").open("w")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
578 )
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
579 # We'll not write the input source plate.
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
580 # raw = file_to_filelike_object(source_plate_path).read()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
581 # f = ziproot.copy(source_plate_path)
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
582 # f.write(raw, mode="wb")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
583 ziproot._close()
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
584 print("success: True")
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
585
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
586
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
587 if __name__ == "__main__":
4bde3e90ee98 planemo upload for repository https://github.com/Edinburgh-Genome-Foundry/Plateo commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents:
diff changeset
588 main()