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