Esempio n. 1
0
print(len(rec.features))

# SeqFeature : describes a region on a parent sequence (typically SeqRecord)
#       the region is described with a location of object (typically range between two positions)
# SeqFeature attributes : type (e.g. 'CDS', 'gene),
#                         location (includes ref, ref_db and strand),
#                         qualifiers (add. info.), sub_features (joins,later -> CompoundLocation)
# position : single position 5,10 (may be fuzzy <100, >200 e.g)
# location : region bounded by positions 5..20
# fuzzy position classes:
#       ExactPosition (5), BeforePosition (<5), AfterPosition (>5)
#       WithinPosition ((1.5)), OnOfPosition, UnknownPosition (?)

from Bio import SeqFeature
start_pos = SeqFeature.AfterPosition(5)
end_pos = SeqFeature.BetweenPosition(position=9, left=8, right=9)
loc = SeqFeature.FeatureLocation(start_pos, end_pos)
print(loc)
print(int(loc.start))
print(int(loc.end))

# iterating over features and finding out a location
from Bio import SeqIO
snp = 4350
rec = SeqIO.read("NC_005816.gb", "genbank")
for feature in rec.features:
    if snp in feature:
        print(feature.type, feature.qualifiers.get("db_xref"))

# SeqFeatures doesn't contain a sequence (it has a parent sequence)
from Bio.Seq import Seq
Esempio n. 2
0
#!/usr/bin/env python
"""Test the Location code located in SeqFeature.py

This checks to be sure fuzzy and non-fuzzy representations of locations
are working properly.
"""
from Bio import SeqFeature

# --- test fuzzy representations
print("Testing fuzzy representations...")

# check the positions alone
exact_pos = SeqFeature.ExactPosition(5)
within_pos_s = SeqFeature.WithinPosition(10, left=10, right=13)
within_pos_e = SeqFeature.WithinPosition(13, left=10, right=13)
between_pos_e = SeqFeature.BetweenPosition(24, left=20, right=24)
before_pos = SeqFeature.BeforePosition(15)
after_pos = SeqFeature.AfterPosition(40)

print "Exact:", exact_pos
print("Within (as start, %i): %s" % (int(within_pos_s), within_pos_s))
print("Within (as end, %i): %s" % (int(within_pos_e), within_pos_e))
print("Between (as end, %i): %s" % (int(between_pos_e), between_pos_e))
print "Before:", before_pos
print "After:", after_pos

# put these into Locations
location1 = SeqFeature.FeatureLocation(exact_pos, within_pos_e)
location2 = SeqFeature.FeatureLocation(before_pos, between_pos_e)
location3 = SeqFeature.FeatureLocation(within_pos_s, after_pos)
#!/usr/bin/env python
"""Test the Location code located in SeqFeature.py

This checks to be sure fuzzy and non-fuzzy representations of locations
are working properly.
"""
from Bio import SeqFeature

# --- test fuzzy representations
print "Testing fuzzy representations..."

# check the positions alone
exact_pos = SeqFeature.ExactPosition(5)
within_pos = SeqFeature.WithinPosition(10, 3)
between_pos = SeqFeature.BetweenPosition(20, 4)
before_pos = SeqFeature.BeforePosition(15)
after_pos = SeqFeature.AfterPosition(40)

print "Exact:", exact_pos
print "Within:", within_pos
print "Between:", between_pos
print "Before:", before_pos
print "After:", after_pos

# put these into Locations
location1 = SeqFeature.FeatureLocation(exact_pos, within_pos)
location2 = SeqFeature.FeatureLocation(before_pos, between_pos)
location3 = SeqFeature.FeatureLocation(within_pos, after_pos)

for location in [location1, location2, location3]:
    print "Location:", location