my_scripts /burn_treefile.py

Language Python Lines 40
MD5 Hash ccac489e3fef6fca90752e08eddf25b9 Estimated Cost $609 (why?)
Repository https://github.com/carlosp420/my_scripts.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python

## It takes a file.trees output from BEAST and does a burnin
## script.py burnin input.trees output.trees

import sys;
import re;

if len(sys.argv) < 4:
	print "You need more arguments";
	print "Usage: script.py burnin input.trees output.trees";
	print "burnin has to be the number of trees to burn\n";
	sys.exit();

try:
	a = int(sys.argv[1]);
except:
	print "Your burnin has to be a number";
	exit(1);

burnin = int(sys.argv[1]);
print "Burning ", burnin, " trees";

inputfile = open(sys.argv[2], "r");
outputfile = open(sys.argv[3], "w");

i = 0;
# read trees and fwrite them without the burned trees
for line in inputfile:
	m = re.search('^tree STATE', line);
	if(m != None):
		i += 1;
		if ( i > burnin ): 
			outputfile.write(line);
	else:
		outputfile.write(line);

inputfile.close();
outputfile.close();
Back to Top