File: compare_gaps_pos.py

package info (click to toggle)
spades 3.13.1+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 22,172 kB
  • sloc: cpp: 136,213; ansic: 48,218; python: 16,809; perl: 4,252; sh: 2,115; java: 890; makefile: 507; pascal: 348; xml: 303
file content (63 lines) | stat: -rwxr-xr-x 1,976 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/python3

############################################################################
# Copyright (c) 2015 Saint Petersburg State University
# Copyright (c) 2011-2014 Saint Petersburg Academic University
# All Rights Reserved
# See file LICENSE for details.
############################################################################

import os
import sys 

def parse_name(name):
      pieces = name.strip().split('_')
      return int(pieces[1])


def find_length(filename):
    inFileName = filename
    inFile = open(inFileName)
    length = 0
    for line in inFile:
        parse = line.strip().split()
        if parse[0] == "10" or parse[0] == "ref0":
            length = max(length, int(parse[3]))
    print "length = " + str(length)
    return length
def find_gaps(filename, length):
    from numpy import ndarray
    a = ndarray((length + 1),int)
    inFileName = filename
    inFile = open(inFileName)
    for line in inFile:
        parse = line.strip().split()
        if parse[0] == "10" or parse[0] == "ref0":
            for j in range(int(parse[1]), int(parse[3])):
                a[j] = 1
    in_gap = 0
    start = 0;
    for i in range(0, length-1):

        if in_gap == 0:
            if a[i] == 0:
                in_gap = 1
                start = i
        if in_gap == 1:
            if a[i] == 1:
                finish = i - 1
                in_gap = 0
                if finish - start > 10:
                    print "gap " + str(start) + " - " + str(finish) +" len: " + str(finish - start)

if len(sys.argv) != 2:
        print "Prints gaps for given .pos file"
        print("Usage: " + sys.argv[0] + " <.pos>")
        sys.exit()
       
length = find_length(sys.argv[1])       
find_gaps(sys.argv[1], length)
#print "*************************************** \nSecond:"
#gaps_after = make_snap(sys.argv[2], length)
#print "####################################### \nCounting gaps ..."
#find__gaps(gaps_before, gaps_after, length)