在MATLAB中更改seqlogo图形的x轴 [英] Changing the x-axis of seqlogo figures in MATLAB

查看:112
本文介绍了在MATLAB中更改seqlogo图形的x轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在大量制作 seqlogos 以编程方式.它们有数百列宽,因此运行seqlogo通常会创建太薄而看不到的字母.我注意到,我只关心其中的几列(不一定是连续的列)……大多数是噪音,但有些高度保守.

I'm making a large number of seqlogos programmatically. They are hundreds of columns wide and so running a seqlogo normally creates letters that are too thin to see. I've noticed that I only care about a few of these columns (not necessarily consecutive columns) ... most are noise but some are highly conserved.

我使用以下代码段:

wide_seqs = cell2mat(arrayfun(@randseq, repmat(200, [500 1]), 'uniformoutput', false));
wide_seqs(:, [17,30, 55,70,130]) = repmat(['ATCGG'], [500 1])

conserve_cell = seqlogo(wide_seqs, 'displaylogo', false);
high_bit_cols = any(conserve_cell{2}>1.0,1);
[~, handle] = seqlogo(wide_seqs(:,high_bit_cols ));

尽管这样做时,我会丢失有关数据来自哪些列的信息.

Although when I do this I lose the information about which columns the data came from.

通常,我只需要更改seqlogo的x轴即可.但是,seqlogo是某种基于Java的疯狂对象,其调用类似于:

Normally I would just change the x-axis of the seqlogo. However, seqlogo's are some sort of crazy java-based object and calls like:

set(handle, 'xticklabel', num2str(find(high_bit_cols)))

不起作用.任何帮助将不胜感激.

don't work. Any help would be greatly appreciated.

谢谢, 会

有幸的是,我愿意接受任何一种疯狂的方法来更改轴标签,包括(但不限于):保存后使用图像处理工具箱修改图像,使用文本框创建新的seqlogo函数,修改Java代码(如果可能)等.我不愿意接受使用python",使用此R库"或任何其他非Matlab解决方案.

On the bounty I'm willing to accept any kind of crazy method for changing the axis labels include (but not limited to): Using the image-processing toolbox to modify the image after saving, creating a new seqlogo function using textboxes, modifying the java-code (if possible), etc. I'm NOT willing to accept things like "use python", "use this R library" or any other sort of non-Matlab solution.

推荐答案

好的,我为此问题花了几个小时.看来您无法在该hgjavacomponent对象的顶部放置任何MATLAB对象(轴或文本框).当然,我无法修改Java代码.因此,我找到的唯一可行的解​​决方案是从头开始创建图形.

OK, I killed a few hours with this problem. It appears that you cannot place any MATLAB object (axes or textbox) on the top of that hgjavacomponent object. And I couldn't modified the java code, of course. So the only feasible solution I found is to create the figure from scratch.

我不想重写代码来计算权重矩阵(符号高度),您已经做到了.但是,如果您根本不想使用MATLAB的seqlogo,则可以这样做.因此,我对您的最后一行进行了一些更改以获取矩阵:

I didn't want to rewrite the code to calculate weight matrices (symbols heights), you already did that. But it can be done, if you don't want to use MATLAB's seqlogo at all. So I've changed your last line a little to get the matrix:

[wm, handle] = seqlogo(wide_seqs(:,high_bit_cols ));

文本符号的问题是您无法精确控制其大小,无法使符号适合文本框.这可能是MATLAB决定使用Java图形对象的原因.但是我们可以创建符号图像并对其进行处理.

The problem with text symbols is that you cannot exactly control their size, cannot fit the symbol to textbox. This is probably why MATLAB decided to go with java graphic object. But we can create symbols images and deal with them.

以下是用于创建字母图像的代码:

Here is code to create images of letters:

letters = wm{1};
clr = [0 1 0; 0 0 1; 1 0.8 0;1 0 0]; % corresponding colors
for t = 1:numel(letters)
    hf = figure('position',[200 200 100 110],'color','w');
    ha = axes('parent',hf, 'visible','off','position',[0 0 1 1]);
    ht = text(50,55,letters(t),'color',clr(t,:),'units','pixels',...
        'fontsize',100,'fontweight','norm',...
        'vertical','mid','horizontal','center');
    F = getframe(hf); % rasterize the letter
    img = F.cdata;
    m = any(img < 255,3); % convert to binary image
    m(any(m,2),any(m,1))=1; % mask to cut white borders
    imwrite(reshape(img(repmat(m,[1 1 3])),[sum(any(m,2)) sum(any(m,1)) 3]),...
        [letters(t) '.png'])
    close(hf)
end

然后,我们使用这些图像绘制新的seqlogo图:

Then we use those images to draw new seqlogo plot:

xlabels = cellstr(num2str(find(high_bit_cols)'));
letters = wm{1};
wmat=wm{2}; % weight matrix from seqlogo
[nletters  npos] = size(wmat);
wmat(wmat<0) = 0; % cut negative values

% prepare the figure
clf
hAx = axes('parent',gcf,'visible','on');
set(hAx,'XLim',[0.5 npos+0.5],'XTick',1:npos,'XTickLabel',xlabels)
ymax = ceil(max(sum(wmat)));
ylim([0 ymax])
axpos = get(hAx,'Position');
step = axpos(3)/npos;

% place images of letters
for i=1:npos
    [wms idx] = sort(wmat(:,i)); % largest on the top
    let_show = letters(idx);
    ybot = axpos(2);
    for s=1:nletters
        if wms(s)==0, continue, end;
        axes('position',[axpos(1) ybot step wms(s)/ymax*axpos(4)])
        ybot = ybot + wms(s)/ymax*axpos(4);
        img = imread([let_show(s) '.png']);
        image(img)
        set(gca,'visible','off')
    end
    axpos(1)=axpos(1)+step;
end

结果如下: 替代文本http://img716.imageshack.us/img716/2073/seqlogoexample.png

当然可以进一步改进代码和图形,但是我希望这是您可以开始使用的东西.让我知道我是否想念什么.

The code and figure can be further improved, of course, but I hope this is something you can start working with. Let me know if I miss something.

这篇关于在MATLAB中更改seqlogo图形的x轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆