/*************************************************************************** * Author: Jianwei(Jerry) Li. * Name: ScanArrayTav (Version 1.0) * Date: Created: 04/04/2002 and modified: 04/04/2002 * Descp: A Java class that reads a ScanArray file and write it as a .tav file ***************************************************************************/ package org.tigr.microarray.converter; import java.util.*; import java.awt.*; import java.io.*; import javax.swing.*; import org.tigr.util.FileReading; import org.tigr.util.StringSplitter; import org.tigr.util.io.MyIni; public class ScanArrayTav extends Converter { private JFrame parent; private String bgChA, bgChB; private String chA, chB; private String chApixel, chBpixel; private String saFileName; private String tavFileName; private FileReading fileReader; private int numSpot; private int areaPixel; // area in pixels private int quantWay; private boolean keepAll, gSwap; private final int TOTAL = 1; private final int MEAN = 2; private final int MODE = 3; private final int MEDIAN = 4; private final String ARRAY_ROW = "Array Row"; private final String ARRAY_COL = "Array Column"; private final String BEGIN_DATA = "Begin Data"; private final String COLUMN = "Column"; private final String END_DATA = "End Data"; private final String RW = "Row"; private final String INTENSITY = "Intensity"; private final String BKG = "Background"; private final String AREA = "Area"; private final String NULL = "null"; /**************************************************************************** *Constructor: *
Parameters:
*
sfName --- the name of ScanArray file to be converted.
*
tfName --- the name of .tav file that is an output.
*
way -- the protocol to generate the intensity in ScanArray file.
*****************************************************************************/
public ScanArrayTav(String sfName, String tfName, int way) {
inFileNames = new Vector(1);
outFileNames = new Vector(1);
inFileNames.add(sfName);
outFileNames.add(tfName);
ready = false;
wantSort = true;
keepAll = true;
gSwap = false;
fetalError = false;
minorError = false;
quantWay = way;
}
/****************************************************************************
*Constructor:
*
Parameters:
* Parameters:
* Return: the background information
***************************************************************************/
private String calculateBackground(String[] tuple, int backg){
float fPix, bMedian;
int temp;
//float temp;
String bg = new String("");
try{
fPix = Float.parseFloat(tuple[areaPixel]);
bMedian = Float.parseFloat(tuple[backg]);
temp = (int)(bMedian * fPix);
//temp = (bMedian * fPix);
bg += temp;
} catch (NumberFormatException nfex) {
minorError = true;
bg = "null";
msg += "**********\n";
msg += "There is an unacceptable value to calculate background;\n";
msg += "and the background was set to null.\n";
}
return bg;
}
/****************************************************************************
* Description:
* calculate density for a channel
* Parameters:
* Return: the density
***************************************************************************/
private String calculateDensity(String[] tuple, int med, int backg, int areaIndx){
float fMedian, bMedian, fPix, fSat;
int temp;
//float temp;
String den = new String("");
try{
fMedian = Float.parseFloat(tuple[med]);
bMedian = Float.parseFloat(tuple[backg]);
fPix = Float.parseFloat(tuple[areaIndx]);
fPix = fPix / 100;
temp = (int)((fMedian - bMedian) * fPix);
den += temp;
} catch (NumberFormatException nfex) {
minorError = true;
den = "null";
msg += "**********\n";
msg += "There is an unacceptable value to calculate intensity; and the intensity was set to null.\n";
}
return den;
}
/****************************************************************************
* Description:
* calculate spot area in the number of pixels.
* Parameters:
* Return: the area.
***************************************************************************/
private int calculateSpotArea(String[] tuple, int areaIndx){
float area;
int temp;
area = Float.parseFloat(tuple[areaIndx]);
area = area / 100;
temp = (int) area;
return temp;
}
/*****************************************************************************
*Description:
* retrieve a value from the ScanArray file base on the passed key.
* Parameter:
* Return: the value and its line number (address) in the file.
***************************************************************************/
private String[] getValueAndIndex(Vector fileCont, String key){
StringTokenizer token = null;
int size = fileCont.size();
String temp = new String("");
String wantKey = new String("");
String value[] = new String[2];
for(int i=0; i Parameter:
* Parameters:
* Return: the index of the column
****************************************************************************/
private int findRightCol(String str[], String key){
int addr = 0;
int size = str.length;
int i;
String temp = new String("");
for(i=0; i Parameter:
* Return: true if the input is a character; otherwise, false.
****************************************************************************/
private boolean isChar(char x){
boolean b = true;
switch(x) {
case '1': case '2': case '3': case '4': case '5': case '6': case '7':
case '8': case '9': case '0':
b = false;
break;
default: b = true;
}
return b;
}
/*****************************************************************************
*DESCRIPTION:
* set all other annotation information to a string for attaching
* Parameters:
* RETRUNED: the annotation info
***************************************************************************/
private String setAnnotaionInfo(String[] val, int[] noNeed){
StringBuffer temp = new StringBuffer();
int i, j;
boolean want = true;
for(i=0; i
gfNames --- the names of GenePix files to be converted.
*
tfNames --- the names of .tav files that is an output.
*****************************************************************************/
public ScanArrayTav(JFrame p, Vector sfNames, Vector tfNames, int way) {
parent = p;
inFileNames = sfNames;
outFileNames = tfNames;
msg = new String("");
ready = false;
wantSort = true;
keepAll = true;
gSwap = false;
fetalError = false;
minorError = false;
quantWay = way;
}
public int getTaskEnd() { return taskEnd; }
public String getFileName() { return saFileName; }
public int getCurrent() { return counter; }
public String getErrorMsg() { return msg; }
/***************************************************************************
* Description:
* overrides an abstract method to implement the main function of class.
**************************************************************************/
public void run () {
boolean noError;
String aLine = new String("");
String densA = new String("");
String densB = new String("");
String tavLine = new String("");
String flagA = new String("");
String flagB = new String("");
String bgA = new String(""); // background info for channel A
String bgB = new String(""); // background info for channel B
String colValues[];
String extraInfo = new String("");
String colNames[];
String channels[] = {"ch1", "ch2"};
String dataStart[], dataEnd[];
int numOfFiles;
int hLines; // the index of header of data section
int lastLine; // the index of last line of data
int max = 0;
int maxRow = 0;
int maxCol = 0;
int maxArrayRow = 0; // meta row
int maxArrayCol = 0; // meta column
int row, col, metaRow, metaCol, slideRow, slideCol;
int i, j, k, flagInt, arrayRowIndex, arrayColIndex, colIndex, rowIndex;
int ch1IntenLoc, ch1Bkg, ch1AreaLoc, ch2IntenLoc, ch2Bkg, ch2AreaLoc;
int spAreaA, spAreaB;
int needLoc[] = new int[10];
Vector scanArrayFile;
BufferedWriter bufWriter = null;
FileOutputStream fileOut = null;
FileReading fileReader;
taskEnd = determineTaskEnd();
if(taskEnd == 1){
return;
}
taskEnd <<= 1;
counter = 0;
numOfFiles = inFileNames.size();
for(i=0; i
tuple -- all information in one row
*
backg -- address for background medien column
*
tuple -- all information in one row
*
med -- address for either channel A or B median column
*
backg -- address for background medien column
*
tuple -- all information in one row
*
areaIndx -- address for spot area.
*
fileCont --- whole content of file.
*
key --- to match the wanted value.
*
chs --- the names of channels.
***************************************************************************/
private void defineKeys(String[] chs) {
chA = new String(chs[0] + " " + INTENSITY);
chB = new String(chs[1] + " " + INTENSITY);
chApixel = new String(chs[0] + " " + AREA);
chBpixel = new String(chs[1] + " " + AREA);
bgChA = new String(chs[0] + " " + BKG);
bgChB = new String(chs[1] + " " + BKG);
}
/****************************************************************************
* Description:
* find the address of the column that is interested.
*
str -- a line of the file
*
key -- column name to be searched
*
x --- the input to be checked.
*
val --- all info of a spot
*