开发者

How do I add lines connecting corresponding boxes, that I've drawn on a plot? (MATLAB)

I have a matrix (Data) which looks like this:

(start) (stop) (strand) (gene number)

    [      1     29           1        1]
    [     32     38           1        1]
    [     44     60           1        1]
    [     66     70           0        2]
    [     75     80           0        2]
    [     81     88           0        3]
    [     99    102           0        3]
    [    111    160           0        3]
    [    166    170           1        4]
    [    171    188           1        4]

which I have plotted onto a graph using the first two columns as X positions, and a set Y position. This is the code I have up till now:

if nargin<4, strands = 0; end;
if nargin<3, height = 0.1; end;
if nargin<2, y = 2.1; end;

    for k=1:size(cds,1),
        xc = [cds(k,1) cds(k,2) cds(k,2) cds(k,1)];
        if strands,
            if cds(k,3), % minus strand
                yc = [y y y-height/2 y-height/2];
                c = 'r';
            else % plus strand
                yc = [y+height/2 y+height/2 y y];
                c = 'b';
            end
        else
            yc = [y+height/2 y+height/2 y-height/2 y-height/2];
            c = 'b';
        end
        h(k) = patch(xc,yc,c);
    end

What I'm trying to do is add lines underneath each 'box' which corresponds to the gene number (4th collumn of the dat开发者_运维问答a matrix). How would I go about doing this with the plot function?


It's not clear from your question how you want the lines to indicate the gene numbers, I assume you want different colors for each type. Here is how I would do it:

cds = [
    1     29           1        1
    32     38           1        1
    44     60           1        1
    66     70           0        2
    75     80           0        2
    81     88           0        3
    99    102           0        3
    111    160           0        3
    166    170           1        4
    171    188           1        4
];

strands = 0;
height = 0.1;
y = 2.1;

[g,gIdx,gNum] = unique(cds(:,4));
clr = 'gcmykrb';

for k=1:size(cds,1),
    xc = [cds(k,1) cds(k,2) cds(k,2) cds(k,1)];
    if strands,
        if cds(k,3), % minus strand
            yc = [y y y-height/2 y-height/2];
            c = 'r';
        else % plus strand
            yc = [y+height/2 y+height/2 y y];
            c = 'b';
        end
    else
        yc = [y+height/2 y+height/2 y-height/2 y-height/2];
        c = 'b';
    end
    h(k) = patch(xc,yc,c);

    hLine(k) = line([cds(k,1) cds(k,2)], [y-3*height/4 y-3*height/4], ...
        'LineWidth',5, 'Color',clr(gNum(k)));
end
legend(hLine(gIdx), num2str(g), 'Orientation','horizontal')

How do I add lines connecting corresponding boxes, that I've drawn on a plot? (MATLAB)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜