Skip to content

Commit

Permalink
Add code
Browse files Browse the repository at this point in the history
  • Loading branch information
veghp committed Apr 11, 2024
1 parent 23e82e0 commit 8ed0ad3
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 1 deletion.
36 changes: 36 additions & 0 deletions seqreport/SeqCollection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import dnacauldron


class SeqCollection:
"""Class to store basic properties of a collection of sequences.
**Parameters**
**fasta**
> The FASTA file of the sequences.
**cost_per_base**
> Cost per nucleotide base.
**cost_per_seq**
> Fix overhead cost for each sequence part (cloning, delivery costs etc).
**currency_symbol**
> The currency symbol to display in the report.
"""

def __init__(self, fasta, cost_per_base=0.25, cost_per_seq=0, currency_symbol="£"):
self.fasta = fasta
self.cost_per_base = cost_per_base
self.cost_per_seq = cost_per_seq
self.currency_symbol = currency_symbol
self.sequences = dnacauldron.biotools.load_records_from_files(
files=[self.fasta], use_file_names_as_ids=False
)
self.n_seq = len(self.sequences)
n_bp = 0
for part in self.sequences:
n_bp += len(part.seq)
self.n_bp = n_bp
self.cost = self.n_seq * self.cost_per_seq + self.n_bp * self.cost_per_base
2 changes: 2 additions & 0 deletions seqreport/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .SeqCollection import SeqCollection
from .reports import write_pdf_report
29 changes: 29 additions & 0 deletions seqreport/report_assets/report_style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.logos {
margin: 0 auto;
}

h1.appendix {
page-break-before: always;
}

h1 {
text-align: center;
}

.ribbon {
margin-left: -2.3em !important;
}

.description {
margin-top: 1em;
}

table {
font-size: 0.6em !important;
}

table img {
width: 1.5em;
/* height: 1em; */
margin-right: 1em
}
45 changes: 45 additions & 0 deletions seqreport/report_assets/seq_report.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#sidebar: p {{sidebar_text}}

.logos
img(src="file:https:///{{ egf_logo_url }}" style="height:40px; width: auto")

hr
h1 Sequence report
hr

p.
This document reports basic sequence statistics.
p.
Number of sequences: <b>{{ seqcollection.n_seq }}</b>
p.
Number of basepairs: <b>{{ seqcollection.n_bp }}</b> bp
p.
Estimated cost: <b>{{ seqcollection.currency_symbol }} {{ seqcollection.cost }}</b>


div(style="margin-top:1cm; margin-bottom:1cm;")

<div style = "display:block; clear:both; page-break-after:always;"></div>

p
strong Seq Report
p.
The report was generated by <a href="https://edinburgh-genome-foundry.github.io/Ediacara/">Seq Report</a>,
a software published by the Edinburgh Genome Foundry (EGF).
Seq Report is part of the <a href="https://edinburgh-genome-foundry.github.io/">EGF Codons</a>
engineering biology software suite for DNA design, manufacturing and validation.


style.
.green {
color: #86bf86
}
.grey {
color: #a9a9a9
}
.red {
color: #fd5a31
}
.yellow {
color: #f7b500
}
47 changes: 47 additions & 0 deletions seqreport/reports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from datetime import datetime
import os

from pdf_reports import (
add_css_class,
dataframe_to_html,
pug_to_html,
style_table_rows,
write_report,
)
import pdf_reports.tools as pdf_tools

from .version import __version__

THIS_PATH = os.path.dirname(os.path.realpath(__file__))
ASSETS_PATH = os.path.join(THIS_PATH, "report_assets")
SEQCOLLECTION_REPORT_TEMPLATE = os.path.join(ASSETS_PATH, "seq_report.pug")
STYLESHEET = os.path.join(ASSETS_PATH, "report_style.css")


def end_pug_to_html(template, **context):
now = datetime.now().strftime("%Y-%m-%d")
defaults = {
"sidebar_text": "Generated on %s by Seq Report (version %s)"
% (now, __version__),
}
for k in defaults:
if k not in context:
context[k] = defaults[k]
return pug_to_html(template, **context)


def write_pdf_report(target, seqcollection):
"""Write a sequence collection report with a PDF summary.
**Parameters**
**target**
> Path for PDF file.
**seqcollection**
> `SeqCollection` instance.
"""

html = end_pug_to_html(SEQCOLLECTION_REPORT_TEMPLATE, seqcollection=seqcollection)
write_report(html, target, extra_stylesheets=(STYLESHEET,))
Empty file removed seqreport/seqreport.py
Empty file.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
keywords="biology dna",
packages=find_packages(exclude="docs"),
include_package_data=True,
install_requires=[],
install_requires=["pdf_reports", "dnacauldron"],
)

0 comments on commit 8ed0ad3

Please sign in to comment.