Compatibility or syntax issue while running a 2014 script ?

Hello,
I'm trying to run a script (written under the R2012b version of mathlab) with the R2016a matlab version, but I have few warnings and the program can't be run. The script is part of a method (ARTIST) used to analyse a biology experiment (Tn-seq) that the authors published in the journal Plos Genetics in 2014 (so it is supposed to work, or was). My problem is that, when the first function is called, an error occurs and I get this message: 'Unexpected MATLAB expression.'.The error refers to the second input of the first function:
function [Chr1_names, Chr1_starts, Chr1_ends, TAsites, TAid] = genome_parser_TA (VCgft, *'chrI'*, 2961149, 'VC_chr1.fa', 'TA')
Imputs are from different types (table, number, character chain, or a reference to a file on the workspace) (I don't know if it is important or not). I have several errors here, 3 imputs are issues ('chrI', 2961149 and 'VC_chr1.fa') and the last parenthesis is one too. When I pass my cursor over the warnings I get different messages:
  • For 'chrI', it is written: Parse error at "chrI": usage might be invalid MATLAB syntax.There is the same error with the parenthesis. (is it produced by the first error or because the software can't recognize the function ?)
  • For the two last warnings, it is said: "Terminate statement with semicolon to supress output (within a script).
Does someone know what would be the issue I experience here ?
I am a beginner with this sowftware, as I'm testing the software and the method quoted above. Thus, I don't clearly know what would be the problem here. However I fear one: might these errors be created by the evolution of the MATLAB syntax over the passed versions thus making the script obsolete ?
Thanks in advance for your answers,
Quentin.

 Akzeptierte Antwort

Steven Lord
Steven Lord am 25 Aug. 2016
That line looks like a combination of the syntax to define a function and the syntax to call a function. That line either needs to specify variable names (to define the function) or values (to call it.)
An example of function definition
function [a, b, c] = myfunction(d, e, f)
An example of function calling
x = 1:10;
[out1, out2, out3] = myfunction(17, 'single', x)

3 Kommentare

Ok !
I think I understand the problem. The script I am trying to run is in fact the function definition. Then, I am supposed, once the script run, to call manually the function by the command window, specifying the arguments I want the function to work with.
From the beginning I have tried to insert the inputs directly in the function definition. That explains why it did not worked. ^^' Here is the code before my modifications.
function [Chr1_names, Chr1_starts, Chr1_ends, TAsites, TAid] = genome_parser_TA (GTFtable, chr_search_term, chrom_end, fasta,motif)
So, if I understand, that would be the function definition and it is followed by the operations the function will perform when you call it?
Yet, when I run the script I have another error. It refers to the line just after the function definition :
function [Chr1_names, Chr1_starts, Chr1_ends, TAsites, TAid] = genome_parser_TA (GTFtable, chr_search_term, chrom_end, fasta,motif)
GTF_file=GTFtable;
It tells me that the function 'genome_parser_TA' needs more inputs arguments. It seems to refer to GTFtable which is already stated among the inputs arguments. Can you see any mistakes here ?
Addressing this part of your comment: So, if I understand, that would be the function definition and it is followed by the operations the function will perform when you call it?
That is correct. That should be in a file named genome_parser_TA.m.
Addressing this part of your comment: It tells me that the function 'genome_parser_TA' needs more inputs arguments.
That too is correct. You need to call the function with the correct number of input arguments. As written, genome_parser_TA is defined to accept 5 input arguments. While it is possible that the author defined genome_parser_TA to handle the case where it is given fewer than 5 inputs by using a default value for one or more of the later inputs, the function uses the first input immediately and so the function MUST be called with at least one input.
FYI, pressing the Run button in the Editor calls the function with 0 input arguments, and so you couldn't run this function that way, at least not without some additional setup.
Quentin
Quentin am 29 Aug. 2016
Bearbeitet: Quentin am 29 Aug. 2016
I am sorry for the time of response, I did not had the notification for your answer.
Ok ! I thought I had to run manually the script that defines the function, so the program has it in memory, before calling the function (as it is roughly done in C++ language)! Of course, now that I just call the function it works almost perfectly! I still have a problem with a 'fastaread' function but I think its a format issue, and that's not the purpose of this subject.
I am sorry for those questions that are due to my lack of experience with the MATLAB language and I hope I have not waisted your time.
Anyway, thank you again for your quick answers and your help !

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Guillaume
Guillaume am 24 Aug. 2016
function ... = ...(x, *'chrI'*, xx, 'VC_chr1.fa', 'TA')
This has never been valid syntax in matlab. Neither * nor ' can be included in variable names. This code would not work under 2012b either.
Possibly, remove the * and ' in that function declaration and see if it works.

6 Kommentare

Thank you for your quick response.
The * was not present in the script, it is an error I made while copying the script.
When I remove the single quotes, the error for 'chrI' disappears as well as the warning for all inputs with ' (that I have removed too). Yet, it displays the same error I had for 'chrI' but this time for the next input (2961149).
Can you attach the function or at least show the code for the line that is causing problem.
Quentin
Quentin am 25 Aug. 2016
Bearbeitet: Quentin am 25 Aug. 2016
Part of the problem was solved : I tried to call the function using its declaration. I explain the thing in my answer to Steven Lord. I have another problem now, described in the same answer. If you can check that it would be kind if not thank you for your help !
Please show the exact code that you use to call the function. For the function to work, you would have to call it with at least:
out1 = genome_parser(arg1) %replace arg1 with actual name of variable.
And if all inputs are required:
out1 = genome_parser(arg1, arg2, arg3, arg4, arg5); %replace argx by actual input variable.
And if you need all outputs:
[out1, out2, out3, out4, out5] = genome_parser(____); %replace outx by actual output variable
In fact, the problem was solved. As I explain on the commments on Steven Lord's answer below, I misunderstood how functions works in the MATLAB language. First, I thought I had to specify the arguments in the function declaration, located in the script defining the function. Then, I thought I had to "run" the script of the function definition so the program will memorise it (as it is roughly done in C++ language).
So all my problems were due to my lack of experience with this MATLAB language. Thank you for all you quick answers !

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Gefragt:

am 24 Aug. 2016

Kommentiert:

am 29 Aug. 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by