Skip to content

Instantly share code, notes, and snippets.

@cybersiddhu
Forked from ypandit/pseudogene_issue.py
Created April 27, 2012 23:54
Show Gist options
  • Save cybersiddhu/2514401 to your computer and use it in GitHub Desktop.
Save cybersiddhu/2514401 to your computer and use it in GitHub Desktop.
Solution for pseudogene issue in GFF3 for Artemis
import sys, os, string
if len(sys.argv) != 2:
print 'You seem to have forgotten to provide the input GFF3 file.'
exit()
if __name__ == "__main__":
found = False
with open(sys.argv[1], 'r') as file:
outfile = open(os.path.basename(sys.argv[1]).replace(".gff", "_corrected.gff"), 'w')
for line in file:
if found and ('exon' in line):
found = False
continue
if 'pseudogene' in line:
found = True
continue
if 'gap' in line:
continue
outfile.write(line)
outfile.close()
@cybersiddhu
Copy link
Author

Try to avoid reading entire file in memory. So instead of this ...

lines = files.readlines()

try this

file = open('file.txt','r')
for line in file:
  blah blah.....

Even better

with open('file', 'r') as file:
   for line in file:
     blah blah .....

Consult the python standard documentation for the advantage of using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment