Skip to content

Commit

Permalink
zoom feature
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoTianze committed Aug 11, 2023
1 parent 4ea8a8c commit 62d6e55
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions plotnineseqsuite/tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import List


def extract(data: List[str], start: int = None, end: int = None) -> List[str]:
complete_len = len(data[0])
if start is None:
start = 0
if end is None:
end = complete_len
return list(map(lambda x: x[start:end], data))
6 changes: 6 additions & 0 deletions tests/test_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from plotnineseqsuite.tool import extract


def test_extract():
seqs = ['TTGTGAAAGAC', 'AAGTAAACTAA', 'TAATAAACAAA', 'TAATAAACAAA', 'CTGTAAATATT', 'TAGAAAGGTAT']
result = extract(seqs, start=1, end=4)
22 changes: 22 additions & 0 deletions tests/test_zoom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from plotnine import ggplot, coord_fixed, ggtitle, theme, element_text, scale_x_continuous
from plotnineseqsuite.align import geom_alignedSeq, theme_seq, extract
from math import floor, ceil

seqs = ['TTGTGAAAGAC', 'AAGTAAACTAA', 'TAATAAACAAA', 'TAATAAACAAA', 'CTGTAAATATT', 'TAGAAAGGTAT']
result = extract(seqs, start=1, end=4)
a=ggplot() + geom_alignedSeq(data=seqs) + coord_fixed() + theme_seq()+ggtitle('Completed sequences') + theme(plot_title=element_text(size=30, ha='left'))
b=ggplot() + geom_alignedSeq(data=result) + scale_x_continuous(breaks=lambda x: range(floor(x[0]), ceil(x[1])), labels=lambda x:x+1, expand=(0,0)) + coord_fixed() + theme_seq()+ggtitle('Fragmented sequences') + theme(plot_title=element_text(size=30, ha='left'))
a.save('Fig. complete.png')
b.save('Fig. fragment.png')

from PIL import Image
a_pic=Image.open('Fig. complete.png')
b_pic=Image.open('Fig. fragment.png')
a_width = a_pic.width
a_height = a_pic.height
b_width = b_pic.width
b_height = b_pic.height
dst = Image.new('RGB', (a_width+b_width, b_height), color='white')
dst.paste(a_pic, (0, 0))
dst.paste(b_pic, (a_width, 0))
dst.save('Fig. zoom.png')

0 comments on commit 62d6e55

Please sign in to comment.