Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Check whether the high-level utility functions return the expected
content of a known GenBank file.
"""
gb_file = gb.GenBankFile.read(join(data_dir("sequence"), "ec_bl21.gb"))
assert gb.get_locus(gb_file) \
== ("CP001509", 4558953, "DNA", True, "BCT", "16-FEB-2017")
assert gb.get_definition(gb_file) \
== ("Escherichia coli BL21(DE3), complete genome.")
assert gb.get_version(gb_file) == "CP001509.3"
assert gb.get_gi(gb_file) == 296142109
assert gb.get_db_link(gb_file) \
== {"BioProject" : "PRJNA20713", "BioSample" : "SAMN02603478"}
annotation = gb.get_annotation(gb_file, include_only=["CDS"])
feature = seq.Feature(
"CDS",
[seq.Location(5681, 6457, seq.Location.Strand.REVERSE)],
{"gene": "yaaA", "transl_table": "11"}
)
in_annotation = False
for f in annotation:
if f.key == feature.key and f.locs == feature.locs and \
all([(key, val in f.qual.items())
for key, val in feature.qual.items()]):
in_annotation = True
assert in_annotation
assert len(gb.get_sequence(gb_file, format="gb")) == 4558953
def test_feature_without_id():
"""
A feature without 'ID' should raise an error if it has multiple
locations and consequently multiple entries in the GFF3 file.
"""
annot = seq.Annotation(
[seq.Feature(
key = "CDS",
locs = [seq.Location(1,2), seq.Location(4,5)],
qual = {"some" : "qualifiers"}
)]
)
file = gff.GFFFile()
with pytest.raises(ValueError):
gff.set_annotation(file, annot)
def test_annotation_indexing():
feature1 = Feature("CDS", [Location(-10,30 )], qual={"gene" : "test1"})
feature2 = Feature("CDS", [Location(20, 50 )], qual={"gene" : "test2"})
feature3 = Feature("CDS", [Location(100,130)], qual={"gene" : "test3"})
feature4 = Feature("CDS", [Location(150,250)], qual={"gene" : "test4"})
feature5 = Feature("CDS", [Location(-50,200)], qual={"gene" : "test5"})
annotation = Annotation([feature1,feature2,feature3,feature4,feature5])
sub_annot = annotation[40:150]
# Only one location per feature
assert set([list(f.locs)[0].defect for f in sub_annot]) \
== set([Location.Defect.MISS_LEFT, Location.Defect.NONE,
(Location.Defect.MISS_LEFT | Location.Defect.MISS_RIGHT)])
assert set([f.qual["gene"] for f in sub_annot]) \
== set(["test2", "test3", "test5"])
def test_annotation_creation():
feature1 = Feature("CDS", [seq.Location(1,2)], qual={"gene" : "test1"})
feature2 = Feature("CDS", [seq.Location(3,4)], qual={"gene" : "test2"})
feature_list = [feature1, feature2]
annotation = Annotation(feature_list)
for feature in annotation:
assert feature.key in [f.key for f in feature_list]
assert feature.qual["gene"] in [
f.qual["gene"] for f in feature_list
]
"""
Feature map of a synthetic operon
=================================
This script shows how to create a picture of an synthetic operon for
publication purposes.
"""
# Code source: Patrick Kunzmann
# License: BSD 3 clause
import matplotlib.pyplot as plt
from biotite.sequence import Annotation, Feature, Location
import biotite.sequence.graphics as graphics
strand = Location.Strand.FORWARD
prom = Feature("regulatory", [Location(10, 50, strand)],
{"regulatory_class" : "promoter",
"note" : "T7"})
rbs1 = Feature("regulatory", [Location(60, 75, strand)],
{"regulatory_class" : "ribosome_binding_site",
"note" : "RBS1"})
gene1 = Feature("gene", [Location(81, 380, strand)],
{"gene" : "gene1"})
rbs2 = Feature("regulatory", [Location(400, 415, strand)],
{"regulatory_class" : "ribosome_binding_site",
"note" : "RBS2"})
gene2 = Feature("gene", [Location(421, 1020, strand)],
{"gene" : "gene2"})
term = Feature("regulatory", [Location(1050, 1080, strand)],
{"regulatory_class" : "terminator"})
annotation = Annotation([prom, rbs1, gene1, rbs2, gene2, term])
# Code source: Patrick Kunzmann
# License: BSD 3 clause
import matplotlib.pyplot as plt
from biotite.sequence import Annotation, Feature, Location
import biotite.sequence.graphics as graphics
strand = Location.Strand.FORWARD
prom = Feature("regulatory", [Location(10, 50, strand)],
{"regulatory_class" : "promoter",
"note" : "T7"})
rbs1 = Feature("regulatory", [Location(60, 75, strand)],
{"regulatory_class" : "ribosome_binding_site",
"note" : "RBS1"})
gene1 = Feature("gene", [Location(81, 380, strand)],
{"gene" : "gene1"})
rbs2 = Feature("regulatory", [Location(400, 415, strand)],
{"regulatory_class" : "ribosome_binding_site",
"note" : "RBS2"})
gene2 = Feature("gene", [Location(421, 1020, strand)],
{"gene" : "gene2"})
term = Feature("regulatory", [Location(1050, 1080, strand)],
{"regulatory_class" : "terminator"})
annotation = Annotation([prom, rbs1, gene1, rbs2, gene2, term])
fig = plt.figure(figsize=(8.0, 0.8))
ax = fig.add_subplot(111)
graphics.plot_feature_map(
ax, annotation, multi_line=False, loc_range=(1, 1101),
)
fig.tight_layout()
def _add_sec_str(annotation, first, last, str_type):
if str_type == "a":
str_type = "helix"
elif str_type == "b":
str_type = "sheet"
else:
# coil
return
feature = seq.Feature(
"SecStr", [seq.Location(first, last)], {"sec_str_type" : str_type}
)
annotation.add_feature(feature)
# 'omit_oversized_labels' to False
seq.Feature(
"primer_bind",
[seq.Location(1385, 1405)],
{"note": "geneC"}
),
seq.Feature(
"primer_bind",
[seq.Location(345, 365, seq.Location.Strand.REVERSE)],
{"note": "geneC_R"}
),
# Terminator
seq.Feature(
"regulatory",
[seq.Location(310, 350)],
{"regulatory_class": "terminator", "note": "MyTerm"}
),
])
fig = plt.figure(figsize=(8.0, 8.0))
ax = fig.add_subplot(111, projection="polar")
graphics.plot_plasmid_map(
ax, annotation, plasmid_size=1500, label="My plasmid",
label_properties={"fontsize": 8}
)
ticks = ax.get_xticks()
labels = ax.get_xticklabels()
fig.tight_layout()