Search code examples
matlabmatlab-figurebioinformatics

Error in creating a volcano plot in MATLAB


I am a complete newbie to MATLAB and the first task I have is to create a volcano plot. I have been using the documentation to understand about it and get started.

I tried to run it on dummy values -

a=[1 2 3]
b=[4.6 2.7 4.5]
c=[0.05 0.33 0.45]

And then I ran -

SigStructure = mavolcanoplot(a, b, c)

My understanding is that a represents the gene expression values for condition 1, b for condition 2, and c is the list of p-values for the 3 data points in a and b.

However running this code gives me the error -

Index exceeds matrix dimensions.

Error in mavolcanoplot (line 127)
appdata.effect = X(paramStruct.goodVals) - Y(paramStruct.goodVals);

Error in volc (line 4)
SigStructure = mavolcanoplot(a, b, c)

Can anyone explain where I am going wrong?


Solution

  • You're encountering an issue because you are using row vectors.

    Inside the mavolcanoplot function (you can see the file by typing edit mavolcanoplot in the command window) there is a local function for checking the inputs, called check_inputdata.

    Your data passes all of the validation checks, and then encounters this section:

    % Here, 'X' and 'Y' are the local names for your inputs 'a' and 'b'
    % Below code is directly from mavolcanoplot.m:
    
    % Handle the matrix input. Use its mean values per row
    if size(X, 2) > 1
        X = mean(X,2);
    end    
    if size(Y, 2) > 1
        Y = mean(Y,2);
    end
    

    This reduces your inputs to their mean. Later in the main function (line 127) you encounter the error as described, where paramStruct.goodVals is a 3 element array, which is now trying to index a 1 element array and fails!


    This is basically a lesson in debugging and reading the documentation, which states

    DataX, DataY: If a [...] matrix, each row is a gene, each column is a sample and an average expression value is calculated for each gene.

    You should use one of these equivalent methods to create column vector inputs

    a=[1 2 3].';       % Using transpose (.') to create a column vector from a row vector
    b=[4.6; 2.7; 4.5]; % Creating a column vector using the semi-colon operator to end each row
    c=[0.05
       0.33
       0.45];          % Using actual code layout to create a column vector