1.1 --- a/scripts/last-dotplot Tue Dec 05 17:57:24 2017 +0900
1.2 +++ b/scripts/last-dotplot Thu Dec 21 16:22:52 2017 +0900
1.3 @@ -280,22 +280,17 @@
1.4 if toMiddle < 0:
1.5 return i[1:3] # sequence-rank and "position" of this alignment
1.6
1.7 -def alignmentSortData1(alignments, seqNamesToRanks2):
1.8 - for seqName1, seqName2, blocks in alignments:
1.9 - seqRank2 = seqNamesToRanks2[seqName2]
1.10 - pos2 = abs(blocks[0][1] + blocks[-1][1] + blocks[-1][2])
1.11 +def alignmentSortData(alignments, seqIndex, otherNamesToRanks):
1.12 + otherIndex = 1 - seqIndex
1.13 + for i in alignments:
1.14 + blocks = i[2]
1.15 + otherRank = otherNamesToRanks[i[otherIndex]]
1.16 + otherPos = abs(blocks[0][otherIndex] +
1.17 + blocks[-1][otherIndex] + blocks[-1][2])
1.18 numOfAlignedLetterPairs = sum(i[2] for i in blocks)
1.19 - yield seqName1, seqRank2, pos2, numOfAlignedLetterPairs
1.20 + yield i[seqIndex], otherRank, otherPos, numOfAlignedLetterPairs
1.21
1.22 -def alignmentSortData2(alignments, seqNamesToRanks1):
1.23 - for seqName1, seqName2, blocks in alignments:
1.24 - seqRank1 = seqNamesToRanks1[seqName1]
1.25 - pos1 = abs(blocks[0][0] + blocks[-1][0] + blocks[-1][2])
1.26 - numOfAlignedLetterPairs = sum(i[2] for i in blocks)
1.27 - yield seqName2, seqRank1, pos1, numOfAlignedLetterPairs
1.28 -
1.29 -def mySortedRanges(seqRanges, sortOpt,
1.30 - alignmentSortDataFunc, alignments, otherRanges):
1.31 +def mySortedRanges(seqRanges, sortOpt, seqIndex, alignments, otherRanges):
1.32 rangesGroupedBySeqName = itertools.groupby(seqRanges, itemgetter(0))
1.33 g = [list(ranges) for seqName, ranges in rangesGroupedBySeqName]
1.34 if sortOpt == "1":
1.35 @@ -306,7 +301,8 @@
1.36 otherNameGroups = itertools.groupby(i[0] for i in otherRanges)
1.37 ranksAndNames = enumerate(i[0] for i in otherNameGroups)
1.38 otherNamesToRanks = dict((n, r) for r, n in ranksAndNames)
1.39 - alns = sorted(alignmentSortDataFunc(alignments, otherNamesToRanks))
1.40 + alns = sorted(alignmentSortData(alignments, seqIndex,
1.41 + otherNamesToRanks))
1.42 alnsGroupedBySeqName = itertools.groupby(alns, itemgetter(0))
1.43 seqNamesToLists = dict((k, list(v)) for k, v in alnsGroupedBySeqName)
1.44 g.sort(key=functools.partial(alignmentKey, seqNamesToLists))
1.45 @@ -323,11 +319,11 @@
1.46 if o2 != "3":
1.47 s2 = mySortedRanges(seqRanges2, o2, None, None, None)
1.48 if o1 == "3":
1.49 - s1 = mySortedRanges(seqRanges1, o1, alignmentSortData1, alignments, s2)
1.50 + s1 = mySortedRanges(seqRanges1, o1, 0, alignments, s2)
1.51 if o2 == "3":
1.52 - s2 = mySortedRanges(seqRanges2, o2, alignmentSortData2, alignments, s1)
1.53 - t1 = mySortedRanges(seqRangesB1, oB1, alignmentSortData1, alignmentsB, s2)
1.54 - t2 = mySortedRanges(seqRangesB2, oB2, alignmentSortData2, alignmentsB, s1)
1.55 + s2 = mySortedRanges(seqRanges2, o2, 1, alignments, s1)
1.56 + t1 = mySortedRanges(seqRangesB1, oB1, 0, alignmentsB, s2)
1.57 + t2 = mySortedRanges(seqRangesB2, oB2, 1, alignmentsB, s1)
1.58 return s1 + t1, s2 + t2
1.59
1.60 def prettyNum(n):
1.61 @@ -430,7 +426,6 @@
1.62 size -= next_pix
1.63
1.64 def drawLineReverse(hits, width, bp_per_pix, beg1, beg2, size):
1.65 - beg2 = -1 - beg2
1.66 while True:
1.67 q1, r1 = divmod(beg1, bp_per_pix)
1.68 q2, r2 = divmod(beg2, bp_per_pix)
1.69 @@ -461,10 +456,10 @@
1.70 beg2 = -(beg2 + size)
1.71 if beg2 >= 0:
1.72 drawLineForward(hits, width, bp_per_pix,
1.73 - beg1 + ori1, beg2 + ori2, size)
1.74 + ori1 + beg1, ori2 + beg2, size)
1.75 else:
1.76 drawLineReverse(hits, width, bp_per_pix,
1.77 - beg1 + ori1, beg2 - ori2, size)
1.78 + ori1 + beg1, ori2 - beg2 - 1, size)
1.79 return hits
1.80
1.81 def expandedSeqDict(seqDict):
1.82 @@ -636,10 +631,10 @@
1.83 image_size = (margin, end) if textRot else (end, margin)
1.84 im = Image.new(image_mode, image_size, opts.margin_color)
1.85 draw = ImageDraw.Draw(im)
1.86 - for i in labels:
1.87 - base = margin - i[4] if textAln else 0
1.88 - position = (base, i[1]) if textRot else (i[1], base)
1.89 - draw.text(position, i[3], font=font, fill=opts.text_color)
1.90 + for sortKey, labelBeg, labelEnd, text, textHeight in labels:
1.91 + base = margin - textHeight if textAln else 0
1.92 + position = (base, labelBeg) if textRot else (labelBeg, base)
1.93 + draw.text(position, text, font=font, fill=opts.text_color)
1.94 return im
1.95
1.96 def rangesWithOrigins(sortedRanges, rangePixBegs, bpPerPix):