Skip to content

Commit

Permalink
Add assembly plan option
Browse files Browse the repository at this point in the history
  • Loading branch information
veghp committed Apr 19, 2024
1 parent f3097b9 commit 704c8ea
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
26 changes: 26 additions & 0 deletions seqreport/SeqCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class SeqCollection:
**name_length**
> Check which sequence IDs are longer than this cutoff. Genbank has a character
limit.
**assembly_plan**
> An optional assembly plan for calculating savings by re-using DNA parts.
"""

def __init__(
Expand All @@ -49,6 +52,7 @@ def __init__(
min_length=100, # a good cutoff for min DNA synthesis length
max_length=3000, # a good cutoff for max DNA synthesis length
name_length=15, # max seq record name length. Genbank character limit.
assembly_plan=""
):
self.sequences = records
self.cost_per_base = cost_per_base
Expand All @@ -59,6 +63,7 @@ def __init__(
self.min_length = min_length
self.max_length = max_length
self.name_length = name_length
self.assembly_plan = assembly_plan
self.calculate_values()

def calculate_values(self):
Expand Down Expand Up @@ -125,6 +130,27 @@ def calculate_values(self):
reverse_complement_seq_text_list += [combined]
self.reverse_complement_seq_text = " ; ".join(reverse_complement_seq_text_list)

# Savings section
if self.assembly_plan:
all_rows = []
with open(self.assembly_plan, "r") as f:
reader = csv.reader(f, skipinitialspace=True)
next(reader) # ignore header
for row in reader:
all_rows += row[1:] # first column is construct name
self.savings_list = []
self.total_savings = 0
for record in self.sequences:
count_in_plan = all_rows.count(record.id)
if count_in_plan > 1: # we count re-use savings only
self.total_savings += len(record.seq) * (count_in_plan - 1) # ignore first synthesis
self.savings_list += [record.id]
self.total_cost_savings = self.total_savings * self.cost_per_base # ignore cost / seq
# For the PDF report:
self.savings_list_text = " ; ".join(self.savings_list)
else:
self.savings_list_text = ""


def read_fasta(fasta):
"""Read a FASTA sequence file into a list of records.
Expand Down
11 changes: 11 additions & 0 deletions seqreport/report_assets/seq_report.pug
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ else
p.
#[span.green] None of the sequences are reverse complements.

if seqcollection.assembly_plan

if seqcollection.savings_list_text
p.
Re-used sequences in the provided assembly plan: {{ seqcollection.savings_list_text }}.
Total savings: <b>{{ seqcollection.total_savings }}</b> bp or <b>{{ seqcollection.currency_symbol }} {{ seqcollection.total_cost_savings }}</b>.
else
p.
None of the sequences are used more than once in the provided assembly plan.


if seqcollection.comments
p.
Comments: <i>{{ seqcollection.comments }}</i>
Expand Down

0 comments on commit 704c8ea

Please sign in to comment.