Created
December 20, 2013 16:22
-
-
Save learner-long-life/8057238 to your computer and use it in GitHub Desktop.
Supposed improvement in Python file-reading speed, submitted by one of my students
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inputfile = open(filename) | |
#... | |
# I swear enumerate() makes this faster. | |
for i, line in enumerate(inputfile): | |
if readnext == True: # Previous line started with an '@' | |
# linescounted += 1 # For line count check. | |
for bp in line.rstrip(): | |
if bp == 'G': | |
total_count += 1 # Increment total count on valid counts | |
g_count += 1 | |
elif bp == 'C': | |
total_count += 1 | |
c_count += 1 | |
elif bp == 'A': | |
total_count += 1 | |
a_count += 1 | |
elif bp == 'T': | |
total_count += 1 | |
t_count += 1 | |
elif count_invalid == True: | |
total_count += 1 # Increment total count on invalid counts | |
seq_count += 1 | |
readnext = False | |
elif readnext == False and line[0] == '@': # Read first character of line. | |
readnext = True # Count pairs in next line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment