-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
55 lines (49 loc) · 1.94 KB
/
plot.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import sys
import subprocess
import math
def plot(x_name, y_name, x_len, y_len, kmer_size, f_file, b_file, out_file, draw_tics=True, draw_labels=True, linear_scale=False, color=False):
cmd = 'gnuplot -e "'
cmd += 'set x2range [0 : %d];' % x_len
cmd += 'set yrange [%d : 0];' % y_len
cmd += 'unset key;'
cmd += 'unset ytics;'
if draw_tics:
cmd += 'set x2tics %d;' % 10000
cmd += 'set ytics %d;' % 10000
cmd += 'set mx2tics 5;'
cmd += 'set mytics 5;'
cmd += 'set tics out;'
cmd += 'set tics scale 1.5, 0.5;'
cmd += 'set x2tics offset 0, -0.5;'
cmd += 'set ytics offset 0.8, 0;'
if draw_labels:
cmd += "set x2label '%s';" % x_name.replace('_', '\_')
cmd += "set ylabel '%s';" % y_name.replace('_', '\_')
cmd += 'set x2label offset 0, -0.8;'
cmd += 'set ylabel offset 2.0, 0;'
cmd += "set label 'k-mer size = %d' at screen 0.01, 0.98 ;" % kmer_size
cmd += 'unset xtics;'
if linear_scale:
x_size = x_len / 100
y_size = y_len / 100
else:
if x_len > y_len:
x_size = 100 * math.log(x_len, 2)
y_size = x_size * y_len / x_len
else:
y_size = 100 * math.log(y_len, 2)
x_size = y_size * x_len / y_len
cmd += 'set size ratio %f;' % (float(y_len) / x_len)
cmd += 'set terminal png size %d, %d;' % (x_size, y_size)
cmd += "set output '%s';" % out_file
if color:
cmd += "plot '%s' w p ps 0.15 lc rgb 'red', '%s' w p ps 0.15 lc rgb 'dark-green';" % (f_file, b_file)
else:
if not os.path.exists(f_file) or not os.path.exists(b_file):
sys.exit('Cannot find match files. Exit')
cat_cmd = 'tail -n +2 %s >> %s' % (b_file, f_file)
subprocess.check_call(cat_cmd, shell=True)
cmd += "plot '%s' w p ps 0.15 lc rgb 'black';" % f_file
cmd += '"'
subprocess.check_call(cmd, shell=True)