-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathsolution_91.py
More file actions
83 lines (64 loc) · 2.91 KB
/
Copy pathsolution_91.py
File metadata and controls
83 lines (64 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Exercise 9.1
# 1. For this and the following exercises we will work only with
# the **first accession**.
# Retrieve the sequence record for the first accession from Genbank
# using `Bio.Entrez`. Keep this record as a new variable.
from Bio import Entrez
from Bio import SeqIO
accession_id = "MT385458.1"
Entrez.email = "A.N.example@institute.ch"
handle = Entrez.efetch(db="nucleotide", id=accession_id, rettype="gb", retmode="text")
rec = SeqIO.read(handle, "genbank")
handle.close()
# What is the `id`, `name` and `description` of this record?
print("ID={}\nName={}\nDescription={}".format(rec.id, rec.name, rec.description))
# Confirm that the ID of this record matches the first accession in the
# accessions text file. Based on these information, can you guess in which
# country this isolate was identified?
print("Accession IDs do match:", rec.id == accession_id)
print("Country of origin could be", rec.description.split("/")[2])
# 2. How many entries are there in the `annotations` of this record?
print("There are", len(rec.annotations), "annotations associated with this record")
# Print the 'taxonomy' and the 'references' of this record. What is the title
# of the publication this sequence was published?
print(rec.annotations["taxonomy"])
print(rec.annotations["references"])
print()
print("Method of submission:", rec.annotations["references"][0].title)
# 3. How many entries are there in the `features` of this record?
# Print the first feature.
print("There are", len(rec.features), "features")
print(rec.features[0])
# This is a 'source' feature and usually there is a single 'source' feature
# for a record. It holds like the 'annotations' very useful information about
# the source of this record. Can you confirm the country of origin?
print(
"The place of origin for this isolate is",
rec.features[0].qualifiers["geo_loc_name"][0],
)
# How many different possible values are there for the `type` of these
# features and what are they?
# Using a list.
feature_types = []
for feature in rec.features:
if feature.type not in feature_types:
feature_types.append(feature.type)
print("There are {} different values for feature types".format(len(feature_types)))
print(feature_types)
# Optional - alternative using set
feature_types_set = set([feature.type for feature in rec.features])
print("There are {} different values for feature types".format(len(feature_types_set)))
print(feature_types_set)
# Can you spot the differences between the list and set versions?
# Sets are very useful counters to hold unique members
# Try help(set)
# How many 'gene's does this viral genome have, according to the features?
# How many 'CDS's are defined in the features? Are the number of genes and
# CDSs same?
# *Hint*, dictionaries can be used to count multiple things within a single
# loop.
counter = {"CDS": 0, "gene": 0}
for feature in rec.features:
if feature.type in counter:
counter[feature.type] += 1
print(counter)