File: sens_vs_spec.py

package info (click to toggle)
seqprep 1.3.2-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 64,480 kB
  • sloc: ansic: 2,432; python: 165; sh: 89; makefile: 39
file content (93 lines) | stat: -rw-r--r-- 2,841 bytes parent folder | download | duplicates (4)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/python3
from glob import iglob as glob
from operator import itemgetter
flist = glob("trimmed_*.txt")
sensdict = dict()
specdict = dict()
xpoints = []
ypoints = []

for fn in flist:
    f = open(fn,'r')
    parts = fn.split("_")
    res_parts = parts[1:-1]
    res_parts.append(parts[-1][:-4]) #remove .txt
    res_parts2 = [ x[0]+":"+x[1:] for x in res_parts]
    rname = '_'.join(res_parts2)
    for line in f:
        if line.startswith("Adapter Trimming Specificity:"):
            spec = float(line.split()[-1])
            xpoints.append(spec)
            specdict[rname] = spec
        elif line.startswith("Adapter Trimming Sensitivity:"):
            sens = float(line.split()[-1])
            ypoints.append(sens)
            sensdict[rname] = sens
    f.close()


outf =  open('spec_sorted_results.txt','w')
colnames = []
rowdata = []
outf.write("#Fname\tSpecificity\tSensitivity\n")
total = len(list(specdict.items()))
num = 1
for (fname,spec) in sorted(list(specdict.items()),key=itemgetter(1),reverse=True):
    colnames.append("data.addColumn('number','%s');"%(fname))
    sens = sensdict[fname]
    rowarr = [str(sens)]
    for x in range(1,total+1):
        if x == num:
            rowarr.append(str(spec))
        else:
            rowarr.append("null")
    rowdata.append("data.addRow([%s]);" %(", ".join(rowarr)))
    outf.write("%s\t%f\t%f\n"%(fname,spec,sens))
    num += 1
outf.close()

outf = open("result.html","w")


goog_head = '''
<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawVisualization);
      function drawVisualization() {
          // Create and populate the data table.
          var data = new google.visualization.DataTable();
          data.addColumn('number', 'Sensitivity');
          %s
          %s

          // Create and draw the visualization.
          var chart = new google.visualization.ScatterChart(
          document.getElementById('visualization'));
          chart.draw(data, {title: 'Adapter Removal With Different Settings',
              width: 800, height: 800,
              vAxis: {title: "Adapter Specificity",
                  //minValue: 0.8,
                  //maxValue: 1,
                  titleTextStyle: {color: "green"}},
              hAxis: {title: "Adapter Sensitivity",
                  //minValue: 0.8,
                  //maxValue: 1,
                  titleTextStyle: {color: "green"}},          pointSize: 4,       
              legend: 'none'}
           );
      }
    </script>
  </head>

  <body>
    <div id="visualization"></div>
  </body>
</html>
''' % ("\n          ".join(colnames),"\n          ".join(rowdata))

outf.write(goog_head)
outf.close()