Skip to content
GitLab
Menu
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
ad4915a7
Commit
ad4915a7
authored
Mar 19, 2019
by
Blaise Li
Browse files
Formatting.
parent
925f3c5e
Pipeline
#10495
passed with stages
in 25 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
source/Input_Output.rst
View file @
ad4915a7
...
...
@@ -14,7 +14,7 @@ Exercise
--------
Write a function that takes the path of file as parameter
and display it's content on the screen.
and display
s
it's content on the screen.
We expect the same behavior as the shell ``cat`` command.
...
...
@@ -87,7 +87,7 @@ Write sequences with 80 aa/line
Exercise
--------
w
e ran a blast with the folowing command *blastall -p blastp -d uniprot_sprot -i query_seq.fasta -e 1e-05 -m 8 -o blast2.txt*
W
e ran a blast with the fol
l
owing command *blastall -p blastp -d uniprot_sprot -i query_seq.fasta -e 1e-05 -m 8 -o blast2.txt*
-m 8 is the tabular output. So each fields is separate to the following by a '\t'
...
...
@@ -120,7 +120,7 @@ Hint:
^^^^^
Use the module csv in python https://docs.python.org/3/library/csv.html#module-csv
u
se a reader
like be
low
::
U
se a reader
, as fol
low
s
::
>>> reader = csv.reader(input, quotechar='"')
...
...
@@ -140,6 +140,7 @@ use the file :download:`abcd.fasta <_static/data/abcd.fasta>` to test your code.
solution 1
^^^^^^^^^^
.. literalinclude:: _static/code/multiple_fasta_reader.py
:linenos:
:language: python
...
...
@@ -148,6 +149,7 @@ solution 1
solution 2
^^^^^^^^^^
.. literalinclude:: _static/code/multiple_fasta_reader2.py
:linenos:
:language: python
...
...
@@ -156,6 +158,7 @@ solution 2
solution 3
^^^^^^^^^^
.. literalinclude:: _static/code/fasta_iterator.py
:linenos:
:language: python
...
...
@@ -168,19 +171,19 @@ if the file is huge (>G0) it can be a problem.
The third version allow to red sequences one by one.
To do that we have to open the file outside the reader function
The fasta format is very convenient for human but not for parser.
The end of a sequence is indicated by the end of file or the begining of a new one.
The end of a sequence is indicated by the end of file or the begin
n
ing of a new one.
So with this version we have play with the cursor to place the cursor backward
when we encouter a new sequence.
t
hen the cursor is placed at the right place
when we encou
n
ter a new sequence.
T
hen the cursor is placed at the right place
for the next sequence.
The third version is an iterator and use generator.
g
enerators are functions which keep a state between to calls.
g
enerators do
es
not use return to return a value but the keyword yield.
Thus this implementation ret
r
un sequence by sequence without to play with the cursor.
G
enerators are functions which keep a state between to calls.
G
enerators do not use return to return a value but the keyword yield.
Thus this implementation retu
r
n sequence by sequence without to play with the cursor.
You can call this function and put in in a loop or call next.
Work with the sequence and pass to the next sequence on so on.
f
or instance which is a very convenient way to use it:
:
:
F
or instance which is a very convenient way to use it::
for seq in fasta_iter('my_fast_file.fasta'):
print seq
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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