Example #1
0
    #for i in range(0,len1+1):
    #    mat[i][0] = i
    #for j in range(0,len2+1):
    #    mat[0][j] = j

    for i in range(1, len1 + 1):
        for j in range(1, len2 + 1):
            if in1[i - 1] == in2[j - 1]:
                mat[i][j] = mat[i - 1][j - 1]
            else:
                mat[i][j] = min(mat[i][j - 1], mat[i - 1][j],
                                mat[i - 1][j - 1]) + 1

    return mat


def print_matrix(mat):
    l1 = len(mat)
    for i in range(l1):
        print "\t".join(map(lambda x: str(x), mat[i]))


afh = open(sys.argv[1])

alignment_it = getNucmerAlignmentIterator(afh)

for pbname, alignment in groupby(alignment_it, lambda x: x.sname):
    print pbname, map(attrgetter("qname"), alignment)

afh.close()
Example #2
0
    #for i in range(0,len1+1):
    #    mat[i][0] = i
    #for j in range(0,len2+1):
    #    mat[0][j] = j
    
    for i in range(1, len1+1):
        for j in range(1,len2+1):
            if in1[i-1] == in2[j-1]:
                mat[i][j] = mat[i-1][j-1]
            else:
                mat[i][j] = min( mat[i][j-1], mat[i-1][j], mat[i-1][j-1]) + 1

    return mat


def print_matrix(mat):
    l1 = len(mat)
    for i in range(l1):
        print "\t".join(map(lambda x: str(x), mat[i]))

afh = open(sys.argv[1])

alignment_it = getNucmerAlignmentIterator(afh)

for pbname, alignment in groupby(alignment_it, lambda x : x.sname):
    print pbname, map(attrgetter("qname"), alignment)



afh.close()
Example #3
0
import sys
from nucio import getNucmerAlignmentIterator, nucRecordToString
from itertools import groupby
from operator import attrgetter

#dist from the end 
#that is considered in the middle
END_CUTOFF =  200

if not len(sys.argv) == 2:
    sys.exit("alignment_verify.py alignments.sc")

fh = open(sys.argv[1])


for pbname, alignments in groupby(getNucmerAlignmentIterator(fh), attrgetter("sname")):
    al = list(alignments)

    ##if all alignments are to the same unitig
    if all(map(lambda x: x.qname == al[0].qname , al)):
        continue
    
    for aln in al:
        if (aln.qstart > END_CUTOFF and aln.qstart < (aln.qlen-END_CUTOFF) 
            and aln.qend > END_CUTOFF and aln.qend < (aln.qlen-END_CUTOFF)):
            print nucRecordToString(aln)+"\tMIDDLE"
        else:
            print nucRecordToString(aln)

fh.close()    
Example #4
0
    sys.exit(1)

fh = open(sys.argv[1])

COV_GAP_MIN = int(sys.argv[2])

fhist = open(sys.argv[3] + ".uncov.hist", "w")
freg = open(sys.argv[3] + ".uncov.regions", "w")
ftbases = open(sys.argv[3] + ".uncov.total.bases", "w")

pcov = []  # pct cov

total_bases = 0
total_uncovered_bases = 0

for pbname, alignments in groupby(getNucmerAlignmentIterator(fh), lambda x: x.sname):
    a = list(alignments)
    cov = getCoverageFromNucAlignments(a)

    # mark the 0 coverage regions
    zcov = map(lambda c: 1 if c == 0 else 0, cov)

    # ranges with 0 coverage
    zcov_ranges = getMarkedRanges(zcov)

    # only look at the gaps larger than the min gap size
    zcov_ranges_filt = filter(lambda (x, y): y - x > COV_GAP_MIN, zcov_ranges)

    # write out the regions that pass filter to region file
    freg.write("\t".join([pbname, " ".join(map(lambda t: "%d,%d" % t, zcov_ranges_filt))]) + "\n")
Example #5
0
    sys.exit(1)

fh = open(sys.argv[1])

COV_GAP_MIN = int(sys.argv[2])

fhist = open(sys.argv[3] + ".uncov.hist", "w")
freg = open(sys.argv[3] + ".uncov.regions", "w")
ftbases = open(sys.argv[3] + ".uncov.total.bases", "w")

pcov = []  #pct cov

total_bases = 0
total_uncovered_bases = 0

for pbname, alignments in groupby(getNucmerAlignmentIterator(fh),
                                  lambda x: x.sname):
    a = list(alignments)
    cov = getCoverageFromNucAlignments(a)

    #mark the 0 coverage regions
    zcov = map(lambda c: 1 if c == 0 else 0, cov)

    #ranges with 0 coverage
    zcov_ranges = getMarkedRanges(zcov)

    #only look at the gaps larger than the min gap size
    zcov_ranges_filt = filter(lambda (x, y): y - x > COV_GAP_MIN, zcov_ranges)

    #write out the regions that pass filter to region file
    freg.write("\t".join(