-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsummary_to_wiki.py
executable file
·54 lines (41 loc) · 1.78 KB
/
summary_to_wiki.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
#!/usr/bin/env python3
### Note: This script is unlikely to be useful outside of Edinburgh Genomics ###
import os, sys, re
"""A simple script. Reads the 10000targets_all_lanes.txt summary text file
as generated by the Snakefile and spits it out as wiki markup for Confluence.
Note the file is actually created by running 'tail' on the individual results
which is where the ==> Headings <== comes from.
I could make the code output Wiki markup directly but I don't want to have
that in the scripts, so this is done in the style of old school "perl -p"
regex-powered munging.
"""
def munge(line):
header_mo = re.search(r"==> [\w/]*?(\d+)targets_lane(\d+)([TB]?)\.txt <==", line)
if header_mo:
return "h3. %s targets per tile on lane %s%s" % header_mo.groups()
sum_mo = re.match(r"LaneSummary:.*(Tiles:.*)", line)
if sum_mo:
return re.sub(r"\t", r" ", sum_mo.group(1))
lev1_mo = re.match("Level: 1\s", line)
if lev1_mo:
headings = [i.split(": ")[0] for i in line.split("\t")]
return "||".join([""] + headings + [""]) + "\n" + fmtline(line)
levn_mo = re.match("Level:", line)
if levn_mo:
return fmtline(line)
def fmtline(line):
"""Formats a Level:.* line
On line 1, hilights the last box, as that's the figure we care about
"""
levn_mo = re.match("Level: (\d+)", line)
vals = [i.split(": ",1)[1] for i in line.split("\t")]
if levn_mo.group(1) == '1':
vals[-1] = "{color:red}%s{color}" % vals[-1]
return "|".join([""] + vals + [""])
if __name__ == '__main__':
#pipeline mode
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE,SIG_DFL)
for line in (x.rstrip("\n") for x in sys.stdin):
munged = munge(line)
if munged is not None: print(munged)