Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hub-courses
python_one_week_4_biologists_solutions
Commits
124f0e8a
Commit
124f0e8a
authored
Feb 18, 2016
by
Bertrand Néron
Browse files
add gc_percent in Sequence and use it
parent
e1e73d4c
Changes
1
Hide whitespace changes
Inline
Side-by-side
source/_static/code/fasta_object.py
View file @
124f0e8a
...
...
@@ -5,6 +5,9 @@ class Sequence(object):
self
.
comment
=
comment
self
.
sequence
=
sequence
def
gc_percent
(
self
):
seq
=
self
.
sequence
.
upper
()
return
float
(
seq
.
count
(
'G'
)
+
seq
.
count
(
'C'
))
/
float
(
len
(
seq
))
class
FastaParser
(
object
):
...
...
@@ -73,4 +76,5 @@ if __name__ == '__main__':
fasta_parser
=
FastaParser
(
fasta_path
)
for
sequence
in
fasta_parser
:
print
"----------------"
print
sequence
.
id
\ No newline at end of file
print
"{seqid} = {gc:.3%}"
.
format
(
gc
=
sequence
.
gc_percent
(),
seqid
=
sequence
.
id
)
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment