Commit 3ebbb658 authored by Pierre Marijon's avatar Pierre Marijon

Module reorganisation, more logic

parent eee8aaea
......@@ -78,6 +78,7 @@ for gfa_line in p.generate_gfa():
p.graph # get an networkx graph where overlap are store
```
## Bug report
For bug report you can send e-mail to pierre.marijon@inria.fr or create [issue](https://gitlab.inria.fr/pmarijon/paf2gfa/issues)
......@@ -2,4 +2,4 @@
__version__ = "0.1"
from paf2gfa.paf2gfa import Parser
from paf2gfa.parser import Parser
import os
import sys
import time
import argparse
import paf2gfa.paf2gfa
from paf2gfa import Parser
def main(args=None):
if args is None:
args = sys.argv[1:]
paf2gfa.paf2gfa.main(args)
parser = argparse.ArgumentParser(prog="paf2gfa",
formatter_class=argparse.
ArgumentDefaultsHelpFormatter)
parser.add_argument('paf', type=argparse.FileType('r'))
parser.add_argument('gfa', type=argparse.FileType('w'))
parser.add_argument("-c", "--remove-all-containment", action='store_true',
help="Remove all containment")
parser.add_argument("-i", "--remove-all-internal", action='store_true',
help="Remove all internal match")
parser.add_argument("-p", "--progression", action='store_true',
help="Show a progress bar durring reading")
arg = vars(parser.parse_args(args))
paf = arg["paf"].name
gfa = arg["gfa"].name
rm_all_contain = arg["remove_all_containment"]
rm_all_internal = arg["remove_all_internal"]
parser = Parser(not rm_all_contain, not rm_all_internal)
file_size = os.path.getsize(paf)
last_time = time.time()
print("begin parsing")
while "read all line in file":
line = arg["paf"].readline()
if not line:
break
parser.parse_line(line)
if arg["progression"] and time.time() - last_time > 2:
parser.parse_line(line)
precent = format((arg["paf"].tell() * 100) / file_size, '.2f')
precent += "%"
sys.stdout.write(precent)
sys.stdout.write("\b" * len(precent))
sys.stdout.flush()
last_time = time.time()
print("end parsing")
print("begin writting")
for line in parser.generate_gfa():
arg["gfa"].write(line+"\n")
print("end writting")
if __name__ == "__main__":
main(sys.argv[1:])
......@@ -2,19 +2,13 @@
# -*- coding: utf-8 -*-
import re
import os
import sys
import time
import logging
import argparse
import networkx as nx
from collections import defaultdict
from types import SimpleNamespace
import networkx as nx
class Parser:
def __init__(self, containment=True, internal=True):
......@@ -53,7 +47,6 @@ class Parser:
def internal(self):
return self.__internal
@property
def graph(self):
return self.__graph
......@@ -67,7 +60,6 @@ class Parser:
if l.read_a == l.read_b:
return
self._add_segment(l.read_a, l.len_a)
self._add_segment(l.read_b, l.len_b)
......@@ -245,51 +237,3 @@ class Parser:
return min(l.beg_a, l.len_b - l.end_b) + min(l.beg_b, l.len_a - l.end_a)
def main(args):
parser = argparse.ArgumentParser(prog="paf2gfa",
formatter_class=argparse.
ArgumentDefaultsHelpFormatter)
parser.add_argument('paf', type=argparse.FileType('r'))
parser.add_argument('gfa', type=argparse.FileType('w'))
parser.add_argument("-c", "--remove-all-containment", action='store_true',
help="Remove all containment")
parser.add_argument("-i", "--remove-all-internal", action='store_true',
help="Remove all internal match")
parser.add_argument("-p", "--progression", action='store_true',
help="Show a progress bar durring reading")
arg = vars(parser.parse_args(args))
paf = arg["paf"].name
gfa = arg["gfa"].name
rm_all_contain = arg["remove_all_containment"]
rm_all_internal = arg["remove_all_internal"]
parser = Parser(not rm_all_contain, not rm_all_internal)
file_size = os.path.getsize(paf)
last_time = time.time()
print("begin parsing")
while "read all line in file":
line = arg["paf"].readline()
if not line:
break
parser.parse_line(line)
if arg["progression"] and time.time() - last_time > 2:
parser.parse_line(line)
precent = format((arg["paf"].tell() * 100) / file_size, '.2f')
precent += "%"
sys.stdout.write(precent)
sys.stdout.write("\b" * len(precent))
sys.stdout.flush()
last_time = time.time()
print("end parsing")
print("begin writting")
for line in parser.generate_gfa():
arg["gfa"].write(line+"\n")
print("end writting")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment