Example #1
0
 def parse(self, edge_ids=None):
     # type: (Optional[Dict[int, List[str]]]) -> Generator[Tuple[int, int, int, int, EdgeInfo]]
     for s in self.dot.readlines():
         if s.find("->") == -1:
             continue
         v_from = basic.parseNumber(s)
         v_to = basic.parseNumber(s, s.find("->"))
         eid = basic.parseNegativeNumber(s, s.find("id"))
         len = basic.parseNegativeNumber(s, s.find("\\l"))
         cov = basic.parseNumber(s, s.find("k "))
         unique = (s.find("black") != -1)
         src = (s.find("dir = both") != -1)
         if edge_ids is None or eid in edge_ids:
             if edge_ids is not None:
                 if "sink" in edge_ids[eid]:
                     v_to = "sink"
                 if "source" in edge_ids[eid]:
                     v_from = "source"
             yield eid, v_from, v_to, cov, EdgeInfo(s, unique, cov, len,
                                                    src)
Example #2
0
 def FillSeq(self, f, numeric=True):
     for s in SeqIO.parse_fasta(open(f, "r")):
         if numeric:
             s.id = str(basic.parseNumber(s.id))
         if s.id in self.e:
             self.e[s.id].seq = s.seq
             self.e[s.id].len = len(s.seq)
         if "-" + s.id in self.e:
             self.e["-" + s.id].seq = basic.RC(s.seq)
             self.e["-" + s.id].len = len(s.seq)
     return self
Example #3
0
 def __init__(self, dir, clean=False):
     # type: (str, bool) -> None
     self.dir = dir
     if clean:
         basic.recreate(self.dir)
     else:
         basic.ensure_dir_existance(self.dir)
     self.cnt = 0
     for name in os.listdir(self.dir):
         num = basic.parseNumber(name)
         if num is not None and num >= self.cnt:
             self.cnt = num + 1
Example #4
0
 def FillSeq(self, f, numeric=True):
     for s in SeqIO.parse_fasta(open(f, "r")):
         if numeric:
             s.id = str(basic.parseNumber(s.id))
         if s.id in self.e:
             self.e[s.id].seq = s.seq
             self.e[s.id].len = len(s.seq)
         if basic.Reverse(s.id) in self.e:
             self.e[basic.Reverse(s.id)].seq = basic.RC(s.seq)
             self.e[basic.Reverse(s.id)].len = len(s.seq)
     for edge in self.e.values():
         assert (edge.seq is not None)
     return self
Example #5
0
 def ReadDot(self, f):
     for s in open(f, "r").readlines():
         tmp = s
         if s[0] != "\"":
             continue
         s = s.strip().split()
         if len(s) < 2 or s[1] != "->":
             vid = s[0][1:-1]
             self.AddVertex(vid, tmp)
             continue
         v_from = s[0][1:-1]
         v_to = s[2][1:-1]
         label = tmp
         cov = basic.parseNumber(tmp, tmp.find("k "))
         l = int(float(tmp[tmp.find("\\l") + 2:tmp.find("k ")]) * 1000)
         id = tmp[tmp.find("id ") + 3:tmp.find("\\l")]
         edge = self.AddEdge(id, v_from, v_to, l, label, cov)
     return self
Example #6
0
import sys
sys.path.append("py")
from common import basic

ll = []
start = False
for s in open(sys.argv[1], "r").readlines():
    if s.startswith("New depth 24218"):
        start = True
    if not start:
        continue
    if s.startswith("Tail"):
        continue
    if s.startswith("New tails"):
        break
    if s.find("Fail") != -1:
        ll = []
    elif s.find("success") != -1:
        call = basic.parseNumber(s)
        for tmp in map(eval, ll):
            if tmp[call] < tmp[1 - call]:
                print min(tmp), max(tmp), 0
            else:
                print min(tmp), max(tmp), 1
        ll = []
    elif s.find("[") != -1:
        ll.append(s.strip())

import os
import shutil
import sys

from common import basic

in_dir = sys.argv[1]
out_dir = sys.argv[2]
basic.ensure_dir_existance(out_dir)
for f in os.listdir(in_dir):
    fig_dir = os.path.join(in_dir, f, "pictures")
    cur = 0
    nums = map(basic.parseNumber, os.listdir(fig_dir))
    last = max(*nums)
    f_name = None
    for f in os.listdir(fig_dir):
        if basic.parseNumber(f) == last:
            f_name = f
            break
    shutil.copy(os.path.join(fig_dir, f_name),
                os.path.join(out_dir, f + ".dot"))