-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtigmint-ntlink-map
executable file
·65 lines (54 loc) · 2.85 KB
/
tigmint-ntlink-map
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
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
"""
Helper script for running ntLink, followed by creation of the molecule extents file
@author: Lauren Coombe
"""
import argparse
import shlex
import subprocess
def run_ntlink_pair(args):
"Run ntLink pair stage to obtain PAF-formatted mappings"
command = f"ntLink pair target={args.target}.fa reads={args.reads} " \
f"paf=True k={args.k} w={args.w} t={args.t} sensitive=True"
command_shlex = shlex.split(command)
return_code = subprocess.call(command_shlex)
assert return_code == 0
def run_tigmint_filter_paf(args):
"Run tigmint-filter-paf to filter and convert PAF file to BED format"
script_loc = "tigmint-filter-paf"
if args.path:
script_loc = f"{args.path}/{script_loc}"
command_1_shlex = shlex.split(f"{script_loc} -m {args.m} {args.target}.fa.k{args.k}.w{args.w}.z1000.paf")
command_2_shlex = shlex.split("sort -k1,1 -k2,2n -k3,3n")
with open(args.bed, "wb") as outfile:
process_1 = subprocess.Popen(command_1_shlex, stdout=subprocess.PIPE)
process_2 = subprocess.Popen(command_2_shlex, stdin=process_1.stdout, stdout=outfile)
process_1.wait()
process_2.wait()
assert process_1.returncode == 0
assert process_2.returncode == 0
def main():
"Run ntLink mapping, then output filtered, sorted BED file with mapping extents"
parser = argparse.ArgumentParser(description="Run ntLink mapping, then output a filtered "
"and sorted BED file with mapping extents")
parser.add_argument("target", help="Draft assembly to scaffold")
parser.add_argument("reads", help="Long reads file")
parser.add_argument("--bed", help="Name for output BED file with mapping extents",
required=True, type=str)
parser.add_argument("-k", help="K-mer size (bp)", required=True, type=int)
parser.add_argument("-w", help="Window size", required=True, type=int)
parser.add_argument("-t", help="Number of threads [4]", default=4, type=int)
parser.add_argument("--path", help="Path to directory with tigmint-fiter-paf executable, "
"if not in PATH", type=str)
parser.add_argument("-m", help="Minimum size for mapping block (bp) [2000]", default=2000, type=int)
parser.add_argument("--span", help="Span value specified for tigmint-cut", required=True)
parser.add_argument('--version', action='version', version='tigmint-ntlink-map 1.2.9')
args = parser.parse_args()
if args.span == "auto":
raise ValueError("Error: span=auto is currently not compatible with using ntLink for mapping. " \
"Please specify an integer value for span. " \
"When using ntLink for mapping, we recommend the span value to be between 2-10.")
run_ntlink_pair(args)
run_tigmint_filter_paf(args)
if __name__ == "__main__":
main()