Commit b1a46e75 authored by MARIJON Pierre's avatar MARIJON Pierre

add option to choose the path search mode

parent ed5b112d
......@@ -10,7 +10,7 @@ rule build_AGG:
"{prefix}_AAG.csv"
shell:
"python -m knot.path_search {input.search} {output} {input.ovl_graph} {input.read2asm} {input.asm_graph} {input.tig2tig}"
"python -m knot.path_search {input.search} {output} {input.ovl_graph} {input.read2asm} {input.asm_graph} {input.tig2tig} --search-mode " + config["search_mode"]
rule filter_contigs:
input:
......
......@@ -35,6 +35,8 @@ def main(args = None):
parser.add_argument("-o", "--output", required=True,
help="output prefix")
parser.add_argument("--search-mode", choices=["base", "node"], default="base",
help="what path search optimize, number of base or number of node")
parser.add_argument("--contig-min-length", default=100000, type=int,
help="contig with size lower this parameter are ignored")
parser.add_argument("--read-type", choices=["pb", "ont"], default="pb",
......@@ -50,7 +52,7 @@ def main(args = None):
parser.print_help()
snakemake_help()
return 1
## if contig graph isn't set generate empty file
if args["contigs_graph"] is None:
args["contigs_graph"] = tempfile.NamedTemporaryFile(delete=False).name
......@@ -65,6 +67,7 @@ def main(args = None):
"contigs_graph="+args["contigs_graph"],
"read_type="+args["read_type"],
"min_contig_length="+str(args["contig_min_length"]),
"search_mode="+args["search_mode"],
"package_path="+package_path
]
......
......@@ -37,6 +37,8 @@ def main(args=None):
parser.add_argument("read2asm", type=argparse.FileType('r'))
parser.add_argument("asm_graph", type=argparse.FileType('r'))
parser.add_argument("tig2tig", type=argparse.FileType('r'))
parser.add_argument("--search-mode", choices=["base", "node"], default="base",
help="what path search optimize, number of base or number of node")
args = vars(parser.parse_args(args))
......@@ -47,7 +49,6 @@ def main(args=None):
# get info about contig
valid_read = extremity_search.get_valid_read(args["ovl_graph"])
tig2reads = {tig[0]: {v[2] for v in val} for tig, val in extremity_search.get_tig2posread(args["read2asm"], valid_read).items()}
# build list of search
tig_ext = list()
......@@ -72,7 +73,7 @@ def main(args=None):
print(ext1[0], node1, ext2[0], node2, 0, 0, "not_search", "not_search", sep=",", file=args["result"])
continue
(path, weight) = paths.get_path(sg, node1, node2)
(path, weight) = paths.get_path(sg, node1, node2, args["search_mode"])
if path:
nbread_contig = paths.format_node_contig_counter(
paths.path_through_contig(tig2reads, path),
......
......@@ -5,10 +5,13 @@ from collections import Counter
# pip import
import networkx as nx
def get_path(graph, n1, n2):
def get_path(graph, n1, n2, mode="base"):
try:
path = nx.shortest_path(graph, n1, n2, weight="weight")
if mode == "base":
path = nx.shortest_path(graph, n1, n2, weight="weight")
else:
path = nx.shortest_path(graph, n1, n2)
except nx.exception.NetworkXError as e:
logging.debug("Networkx exception"+str(e))
path = []
......@@ -18,8 +21,8 @@ def get_path(graph, n1, n2):
except nx.exception.NodeNotFound as e:
logging.debug("Node not found exception "+str(e))
path = []
return path, sum([graph.edges[x, y]["weight"] for x, y in zip(path, path[1:])])
return path, sum([graph.edges[x, y]["weight"] for x, y in zip(path, path[1:])])
def path_through_contig(tig2reads, path):
tig2nb_read = Counter()
......
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