Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expecting EOF, found '<something>'

My 1st post here so I'll try to keep it simple. I'm trying to create a plot of some mass spectrometry data using Processing. I wanted to write a sketch to parse data from pseudo-XML into tables and then to plot this data as points on 2 axes (time, mz) with the third axis, the signal, as the colour of the point.

At this stage I want the plot to be the dimensions of the data. In my test data this is 38 time points on the x axis, 51 mz points on the Y and signal ranging from 0 to 12,000. The bounds of a real data set will be a hundred times bigger in every dimension.

My issue is that the width and height of the plot is dependent on the data and establishing these limits involves a bit of code. In Processing you can only call size() immediately after void setup() so I put all the calculation code first. This threw the title error. I couldn't work around it so I output the data to three csv files and started on a 2nd sketch to import that data and plot it. I've run into the same error.

The exact error is expecting EOF, found '', where can be the first word on a line. It has been for, mzTable and if, depending on the code I've tried.

Here's the second sketch in full:

import java.io.*;

int debug = 1;

String target = "M1A crop.txt";  // test data


File file = new File(target);

// ~  ~  ~  

String folderPath = file.getParent(); // target folder path
String name = file.getName(); 

String mzData = folderPath + "\\" + name + " - mz data.csv" ;    // CSV file to open
String signalData = folderPath + "\\" + name + " - signal data.csv" ;    // CSV file to open
String summaryData = folderPath + "\\" + name + " - summary data.csv" ;    // CSV file to open

Table mzTable = new Table();
Table signalTable = new Table();
Table summaryTable = new Table();

mzTable = loadTable(mzData, "header");
signalTable = loadTable(signalData, "header");
summaryTable = loadTable(summaryData, "header");

int timeMin = summaryTable.getInt(0, "timeMin");
int timeMax = summaryTable.getInt(0, "timeMax");
int mzMin = summaryTable.getInt(0, "mzMin");
int mzMax = summaryTable.getInt(0, "mzMax");
int signalMin = summaryTable.getInt(0, "signalMin");
int signalMax = summaryTable.getInt(0, "signalMax");

width = mzTable.getColumnCount();  // this is the number of time points on the X axis
height = mzMax - mzMin;  // this is the number of mz points on the Y axis

println("time Min: " + timeMin + ", Max: " + timeMax);
println("mz Min: " + mzMin + ", Max: " + mzMax);
println("signal Min: " + signalMin + ", Max: " + signalMax);


void setup() {
  size(width, height);

}    // end of void setup()


void draw() {
  for(int x = 0; x < height; x++) {
    for(int y = 0; y < width; y++) {
      stroke(map(signalTable.getInt(x, y), signalMin, signalMax, 0, 255));
      point(x, y);
    }
  }  
}

The source of the error is identified as coming from line 19:

mzTable = loadTable(mzData, "header");

I'm no hacker but I can see there's nothing wrong with that code. If I comment out everything from void setup() onwards the code runs so its something to do with having the import and summary code outside of that function. If I put bad code in front of it, such as just for( then I get expecting EOF, found 'for'. Can anyone tell me why?

Many thanks in advance,

Chris

edited for derp 20:20 1-5-15

edit 22:00 1-5-15 I've just tried the sketch in Processing 3.0a7, which has much better error reporting. It has identified a different error with line 19: Syntax error on tokens, delete these tokens. Searching for this error lead me to this questions with suggestions of a diagnosis. Syntax error on tokens, delete these tokens

like image 692
Ninja Chris Avatar asked May 01 '15 09:05

Ninja Chris


1 Answers

The only thing you should have at the top of your sketch are declarations. You can't have random code like reassignment and calls to the println() function up there. Code like that needs to be inside of a function.

For example, this line is fine because it's a declaration:

Table mzTable = new Table();

But this line is a no-go, because it's not a declaration:

mzTable = loadTable(mzData, "header");

To fix that error, you can combine them into one single declaration line:

Table mzTable = loadTable(mzData, "header");

Similarly, you can't have calls like this outside of a function, since it's not a declaration:

println("time Min: " + timeMin + ", Max: " + timeMax);

Get rid of those println() functions, or move them into the setup() function.

Same with these lines:

width = mzTable.getColumnCount();  // this is the number of time points on the X axis
height = mzMax - mzMin;  // this is the number of mz points on the Y axis

Those aren't declarations, so they have to be inside a function. Maybe try something like this:

void setup() {
  width = mzTable.getColumnCount();  // this is the number of time points on the X axis
  height = mzMax - mzMin;  // this is the number of mz points on the Y axis
  size(width, height);
}

Although, using the width and height variables like that seems like a bad idea, so instead you might do this:

void setup() {
  size(mzTable.getColumnCount(), mzMax - mzMin);
}

Processing will then set the width and height variables for you.

like image 55
Kevin Workman Avatar answered Nov 13 '22 08:11

Kevin Workman