/*************************************************************************** * Author: Jianwei(Jerry) Li. * Name: CustomerMev (Version 1.0) * Date: Created: 10/11/2004 and modified: 10/11/2004 * Descp: A Java class that reads an input file and write it as a .mev file base * on what the user defined. ***************************************************************************/ package org.tigr.microarray.converter; import java.util.*; import java.awt.*; import java.io.*; import javax.swing.*; import org.tigr.microarray.MevAttributes; import org.tigr.util.FileReading; import org.tigr.util.formula.node.EvaluateException; import org.tigr.util.formula.MathExpression; import org.tigr.util.formula.Variant; import org.tigr.util.MyStringTokenizer; import org.tigr.util.StringSplitter; import org.tigr.util.io.IOUtil; import org.tigr.util.MyTimer; public class CustomerMev extends MevConverter implements MevAttributes, Variant { private final int TOTAL = 0; private final int MEAN = 1; private final int MODE = 2; private final int MEDIAN = 3; private final String DESC = "Description"; private int gAnnType; private int gNumMevCols; // the number of mev columns private int gInHeaderAddr; private int[] gSelCols, gSelAnnHd; private JFrame parent; private MathExpression[] gFormulas; private String inFileNamePath; private String gMevFileName; private String barTitle; private String[] gMevHeaders, gConvEquation, gInputHeader; /**************************************************************************** *Constructor: *
Parameters:
*
cfName --- the name of input file to be converted.
*
mfName --- the name of mev file that is an output.
*
title -- the string showed on the window bar.
*****************************************************************************/
public CustomerMev(String cfName, String mfName, String title) {
super();
inFileNames = new Vector(1);
outFileNames = new Vector(1);
inFileNames.add(cfName);
outFileNames.add(mfName);
barTitle = title;
}
/****************************************************************************
*Constructor:
*
Parameters:
* Parameters:
* Return: the value of cell for mev.
**************************************************************************/
private String convertCell(String[] aRow, MathExpression equation){
int indx;
String val = new String("0");
try{
val = equation.evaluate(aRow);
} catch (EvaluateException ee){
val = "0";
}
/*String formula[];
if(formula.length > 1){
} else {
indx = getInputFileHeaderOffset(formula[0]);
if(indx > 0){
val = aRow[indx];
}
}*/
return val;
}
/****************************************************************************
* Description:
* creates a header for both mev and dat(annotation) file.
* Parameter:
* Return: the header as an array.
**************************************************************************/
private String[] generateHeader(String[] cNames, String fName, int numRow, boolean mev){
int i, j, k, indx, inAddr, count;
int[] cols;
String[] tempHeader, formula;
if(mev){
tempHeader = new String[7 + gNumMevCols];
} else {
tempHeader = new String[7];
}
tempHeader[0] = new String(PAN + SPACE + VERSION + COLON + " V1.0");
tempHeader[1] = new String(PAN + SPACE + FORMAT_VERSION + COLON + ExpressConverter.MEV_VER);
tempHeader[2] = new String(PAN + SPACE + DATE + COLON + SPACE + MyTimer.getCurrentDateAndTime('.'));
tempHeader[3] = new String(PAN + SPACE + CREATED_BY + COLON + SPACE + barTitle);
tempHeader[4] = new String(PAN + SPACE + ROW_COUNT + COLON + numRow);
tempHeader[5] = new String(PAN + " converted from the file: " + fName);
indx = 6;
if(mev){
count = 0;
for(i=0; i Parameter:
* Return: the number, otherwise, -1.
**************************************************************************/
private int getInputFileHeaderOffset(String item){
int num;
try{
num = Integer.parseInt(item);
} catch (NumberFormatException nfe){
return -1;
}
return num;
}
/**************************************************************************
* Description:
* instantiates a writer object for ann file writing.
* Parameters:
* Return: the writer
****************************************************************************/
private BufferedWriter createAnnoWriter(String[] cNames, String fName, String inName,
int numSpots){
BufferedWriter out;
FileOutputStream fOut;
String annoFileHeader[];
try {
fOut = new FileOutputStream(fName);
out = new BufferedWriter(new OutputStreamWriter(fOut));
annoFileHeader = generateHeader(cNames, inName, numSpots, false);
for(int i=0; i Parameter:
* Return: an string array that contains the operators and operants.
***************************************************************************/
private String[] parseEquation(String eq){
int count = 0;
String[] temp;
MyStringTokenizer token = new MyStringTokenizer(eq, OPERATORS, true);
temp = new String[token.countTokens()];
while(token.hasMoreTokens()){
temp[count++] = token.nextToken();
}
return temp;
}
/***************************************************************************
* Description:
* sets the values of a row for ann file.
**************************************************************************/
private StringBuffer setAnnRow(StringBuffer sb, String id, int r, int c, String[] vals){
sb.append(id);
if(wantSort){
sb.append(TAB).append(r).append(TAB).append(c);
}
for(int i = 0; i
cfNames --- the names of input files to be converted.
*
mfNames --- the names of mev files that are outputs.
*
title -- the string showed on the window bar.
*
annNum --- the ann file type, one for one / many for one.
*****************************************************************************/
public CustomerMev(JFrame p, Vector cfNames, Vector mfNames, String title, int annNum) {
super();
parent = p;
inFileNames = cfNames;
outFileNames = mfNames;
barTitle = title;
gAnnType = annNum;
gInHeaderAddr = -1;
}
/***************************************************************************
* Description:
* overrides an abstract method to implement the main function of class.
**************************************************************************/
public void run () {
boolean noError;
boolean consqId = false;
BufferedWriter annoWriter = null;
BufferedWriter mevWriter = null;
FileReading fileReader;
FileOutputStream mevFileOut = null;
int lastLine; // the index of last line of data
String aLine = new String("");
String annoFileNamePath;
String unid = new String("");
String inputFileName;
String colNames[];
String colValues[];
String custFile[];
String annoFile[] = null;
String mevFileHeader[];
StringBuffer mevLine = new StringBuffer(200);
StringBuffer extraInfo = new StringBuffer(200);
int numOfFiles;
int slideRow = 0;
int slideCol = 0;
int i, j, k, flagInt, numSpot;
taskEnd = determineTaskEnd();
if(taskEnd == 1){
return;
}
taskEnd <<= 1;
counter = 0;
numOfFiles = inFileNames.size();
gNumMevCols = getMevValidColumns();
gFormulas = new MathExpression[gConvEquation.length];
for(i=0; i
aRow -- the data of a row (gene) of input file.
*
equation -- a formula based on which the conversion processed.
*
cNames -- the header of the input file.
*
fName -- the mev file name that should be written to the file.
*
numRow -- the number of spots (genes/row).
*
mev -- indicate if the header is for ann or mev.
*
item -- the item to be converted.
*
cNames --- the header of agilent file.
*
fName --- ann file name to be written.
*
inName --- the input file name.
*
numSpots --- the number of rows in the input file.
*
eq -- the equation to be splitted.
*