Differences

This shows you the differences between two versions of the page.

part6 [2009/05/12 11:19]
nuin created
part6 [2010/02/11 05:21] (current)
newacct
Line 158: Line 158:
    start = False     start = False
    for line in file:     for line in file:
-        if line.find('Rich Roberts') >= 0:+        if 'Rich Roberts' in line:
            start = True             start = True
            line = file.next()             line = file.next()
-        if start == True and len(line) > 10:</code>+        if start and len(line) > 10:</code>
where we already declared the dictionary that will receive the name and sites. We have a flag boolean that tells the script where the actual enzyme list starts (//start//), declared as false and then modified to true when the line containing //Rich Roberts// is found. The line //line = file.next()// tells the script that the current line is equal to the next line of the file. We do this to avoid starting the parsing of the file at the line we found //Rich Roberts//. the //if// statement checks for the line size in order to split and parse only the actual lines and discard empty ones. where we already declared the dictionary that will receive the name and sites. We have a flag boolean that tells the script where the actual enzyme list starts (//start//), declared as false and then modified to true when the line containing //Rich Roberts// is found. The line //line = file.next()// tells the script that the current line is equal to the next line of the file. We do this to avoid starting the parsing of the file at the line we found //Rich Roberts//. the //if// statement checks for the line size in order to split and parse only the actual lines and discard empty ones.
Line 178: Line 178:
    start = False     start = False
    for line in file:     for line in file:
-        if line.find('Rich Roberts') >= 0:+        if 'Rich Roberts' in line:
            start = True             start = True
            line = file.next()             line = file.next()
-        if start == True and len(line) > 10:+        if start and len(line) > 10:
            buffer = line.split()             buffer = line.split()
            resenz[buffer[0]] = buffer[-1].replace('^', '')</code>             resenz[buffer[0]] = buffer[-1].replace('^', '')</code>
Line 234: Line 234:
    start = False     start = False
    for line in file:     for line in file:
-        if line.find('Rich Roberts') >= 0:+        if 'Rich Roberts' in line:
            start = True             start = True
            line = file.next()             line = file.next()
-        if start == True and len(line) > 10:</pre>+        if start and len(line) > 10:</pre>
            buffer = line.split()             buffer = line.split()
            resenz[buffer[0]] = buffer[-1].replace('^', '')             resenz[buffer[0]] = buffer[-1].replace('^', '')
Line 263: Line 263:
<code python>def check_enzyme(input, set): <code python>def check_enzyme(input, set):
-    if set.has_key(input): +    return input in set</code>
-        return True +
-    else: +
-        return False</code>+
This basically tests of the dictionary contains the name entered. If yes then we return True, otherwise False is returned. This changes our main script body This basically tests of the dictionary contains the name entered. If yes then we return True, otherwise False is returned. This changes our main script body
Line 355: Line 352:
        sites, positions = find_sites(enzyme, enzymeset, item.sequence)         sites, positions = find_sites(enzyme, enzymeset, item.sequence)
        print item.name[:20]+'...'         print item.name[:20]+'...'
-        for i in zip(sites, positions): +        for a,b in zip(sites, positions): 
-            print i[0], '->', i[1]+            print a, '->', b
else: else:
    print 'Enzyme name not found, please try again'</code>     print 'Enzyme name not found, please try again'</code>
 
part6.txt · Last modified: 2010/02/11 05:21 by newacct
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki