diff --git a/README.md b/README.md index 9b8b607..b9249b9 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,6 @@ See [plotnineSeqSuite Documentation](https://caotianze.github.io/plotnineseqsuit PyCharm 2022.1 (Community Edition) and Spyder version: 5.4.1 (conda) ## Dependencies Python version: 3.10.9 64-bit -plotnine: 0.10.1 +plotnine: 0.12.2 +## Similar projects +R package [ggmsa](https://github.com/YuLab-SMU/ggmsa) and [ggseqlogo](https://github.com/omarwagih/ggseqlogo) diff --git a/compare/test_ggmsa.r b/compare/test_ggmsa.r new file mode 100644 index 0000000..078126d --- /dev/null +++ b/compare/test_ggmsa.r @@ -0,0 +1,12 @@ +library(ggseqlogo) +library(Biostrings) +data(ggseqlogo_sample) +library(ggplot2) +library(ggmsa) +aastr=seqs_aa[['CSNK2A2']] +names(aastr)=1:80 +seqstr = AAStringSet(aastr) + +A=seqlogo(seqstr, adaptive = TRUE)+ggtitle('C') +A=A+theme(panel.grid=element_blank(),panel.background=element_rect(fill='white',color=NA),plot.background=element_rect(fill='white',color=NA),axis.ticks.x=element_blank()) +ggsave('Fig. 3C.png',width=7,height=7,dpi=300) diff --git a/compare/test_ggseqlogo.r b/compare/test_ggseqlogo.r new file mode 100644 index 0000000..30ec26f --- /dev/null +++ b/compare/test_ggseqlogo.r @@ -0,0 +1,7 @@ +library(ggplot2) +library(ggseqlogo) +data(ggseqlogo_sample) + +A=ggplot() + geom_logo(seqs_aa[['CSNK2A2']], method = 'probability', col_scheme='chemistry')+ggtitle('B')+guides(fill=FALSE) +A=A+theme(panel.grid=element_blank(),panel.background=element_rect(fill='white'),axis.ticks.x=element_blank()) +ggsave('Fig. 3B.png',width=7,height=7,dpi=300) diff --git a/compare/test_plotnineSeqSuite.py b/compare/test_plotnineSeqSuite.py new file mode 100644 index 0000000..b437d80 --- /dev/null +++ b/compare/test_plotnineSeqSuite.py @@ -0,0 +1,8 @@ +from plotnine import ggplot, ggtitle, theme, guides, element_blank, element_rect +from plotnineseqsuite.data import seqs_aa +from plotnineseqsuite.logo import geom_logo + +A=ggplot() + geom_logo(seqs_aa['CSNK2A2'], method='probability', col_scheme='chemistry') + ggtitle('A')+ guides(fill=False) +A=A+theme(panel_grid=element_blank(),panel_background=element_rect(fill='white'),axis_ticks_major_x=element_blank()) + +A.save("Fig. 3A.png",width=7,height=7,dpi=300) diff --git a/plotnineseqsuite/align.py b/plotnineseqsuite/align.py index f91d503..374ad88 100644 --- a/plotnineseqsuite/align.py +++ b/plotnineseqsuite/align.py @@ -133,10 +133,11 @@ def __radd__(self, gg): mapping=aes(x='x', y='y', width='width', height='height', fill='group'), **self.__kwargs) params.append(bg_layer) + params.append(self.colscale_opts) if self.letter_data is not None: letter_layer = geom_polygon(data=self.letter_data, mapping=aes(x='x', y='y', group='group_by'), fill=self.__font_col, **self.__kwargs) params.append(letter_layer) - params.extend([self.scale_x_continuous, self.scale_y_continuous, self.ylab, self.xlab, self.colscale_opts]) + params.extend([self.scale_x_continuous, self.scale_y_continuous, self.ylab, self.xlab]) gg = gg + params return gg diff --git a/setup.py b/setup.py index 927c74a..196366d 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="plotnineseqsuite", - version="0.9.0", + version="0.9.1", author="Cao Tianze", author_email="hnrcao@qq.com", description="A Python package for visualizing sequence data using ggplot2", @@ -24,9 +24,9 @@ ], packages=['plotnineseqsuite','plotnineseqsuite.font','plotnineseqsuite.data'], python_requires=">=3.10", - install_requires=['plotnine>=0.10.1'], + install_requires=['plotnine==0.12.2'], license="MIT", - keywords=['ggplot2', 'plotnine', 'Bioinformatics', 'Sequence logo'], + keywords=['ggplot2', 'plotnine', 'Bioinformatics tool', 'Sequence logo'], package_data={ "": ["*.csv"] } diff --git a/tests/test_paper.py b/tests/test_paper.py index 6ca5061..8d7a549 100644 --- a/tests/test_paper.py +++ b/tests/test_paper.py @@ -1,36 +1,28 @@ -# In order to execute the code correctly, the user needs to ensure that there is a 'paper' directory in the working directory. # Install plotnineSeqSuite: pip install plotnineseqsuite # Install Pillow: pip install Pillow -from plotnine import ggplot, ggtitle, theme, element_text +from plotnine import ggplot, ggtitle from plotnineseqsuite.data import seqs_dna, seqs_aa from plotnineseqsuite.logo import geom_logo from plotnineseqsuite.theme import theme_seq -A = ggplot() + geom_logo(seqs_aa['CSNK2A2'], col_scheme='chemistry') + ggtitle('A') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) # Fig. 2A -A.save('paper/Fig. 2A.png') -B = ggplot() + geom_logo(seqs_aa['CSNK2A2'], col_scheme='chemistry2') + ggtitle('B') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) # Fig. 2B -B.save('paper/Fig. 2B.png') -C = ggplot() + geom_logo(seqs_aa['CSNK2A2'], col_scheme='hydrophobicity') + ggtitle('C') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) # Fig. 2C -C.save('paper/Fig. 2C.png') -D = ggplot() + geom_logo(seqs_dna['MA0001.1'], col_scheme='nucleotide') + ggtitle('D') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) # Fig. 2D -D.save('paper/Fig. 2D.png') -E = ggplot() + geom_logo(seqs_dna['MA0001.1'], col_scheme='nucleotide2') + ggtitle('E') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) # Fig. 2E -E.save('paper/Fig. 2E.png') -F = ggplot() + geom_logo(seqs_dna['MA0001.1'], col_scheme='base_pairing') + ggtitle('F') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) # Fig. 2F -F.save('paper/Fig. 2F.png') -G = ggplot() + geom_logo(seqs_aa['CSNK2A2'], col_scheme='clustalx') + ggtitle('G') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) # Fig. 2G -G.save('paper/Fig. 2G.png') -H = ggplot() + geom_logo(seqs_aa['CSNK2A2'], col_scheme='taylor') + ggtitle('H') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) # Fig. 2H -H.save('paper/Fig. 2H.png') +A = ggplot() + geom_logo(seqs_aa['CSNK2A2'], col_scheme='chemistry') + ggtitle('A') + theme_seq() # Fig. 2A +A.save('Fig. 2A.png') +B = ggplot() + geom_logo(seqs_aa['CSNK2A2'], col_scheme='chemistry2') + ggtitle('B') + theme_seq() # Fig. 2B +B.save('Fig. 2B.png') +C = ggplot() + geom_logo(seqs_aa['CSNK2A2'], col_scheme='hydrophobicity') + ggtitle('C') + theme_seq() # Fig. 2C +C.save('Fig. 2C.png') +D = ggplot() + geom_logo(seqs_dna['MA0001.1'], col_scheme='nucleotide') + ggtitle('D') + theme_seq() # Fig. 2D +D.save('Fig. 2D.png') +E = ggplot() + geom_logo(seqs_dna['MA0001.1'], col_scheme='nucleotide2') + ggtitle('E') + theme_seq() # Fig. 2E +E.save('Fig. 2E.png') +F = ggplot() + geom_logo(seqs_dna['MA0001.1'], col_scheme='base_pairing') + ggtitle('F') + theme_seq() # Fig. 2F +F.save('Fig. 2F.png') +G = ggplot() + geom_logo(seqs_aa['CSNK2A2'], col_scheme='clustalx') + ggtitle('G') + theme_seq() # Fig. 2G +G.save('Fig. 2G.png') +H = ggplot() + geom_logo(seqs_aa['CSNK2A2'], col_scheme='taylor') + ggtitle('H') + theme_seq() # Fig. 2H +H.save('Fig. 2H.png') + from plotnine import ggplot from plotnineseqsuite.data import seqs_dna from plotnineseqsuite.col_schemes import make_col_scheme @@ -39,68 +31,13 @@ cs1 = make_col_scheme(chars=['A', 'T', 'C', 'G'], groups=['gr1', 'gr1', 'gr2', 'gr2'], cols=['purple', 'purple', 'blue', 'blue']) -I = ggplot() + geom_logo(seqs_dna['MA0001.1'], col_scheme=cs1) + ggtitle('I') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) # Fig. 2I -I.save('paper/Fig. 2I.png') +I = ggplot() + geom_logo(seqs_dna['MA0001.1'], col_scheme=cs1) + ggtitle('I') + theme_seq() # Fig. 2I +I.save('Fig. 2I.png') cs2 = make_col_scheme(chars=['A', 'T', 'C', 'G'], values=[1, 2, 3, 4]) -J = ggplot() + geom_logo(seqs_dna['MA0001.1'], col_scheme=cs2) + ggtitle('J') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) # Fig. 2J -J.save('paper/Fig. 2J.png') +J = ggplot() + geom_logo(seqs_dna['MA0001.1'], col_scheme=cs2) + ggtitle('J') + theme_seq() # Fig. 2J +J.save('Fig. 2J.png') -from plotnine import ggplot, coord_fixed, ggtitle, theme, element_text -from plotnineseqsuite.align import geom_alignedSeq -from plotnineseqsuite.theme import theme_seq -from plotnineseqsuite.data import seqs_dna - -A = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='times_new_roman') + ggtitle('A') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3A -A.save('paper/Fig. 3A.png') -B = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='arial') + ggtitle('B') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3A -B.save('paper/Fig. 3B.png') -C = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='courier_new') + ggtitle('C') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3A -C.save('paper/Fig. 3C.png') -D = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='xkcd_regular') + ggtitle('D') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3A -D.save('paper/Fig. 3D.png') -E = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='akrobat_bold') + ggtitle('E') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3B -E.save('paper/Fig. 3E.png') -F = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='akrobat_regular') + ggtitle('F') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3C -F.save('paper/Fig. 3F.png') -G = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='helvetica_bold') + ggtitle('G') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3D -G.save('paper/Fig. 3G.png') -H = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='helvetica_light') + ggtitle('H') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3E -H.save('paper/Fig. 3H.png') -I = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='helvetica_regular') + ggtitle('I') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3F -I.save('paper/Fig. 3I.png') - -J = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='roboto_bold') + ggtitle('J') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3G -J.save('paper/Fig. 3J.png') -K = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='roboto_medium') + ggtitle('K') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3H -K.save('paper/Fig. 3K.png') -L = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='roboto_regular') + ggtitle('L') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3I -L.save('paper/Fig. 3L.png') - -M = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='roboto_slab_bold') + ggtitle('M') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3J -M.save('paper/Fig. 3M.png') -N = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='roboto_slab_light') + ggtitle('N') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3K -N.save('paper/Fig. 3N.png') -O = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font='roboto_slab_regular') + ggtitle('O') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig .3L -O.save('paper/Fig. 3O.png') - -from plotnine import ggplot, coord_fixed, ggtitle, theme, element_text +from plotnine import ggplot, coord_fixed, ggtitle, element_text from plotnine.guides import guides from plotnineseqsuite.data import seqs_dna from plotnineseqsuite.logo import geom_logo @@ -110,34 +47,32 @@ seqs_numeric = list( map(lambda x: x.replace('A', 'a').replace('T', 't').replace('G', 'g').replace('C', 'c'), seqs_dna['MA0001.1'])) -A = ggplot() + geom_logo(seqs_numeric, method='probability', namespace=['a', 't', 'g', 'c']) + ggtitle( - 'A') + theme_seq() + theme(plot_title=element_text(size=30, ha='left')) + guides(fill=False) # Fig .4A -A.save('paper/Fig. 4A.png') +K = ggplot() + geom_logo(seqs_numeric, method='probability', namespace=['a', 't', 'g', 'c']) + ggtitle( + 'K') + theme_seq() + guides(fill=False) # Fig .4K +K.save('Fig. 2K.png') seqs_numeric = list( map(lambda x: x.replace('A', '1').replace('T', '2').replace('G', '3').replace('C', '4'), seqs_dna['MA0001.1'])) -B = ggplot() + geom_logo(seqs_numeric, method='probability', namespace=['1', '2', '3', '4']) + ggtitle( - 'B') + theme_seq() + theme(plot_title=element_text(size=30, ha='left')) + guides(fill=False) # Fig .4B -B.save('paper/Fig. 4B.png') +L = ggplot() + geom_logo(seqs_numeric, method='probability', namespace=['1', '2', '3', '4']) + ggtitle( + 'L') + theme_seq() + guides(fill=False) # Fig .4L +L.save('Fig. 2L.png') seqs_numeric = list( map(lambda x: x.replace('A', 'δ').replace('T', 'ε').replace('G', 'ψ').replace('C', 'λ'), seqs_dna['MA0001.1'])) -C = ggplot() + geom_logo(seqs_numeric, method='probability', namespace=['δ', 'ε', 'ψ', 'λ']) + ggtitle( - 'C') + theme_seq() + theme(plot_title=element_text(size=30, ha='left')) + guides(fill=False) # Fig .4C -C.save('paper/Fig. 4C.png') +M = ggplot() + geom_logo(seqs_numeric, method='probability', namespace=['δ', 'ε', 'ψ', 'λ']) + ggtitle( + 'M') + theme_seq() + guides(fill=False) # Fig .4M +M.save('Fig. 2M.png') + import numpy as np custom_mat = np.random.randn(4, 5) -D = ggplot() + geom_logo(custom_mat, method='custom', seq_type='DNA') + ggtitle('D') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) # Fig .4D -D.save('paper/Fig. 4D.png') -E = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font=None) + ggtitle('E') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig. 4E -E.save('paper/Fig. 4E.png') -F = ggplot() + geom_seqBar(seqs_dna['MA0013.1'], font=None) + ggtitle('F') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) # Fig. 4F -F.save('paper/Fig. 4F.png') -G = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font_col='black', bg_col_scheme=None) + ggtitle( - 'G') + theme_seq() + theme(plot_title=element_text(size=30, ha='left')) + coord_fixed() # Fig. 4G -G.save('paper/Fig. 4G.png') +N = ggplot() + geom_logo(custom_mat, method='custom', seq_type='DNA') + ggtitle('N') + theme_seq()# Fig .4N +N.save('Fig. 2N.png') +O = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font=None) + ggtitle('O') + theme_seq() + coord_fixed() # Fig. 2O +O.save('Fig. 2O.png') +P = ggplot() + geom_seqBar(seqs_dna['MA0013.1'], font=None) + ggtitle('P') + theme_seq()# Fig. 2P +P.save('Fig. 2P.png') +Q = ggplot() + geom_alignedSeq(seqs_dna['MA0013.1'], font_col='black', bg_col_scheme=None) + ggtitle( + 'Q') + theme_seq() + coord_fixed() # Fig. 2G +Q.save('Fig. 2Q.png') from plotnine import scale_y_continuous names = ['seq-a', 'seq-b', 'seq-c', 'seq-d', 'seq-e', 'seq-f'] @@ -146,13 +81,12 @@ logo.data['y'] = logo.data['y'] + 6.1 bar = geom_seqBar(seqs_dna['MA0013.1'], font=None) bar.bar_data['y'] = bar.bar_data['y'] - 1.1 -H = ggplot() + logo + bar + seqs + ggtitle('H') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) + scale_y_continuous( +R = ggplot() + logo + bar + seqs + ggtitle('R') + theme_seq()+ scale_y_continuous( breaks=lambda x: [k + 0.5 for k in range(0, len(names))], labels=names) # Fig .4H -H.save('paper/Fig. 4H.png') +R.save('Fig. 2R.png') from plotnine.geoms import annotate -I = ggplot() + geom_seqBar(seqs_dna['MA0013.1']) + annotate('segment', x=1.5, xend=2.5, y=0, yend=0, size=2, +S = ggplot() + geom_seqBar(seqs_dna['MA0013.1']) + annotate('segment', x=1.5, xend=2.5, y=0, yend=0, size=2, color='red') + annotate('segment', x=4.5, xend=7.5, y=0, yend=0, size=2, color='red') + annotate('segment', @@ -161,47 +95,84 @@ y=0, yend=0, size=2, color='red') + annotate( - 'text', x=6, y=-0.2, label='A is the most', color='red') + ggtitle('I') + theme_seq() + theme( - plot_title=element_text(size=30, ha='left')) # Fig .4I -I.save('paper/Fig. 4I.png') + 'text', x=6, y=-0.2, label='A is the most', color='red') + ggtitle('S') + theme_seq() # Fig .2I +S.save('Fig. 2S.png') from PIL import Image -name2 = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'] +name2 = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S'] img2 = [] -resize_img2=[] +resize_img2 = [] for item in name2: - img2.append(Image.open('paper/Fig. 2%s.png' % item)) + img2.append(Image.open('Fig. 2%s.png' % item)) for item in img2: - resize_img2.append(item.resize((img2[0].width,img2[0].height))) -coordinate2 = [(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (0, 1), (1, 1), (2, 1), (3, 1), (4, 1)] -dst = Image.new('RGB', (img2[0].width * 5, img2[0].height * 2)) + resize_img2.append(item.resize((img2[0].width, img2[0].height))) +coordinate2 = [(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (0, 1), (1, 1), (2, 1), (3, 1), (4, 1) + , (0, 2), (1, 2), (2, 2), (3, 2), (4, 2), (0, 3), (1, 3), (2, 3), (3, 3)] +dst = Image.new('RGB', (img2[0].width * 5, img2[0].height * 4), color='white') list(map(lambda img_item, coordinate_size: dst.paste(img_item, ( -img2[0].width * coordinate_size[0], img2[0].height * coordinate_size[1])), resize_img2, coordinate2)) -dst.save('paper/Fig. 2.png') + img2[0].width * coordinate_size[0], img2[0].height * coordinate_size[1])), resize_img2, coordinate2)) +dst.save('Fig. 2.png') -name3 = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J','K','L','M','N','O'] +#Fig. 3 +name3 = ['A', 'B', 'C'] img3 = [] -resize_img3=[] +resize_img3 = [] for item in name3: - img3.append(Image.open('paper/Fig. 3%s.png' % item)) + img3.append(Image.open('compare/Fig. 3%s.png' % item)) for item in img3: - resize_img3.append(item.resize((img3[0].width,img3[0].height))) -coordinate3 = [(0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1), (0, 2), (1, 2), (2, 2), (0, 3), (1, 3), (2, 3), (0, 4), (1, 4), (2, 4)] -dst = Image.new('RGB', (img3[0].width * 3, img3[0].height * 5)) + resize_img3.append(item.resize((img3[0].width, img3[0].height))) +coordinate3 = [(0, 0),(1,0),(2,0)] +dst = Image.new('RGB', (img3[0].width * 3, img3[0].height * 1), color='white') list(map(lambda img_item, coordinate_size: dst.paste(img_item, ( -img3[0].width * coordinate_size[0], img3[0].height * coordinate_size[1])), resize_img3, coordinate3)) -dst.save('paper/Fig. 3.png') - -name4 = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'] + img3[0].width * coordinate_size[0], img3[0].height * coordinate_size[1])), resize_img3, coordinate3)) +dst.save('Fig. 3.png') + +#Fig. 4 +from plotnine import ggplot, theme, guides, element_text, element_rect, element_blank, scale_fill_manual +from plotnineseqsuite import geom_logo + +data = ['RELVKDRRWSPDSKKKIREGPSNGAHEERNWHPVDGANGVRRYVP', 'RELIKDRRWSPDSRNDIREGPSDGQHEERNWHPSNGANGVSRYIP', + 'RELIKDRRWSPDSRNNIREGPSDGQHEERNWHPSNGANGVSRYIP', 'RELIKDRRWSPDSRNNIREGPSDGQHEERNWHPSNGANGVSRYIP', + 'RELIKDRRWSPDSRNNIREGPSDGQHEERNWHPSNGANGVSRYIP', 'RELIKDRRWSPDSRNNIREGPSDGQHEERNWHPSNGANGVSRYIP', + 'RELIKDRRWSPDSRNNIREGPSDGQHEERNWHPSNGANGVSRYIP', 'RELIKDRRWSPDSRNNIREGPSDGQHEERNWHPSNGANGVSRYIP', + 'RELIKDRRWSPDSRNNIREGPSDGQHEERNWHPSNGANGVSRYIP', 'RELIKDRRWSPDSRNNIREGPSDGQHEERNWHPSNGANGVSRYIP'] +g = ggplot() + geom_logo(data=data, method='probability')+ggtitle('A') +g = g + theme(aspect_ratio=0.1, panel_grid=element_blank(), + panel_background=element_rect(fill='white'), + axis_title_x=element_blank(), axis_text_x=element_blank(), + axis_ticks_major_x=element_blank(), axis_ticks_major_y=element_blank(), + axis_title_y=element_text(size=8)) + guides(fill=False) +print(g) +g.save('Fig. 4A.png',dpi=300,width=6,height=1) + +layer_logo = geom_logo(data=data, method='probability') + + +def change_group(x): + if x['position'] == 1 or x['position'] == 6 or x['position'] == 19 or x['position'] == 29 or x['position'] == 42: + x['group'] = 'interested' + else: + x['group'] = 'not_interested' + return x + + +layer_logo.data = layer_logo.data.apply(func=change_group, axis=1) +g = ggplot() + layer_logo + ggtitle('B') + scale_fill_manual({'interested': '#B22222', 'not_interested': '#C0C0C0'}) +g = g + theme(aspect_ratio=0.1, panel_grid=element_blank(), panel_background=element_rect(fill='white'), + axis_title_x=element_blank(), axis_text_x=element_blank(), axis_ticks_major_x=element_blank(), + axis_ticks_major_y=element_blank(), axis_title_y=element_text(size=8)) + guides(fill=False) +g.save('Fig. 4B.png', dpi=300,width=6,height=1) + +name4 = ['A', 'B'] img4 = [] -resize_img4=[] +resize_img4 = [] for item in name4: - img4.append(Image.open('paper/Fig. 4%s.png' % item)) + img4.append(Image.open('Fig. 4%s.png' % item)) for item in img4: - resize_img4.append(item.resize((img4[0].width,img4[0].height))) -coordinate4 = [(0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1), (0, 2), (1, 2), (2, 2)] -dst = Image.new('RGB', (img4[0].width * 3, img4[0].height * 3)) + resize_img4.append(item.resize((img4[0].width, img4[0].height))) +coordinate4 = [(0, 0),(0,1)] +dst = Image.new('RGB', (img4[0].width * 1, img4[0].height * 2), color='white') list(map(lambda img_item, coordinate_size: dst.paste(img_item, ( -img4[0].width * coordinate_size[0], img4[0].height * coordinate_size[1])), resize_img4, coordinate4)) -dst.save('paper/Fig. 4.png') \ No newline at end of file + img4[0].width * coordinate_size[0], img4[0].height * coordinate_size[1])), resize_img4, coordinate4)) +dst.save('Fig. 4.png') \ No newline at end of file