好吧,我因为这个问题浪费了几个小时。看来您无法将任何 MATLAB 对象(轴或文本框)放置在该 hgjavacomponent 对象的顶部。当然,我无法修改java代码。所以我找到的唯一可行的解决方案是从头开始创建图形。
我不想重写代码来计算权重矩阵(符号高度),你已经这样做了。但如果您根本不想使用 MATLAB 的 seqlogo,这是可以做到的。所以我稍微改变了你的最后一行以获得矩阵:
[wm, handle] = seqlogo(wide_seqs(:,high_bit_cols ));
文本符号的问题是您无法精确控制它们的大小,无法将符号适合文本框。这可能就是 MATLAB 决定使用 java 图形对象的原因。但我们可以创建符号图像并处理它们。
以下是创建字母图像的代码:
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 图:
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 http://img716.imageshack.us/img716/2073/seqlogoexample.png
当然,代码和图形还可以进一步改进,但我希望这是您可以开始使用的东西。如果我错过了什么,请告诉我。