PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/burn_treefile.py

https://github.com/carlosp420/my_scripts
Python | 39 lines | 27 code | 8 blank | 4 comment | 6 complexity | ccac489e3fef6fca90752e08eddf25b9 MD5 | raw file
  1. #!/usr/bin/python
  2. ## It takes a file.trees output from BEAST and does a burnin
  3. ## script.py burnin input.trees output.trees
  4. import sys;
  5. import re;
  6. if len(sys.argv) < 4:
  7. print "You need more arguments";
  8. print "Usage: script.py burnin input.trees output.trees";
  9. print "burnin has to be the number of trees to burn\n";
  10. sys.exit();
  11. try:
  12. a = int(sys.argv[1]);
  13. except:
  14. print "Your burnin has to be a number";
  15. exit(1);
  16. burnin = int(sys.argv[1]);
  17. print "Burning ", burnin, " trees";
  18. inputfile = open(sys.argv[2], "r");
  19. outputfile = open(sys.argv[3], "w");
  20. i = 0;
  21. # read trees and fwrite them without the burned trees
  22. for line in inputfile:
  23. m = re.search('^tree STATE', line);
  24. if(m != None):
  25. i += 1;
  26. if ( i > burnin ):
  27. outputfile.write(line);
  28. else:
  29. outputfile.write(line);
  30. inputfile.close();
  31. outputfile.close();