-
Notifications
You must be signed in to change notification settings - Fork 5
/
panISa.py
executable file
·68 lines (58 loc) · 2.49 KB
/
panISa.py
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
66
67
68
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
##Copyright (c) 2017 Benoit Valot and Panisa Treepong
##UMR 6249 Chrono-Environnement, Besançon, France
##Licence GPL
"""Search integrative element insertion on BAM alignment"""
import sys
import argparse
import os
import tempfile
from lib import bamreader
from lib.couple import Couples
from lib.writer import writetabular
from lib import variables
desc = "Search integrative element (IS) insertion on a genome using BAM alignment"
command = argparse.ArgumentParser(prog='panISa.py', \
description=desc, usage='%(prog)s [options] bam')
command.add_argument('-o', '--output', nargs="?", \
type=argparse.FileType("w"), default=sys.stdout, \
help='Return list of IS insertion by alignment, default=stdout')
command.add_argument('-q', '--quality', nargs="?", \
type=int, default=20, \
help='Min alignment quality value to conserve a clipped read, default=20')
command.add_argument('-m', '--minimun', nargs="?", \
type=int, default=10, \
help='Min number of clipped reads to look at IS on a position, default=10')
command.add_argument('-s', '--size', nargs="?", \
type=int, default=20, \
help='Maximun size of direct repeat region, default=20pb')
command.add_argument('-p', '--percentage', nargs="?", \
type=float, default=0.8, \
help='Minimum percentage of same base to create consensus, default=0.8')
command.add_argument('bam', type=argparse.FileType("r"), \
help='Alignment on BAM/SAM format')
command.add_argument('-v', '--version', action='version', \
version='%(prog)s ' + variables.version)
if __name__=='__main__':
"""Performed job on execution script"""
args = command.parse_args()
output = args.output
##valided argument
if args.percentage < 0 or args.percentage > 1:
raise Exception("--percentage must be comprised between 0 to 1")
##Search clip read on bam by position with min quality
positions = bamreader.parse(args.bam.name, args.quality)
##filter positions with not enought clipread
positions.filterposition(args.minimun)
##find close position with both start and end clip to make a couple
couples = Couples()
couples.groupeposition(positions, args.size)
couples.filteroverlapcouple()
##Create consensus and search inverted repeat sequence on it
for couple in couples:
couple.createconsensus(args.percentage)
couple.searchir()
##return list of possible IS
writetabular(output, couples)