Commit b6a1787a authored by MARIJON Pierre's avatar MARIJON Pierre

Filter tig extermity if isn't in canu contig

parent de55e564
......@@ -5,6 +5,7 @@ canu_project_name = config["project_name"]
canu_unitigs = os.path.join(in_path, canu_project_name + ".unitigs")
canu_contigs = os.path.join(in_path, canu_project_name + ".contigs")
canu_read2tig = os.path.join(in_path, canu_project_name + ".contigs.layout.readToTig")
canu_tigInfo = os.path.join(in_path, canu_project_name + ".contigs.layout.tigInfo")
canu_gkp_store = os.path.join(in_path, "unitigging", canu_project_name + ".gkpStore")
canu_ovl_store = os.path.join(in_path, "unitigging", canu_project_name + ".ovlStore")
canu_bog = os.path.join(in_path, "unitigging", "4-unitigger", canu_project_name + ".best.edges")
......
import os
import itertools
import csv
from collections import Counter, defaultdict
def project_name(dir_path):
......@@ -69,10 +69,18 @@ def read_contig_layout(filename):
return read2info, tig2extremity
def generate_output_extract_graph(contig_layout, read_names, prefix):
def keep_tig(canu_tig_info):
with open(canu_tig_info) as fh:
reader = csv.DictReader(fh, delimiter="\t")
for row in reader:
if row["tigClass"] == "contig":
yield row["#tigID"]
def generate_output_extract_graph(contig_layout, read_names, tigInfo, prefix):
read2info, tig2extremity = read_contig_layout(contig_layout)
id2name = parse_canu_read_name(read_names)
keep_tigs = set(keep_tig(tigInfo))
tig2ext_filter = {k: (a, b) for k, (a, b) in tig2extremity.items() if a != b}
search_path = prefix + "_extremity_search.csv"
......@@ -85,6 +93,9 @@ def generate_output_extract_graph(contig_layout, read_names, prefix):
if tigA == tigB :
continue
if tigA not in keep_tigs or tigB not in keep_tigs:
continue
read_a_beg = id2name[tig2ext_filter[tigA][0]]
read_b_beg = id2name[tig2ext_filter[tigB][0]]
read_a_end = id2name[tig2ext_filter[tigA][1]]
......
......@@ -64,6 +64,6 @@ rule generate_search_path:
search = "{prefix}_{name}_extremity_search.csv"
run:
if wildcards.name == "canu":
canu_utils.generate_output_extract_graph(canu_read2tig, canu_bog_readname, canu_search_path_prefix)
canu_utils.generate_output_extract_graph(canu_read2tig, canu_bog_readname, canu_tigInfo, canu_search_path_prefix)
else:
canu_utils.generate_output_extract_graph(canu_read2tig, canu_bog_readname, minimap_search_path_prefix)
canu_utils.generate_output_extract_graph(canu_read2tig, canu_bog_readname, canu_tigInfo, minimap_search_path_prefix)
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