function [N,gfpmean,gfpse,redmean,redse,tofmean,tofse,gtmean,gtse,rtmean,rtse,yfpmean,yfpse,ytmean,ytse,extmean,extse]=v1COPASFun(file,answers)
% The file is sent to this function from the import function COPASImp. To
% run this function alone, type
% fid=fopen('EV_1.txt');
% instead of fid=fopen(file); where 'EV_1.txt' is your file name.
fid=fopen(file);
Array=textscan(fid,'%s',-1,'delimiter','\t');
% \t tells MATLAB that the file is tab delimited. -1 tells it to read the
% whole file. %s tells it to read the cells as strings (as opposed to as
% numbers).
[l,wide]=size(Array{1,1});
L=l-10;
fclose(fid);
% This textscan was simply to find out how many rows (worms) are in our
% file. We have to subtract 10 because there are 10 non-data cells at the
% end of the file.
fid=fopen(file);
% We closed the file and now open it again, first reading only the first 26
% cells (the column labels) as strings, then starting to acually import the
% data.
Array2=textscan(fid,'%s',26,'delimiter','\t');
Array3=textscan(fid,'%*f %*f %*f %*f %*s %*f %*f %f %f %f %f %f %f %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s',L,'delimiter','\t');
fclose(fid);
% %f reads a number and converts it to double. %s reads a string. Since
% there are letters and titles in the COPAS document, the first 26 cells
% must be read as strings because they are the column labels. From then
% on, we read most columns as numbers, except columns 5, 16, and 19, which
% include letters such as N or n/a and so must be read as strings. An *
% between the % and the letter means that column is not being imported.
%Array3 is thus only the numerical data of columns 8-13. To read any other
%columns, just delete the * that is after the %. You will also have to add
%new columns to the Data matrix below and new export variables.
[length,width]=size(Array3{1,1});
% This is how many worms are in your sample -- the length of this last
% array we made.
data=[Array3{1,1},Array3{1,2},Array3{1,3},Array3{1,4},Array3{1,5},Array3{1,6}];
% We imported six columns. Now we have one matrix, Data, that contains all
% six columns. Next, we calculate the new columns we need (like Green over TOF)
% and the statistics (mean and SEM) we want. The '.' is to correct for
% matrix division (divide each cell pair individually).
Data=[];
if answers(1,1)==1
for i=1:length
if data(i,1)==40
Data=[Data;data(i,:)];
end
end
elseif answers(1,1)==2
for i=1:length
if data(i,1)~=40
Data=[Data;data(i,:)];
end
end
elseif answers(1,1)==0
Data=data;
else
Data=data;
end
[n,w]=size(Data);
%In our data sets, Green is Ch 1, Yellow is Ch 2, Red is Ch 3.
GFP=Data(:,4);
TOF=Data(:,2);
RED=Data(:,6);
Ext=Data(:,3);
YFP=Data(:,5);
GT=GFP./TOF;
YT=YFP./TOF;
RT=RED./TOF;
% sem=(std(GFP)/sqrt(n))
gfpmean=mean(GFP);
gfpse=std(GFP);
yfpmean=mean(YFP);
yfpse=std(YFP);
redmean=mean(RED);
redse=std(RED);
tofmean=mean(TOF);
tofse=std(TOF);
gtmean=mean(GT);
gtse=std(GT);
rtmean=mean(RT);
rtse=std(RT);
ytmean=mean(YT);
ytse=std(YT);
extmean=mean(Ext);
extse=std(Ext);
N=n;
% These are the values that will be exported back to COPASImp.