Commit 2e85f95b by Bertrand NÉRON

fix typos

parent 9cd31ca1
 ... @@ -170,7 +170,11 @@ from the list l = [1, 2, 3, 4, 5, 6, 7, 8, 9] generate 2 lists l1 containing all ... @@ -170,7 +170,11 @@ from the list l = [1, 2, 3, 4, 5, 6, 7, 8, 9] generate 2 lists l1 containing all l1 = l[::2] l1 = l[::2] l2 = l[1::2] l2 = l[1::2] or :: even = [item for item in l if item % 2 == 0] odd = [item for item in l if item % 2 != 0] Exercise Exercise -------- -------- ... @@ -253,7 +257,7 @@ implementation: ... @@ -253,7 +257,7 @@ implementation: >>> uniqify(l) >>> uniqify(l) [1, 2, 3, 4, 5, 7, 8, 9] [1, 2, 3, 4, 5, 7, 8, 9] :download:`codons_itertools.py <_static/code/codons_itertools.py>` . :download:`uniqify.py <_static/code/uniqify.py>` . second implementation: second implementation: """""""""""""""""""""" """""""""""""""""""""" ... @@ -262,7 +266,7 @@ The problem with the first implementation come from the line 4. ... @@ -262,7 +266,7 @@ The problem with the first implementation come from the line 4. Remember that the membership operator uses a linear search for list, which can be slow for very large collections. Remember that the membership operator uses a linear search for list, which can be slow for very large collections. If we plan to use ``uniqify`` with large list we should find a better algorithm. If we plan to use ``uniqify`` with large list we should find a better algorithm. In the specification we can read that uniqify can work *regardless the order of the resulting list*. In the specification we can read that uniqify can work *regardless the order of the resulting list*. So we can use the specifycity of set :: So we can use the specificity of set :: >>> list(set(l)) >>> list(set(l)) ... @@ -330,13 +334,13 @@ Compare the pseudocode of each of them and implement the fastest one. :: ... @@ -330,13 +334,13 @@ Compare the pseudocode of each of them and implement the fastest one. :: acggcaacatggctggccagtgggctctgagaggagaaagtccagtggatgctcttggtctggttcgtgagcgcaacaca""" acggcaacatggctggccagtgggctctgagaggagaaagtccagtggatgctcttggtctggttcgtgagcgcaacaca""" In the first alogrithm. In the first algorithm. | we first compute all kmers we generate 4\ :sup:`kmer length` | we first compute all kmers we generate 4\ :sup:`kmer length` | then we count the occurence of each kmer in the sequence | then we count the occurrence of each kmer in the sequence | so for each kmer we read all the sequence so the algorith is in O( 4\ :sup:`kmer length` * ``sequence length``) | so for each kmer we read all the sequence so the algorithm is in O( 4\ :sup:`kmer length` * ``sequence length``) | In the secon algorithm we read the sequence only once | In the second algorithm we read the sequence only once | So the algorithm is in O(sequence length) | So the algorithm is in O(sequence length) ... @@ -441,14 +445,14 @@ pseudocode: ... @@ -441,14 +445,14 @@ pseudocode: other solution other solution """""""""""""" """""""""""""" python provide an interresting method for our problem. python provide an interesting method for our problem. The ``translate`` method work on string and need a parameter which is a object The ``translate`` method work on string and need a parameter which is a object that can do the correspondance between characters in old string a the new one. that can do the correspondance between characters in old string a the new one. ``maketrans`` is a function in module ``string`` that allow us to build this object. ``maketrans`` is a function in module ``string`` that allow us to build this object. ``maketrans`` take 2 arguments, two strings, the first string contains the characters ``maketrans`` take 2 arguments, two strings, the first string contains the characters to change, the second string the corresponding characters in the new string. to change, the second string the corresponding characters in the new string. Thus the two strings **must** have the same lenght. The correspondance between Thus the two strings **must** have the same length. The correspondance between the characters to change and their new values is made in funtion of thier position. the characters to change and their new values is made in function of their position. the first character of the first string will be replaced by the first character of the second string, the first character of the first string will be replaced by the first character of the second string, the second character of the first string will be replaced by the second character of the second string, on so on. the second character of the first string will be replaced by the second character of the second string, on so on. So we can write the reverse complement without loop. So we can write the reverse complement without loop. ... ...
 ... @@ -7,6 +7,6 @@ def get_kmer_occurences(seq, kmer_len): ... @@ -7,6 +7,6 @@ def get_kmer_occurences(seq, kmer_len): kmers = {} kmers = {} stop = len(seq) - kmer_len stop = len(seq) - kmer_len for i in range(stop + 1): for i in range(stop + 1): kmer = s[i : i + kmer_len] kmer = seq[i: i + kmer_len] kmers[kmer] = kmers.get(kmer, 0) + 1 kmers[kmer] = kmers.get(kmer, 0) + 1 return kmers.items() return kmers.items() \ No newline at end of file
 import collections import collections from operator import itemgetter from operator import itemgetter def get_kmer_occurences(seq, kmer_len): def get_kmer_occurences(seq, kmer_len): """ """ return a list of tuple return a list of tuple ... @@ -9,9 +10,8 @@ def get_kmer_occurences(seq, kmer_len): ... @@ -9,9 +10,8 @@ def get_kmer_occurences(seq, kmer_len): kmers = collections.defaultdict(int) kmers = collections.defaultdict(int) stop = len(seq) - kmer_len stop = len(seq) - kmer_len for i in range(stop + 1): for i in range(stop + 1): kmer = s[i : i + kmer_len] kmer = seq[i: i + kmer_len] kmers[kmer] += 1 kmers[kmer] += 1 kmers = kmers.items() kmers = kmers.items() kmers.sort(key = itemgetter(1), reverse =True) kmers.sort(key=itemgetter(1), reverse=True) return kmers return kmers \ No newline at end of file
 ... @@ -4,10 +4,10 @@ def rev_comp(seq): ... @@ -4,10 +4,10 @@ def rev_comp(seq): return the reverse complement of seq return the reverse complement of seq the sequence must be in lower case the sequence must be in lower case """ """ complement = {'a' : 't', complement = {'a': 't', 'c' : 'g', 'c': 'g', 'g' : 'c', 'g': 'c', 't' : 'a'} 't': 'a'} rev_seq = seq[::-1] rev_seq = seq[::-1] rev_comp = '' rev_comp = '' for nt in rev_seq: for nt in rev_seq: ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!