/* Copyright @ 2003, The Institute for Genomic Research (TIGR). All rights reserved. */ /***************************************************************************** * Description: A class that reads a set of GenePix (gpr) files and write to * MEV files. * Company: TIGR * @author Jianwei (Jerry) Li * @version 1.5 * @Date: Created: 02/25/2003 and modified: 06/04/2004 * Modified history: * 06/04/04: provides the option to write only one ann file for a set of mev * files that are produced with the same array design. *****************************************************************************/ 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.StringSplitter; import org.tigr.util.io.MyIni; import org.tigr.util.io.IOUtil; import org.tigr.util.MyTimer; public class GenepixMev extends MevConverter implements MevAttributes{ private String bgChA, bgChB, bgChAn, bgChBn; private String chA, chAn, chB, chBn; private String chAs, chAsn, chBs, chBsn; private String title; // the massege showed on the bars of all windows. private Vector mevFileNames; private int fPixAddr, gAnnType; private final int FIRST_NUM = 1; private final String FLAG = "\"Flags\""; private final String BLOCK = "\"Block\""; private final String COLUMN = "\"Column\""; private final String RW = "\"Row\""; private final String F_PIX = "\"F Pixels\""; private final String FLAG_N = "Flags"; private final String BLOCK_N = "Block"; private final String COLUMN_N = "Column"; private final String ROW_N = "Row"; private final String F_PIX_N = "F Pixels"; private final String WAVE_KEY_1 = "ImageName"; private final String WAVE_KEY_2 = "Wavelengths"; final String ID = "ID"; final String ID_N = "\"ID\""; final String NAME = "Name"; final String NAME_N = "\"Name\""; /**************************************************************************** *Constructor: *
Parameters:
*
gfName --- the name of GenePix file to be converted.
*
mfName --- the name of .mev file that is an output.
*****************************************************************************/
public GenepixMev(String gfName, String mfName) {
super();
inFileNames = new Vector(1);
mevFileNames = new Vector(1);
inFileNames.add(gfName);
mevFileNames.add(mfName);
title = new String("Genepix vs Mev");
}
/****************************************************************************
*Constructor:
*
Parameters:
* Parameters:
* Return: the spot area.
***************************************************************************/
private int calculateSpotDimeter(String[] tuple, int sat){
float fSat, fPix;
int temp;
fPix = Float.parseFloat(tuple[fPixAddr]);
fSat = Float.parseFloat(tuple[sat]);
fSat = fSat / 100;
temp = (int) (fPix * (1 - fSat));
return temp;
}
/****************************************************************************
* Description:
* calculate background for a channel with bg = median * area
* 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[fPixAddr]);
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 for either F Pixcel or B Median;\n";
msg += "and the background was set to null.\n";
}
return bg;
}
/****************************************************************************
* Description:
* calculate integrate intensity for a channel
* Parameters:
* Return: the density
***************************************************************************/
private String calculateIntegrateDensity(String[] tuple, int med, int sat, int backg,
boolean bgSub){
float fMedian, bMedian, fPix, fSat;
int temp;
String den = new String("");
try{
fMedian = Float.parseFloat(tuple[med]);
bMedian = Float.parseFloat(tuple[backg]);
fPix = Float.parseFloat(tuple[fPixAddr]);
fSat = Float.parseFloat(tuple[sat]);
fSat = fSat / 100;
if(bgSub){
temp = (int)(fPix * (fMedian - bMedian) * ( 1 - fSat));
} else {
temp = (int)(fPix * fMedian * ( 1 - fSat));
}
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 median intensity for a channel
* Parameters:
* Return: the density
***************************************************************************/
private String calculateMedianIntensity(String[] tuple, int med, int backg,
boolean bgSub){
float fMedian, bMedian;
float temp;
String den = new String("");
try{
fMedian = Float.parseFloat(tuple[med]);
bMedian = Float.parseFloat(tuple[backg]);
if(bgSub){
temp = fMedian - bMedian;
} else {
temp = fMedian;
}
den += (int)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:
* creates a header for both mev and dat(annotation) file.
* Parameter:
* Return: the header as an array.
**************************************************************************/
private String[] generateHeader(String fName, int numRow, boolean mev){
String[] tempHeader;
String bkgVal;
if(mev){
tempHeader = new String[8];
} else {
tempHeader = new String[7];
}
if(gBkgCorrect){
bkgVal = ON;
} else {
bkgVal = OFF;
}
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 + title);
tempHeader[4] = new String(PAN + SPACE + ROW_COUNT + COLON + numRow);
tempHeader[5] = new String(PAN + " converted from GenePix file: " + fName);
if(mev){
tempHeader[6] = new String(PAN + SPACE + BKG_CORRECT + COLON + bkgVal);
if(gUseMedian){
tempHeader[7] = UID + TAB + MEDA + TAB + MEDB + TAB + R + TAB + C + TAB +
MR + TAB + MC + TAB + SR + TAB + SC + TAB + BKGA + TAB + BKGB + TAB +
FLAGA + TAB + FLAGB + TAB + SAA + TAB + SAB + TAB + IA + TAB + IB;
} else {
tempHeader[7] = UID + TAB + IA + TAB + IB + TAB + R + TAB + C + TAB +
MR + TAB + MC + TAB + SR + TAB + SC + TAB + BKGA + TAB + BKGB + TAB +
FLAGA + TAB + FLAGB + TAB + SAA + TAB + SAB + TAB + MEDA + TAB + MEDB;
}
} else {
tempHeader[6] = UID + TAB + R + TAB + C + TAB + NAME + TAB + ID;
}
return tempHeader;
}
/****************************************************************************
* Description:
* find the wave lengths from the header information
* Parameters:
* Return: the wave lengths as an array.
****************************************************************************/
private String[] getWaveLengths(String str){
int num;
String wv;
String tempWave[] = new String[2];
String wavStr = new String(str.substring(str.indexOf('=')+1, str.lastIndexOf('\"')));
StringTokenizer token = new StringTokenizer(wavStr);
num = 0;
while(token.hasMoreTokens()){
wv = token.nextToken();
if(isNumber(wv)){
tempWave[num] = new String(wv);
num++;
}
}
return tempWave;
}
/**************************************************************************
* Description:
* instantiates a writer object for ann file writing.
* Parameters:
* Return: the writer
****************************************************************************/
private BufferedWriter createAnnoWriter(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(inName, numSpots, false);
for(int i=0; i Parameter:
* Parameters:
* Return: the index of the column
****************************************************************************/
private int findRightCol(String str[], String key, String noQuato){
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:
* check if a input string is a number.
* Parameter:
* Return: true if the input is a character; otherwise, false.
****************************************************************************/
private boolean isNumber(String x){
boolean b = true;
int length = x.length();
for(int i=0; i Parameter:
* Return: true if the input contains the info; otherwise, false.
****************************************************************************/
private boolean isWaveLengthDefination(String str){
String temp = str;
if(temp.charAt(0) == '\"' && temp.indexOf('=') > 0){
temp = temp.substring(1, temp.indexOf('='));
if(temp.equalsIgnoreCase(WAVE_KEY_1) || temp.equalsIgnoreCase(WAVE_KEY_2)){
return true;
} else {
return false;
}
} else {
return false;
}
}
/*****************************************************************************
*DESCRIPTION:
* set flag based on saturated pixels
* Parameters:
* RETRUNED: the flag
***************************************************************************/
private String setFlag(String[] tuple, int sat, int indx){
String f = new String("");
int flagInt;
float test, fPix, fSat;
flagInt = Integer.parseInt(tuple[indx]);
if(flagInt < 0){
f = "X";
} else {
fPix = Float.parseFloat(tuple[fPixAddr]);
fSat = Float.parseFloat(tuple[sat]);
test = fPix * (1 - fSat);
if(test < 10){
f = "A";
} else if (test >= 10 || test < 50){
f = "B";
} else {
f = "C";
}
}
return f;
}
}
gfNames --- the names of GenePix files to be converted.
*
mfNames --- the names of .mev files that is an output.
*
barTitle --- the string on the bar.
*
annNum --- the ann file type, one for one / many for one.
*****************************************************************************/
public GenepixMev(Vector gfNames, Vector mfNames, String barTitle, int annNum) {
super();
inFileNames = gfNames;
mevFileNames = mfNames;
title = barTitle;
gAnnType = annNum;
}
/***************************************************************************
* Description:
* overrides an abstract method to implement the main function of class.
**************************************************************************/
public void run () {
boolean going, noError;
String aLine = new String("");
String densA = new String("");
String densB = 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 medA = new String("");
String medB = new String("");
String mevFileName;
String annoFileNamePath, oneAnnFileName;
String gprFileName;
String colValues[];
String extraInfo = new String("");
String colNames[];
String mevFileHeader[];
String annoFile[] = null;
String waves[] = new String[2]; // first for channel A and second for B.
StringBuffer mevLine = new StringBuffer(200);
int hLines;
int max = 0;
int maxRow = 0;
int maxCol = 0;
int ident;
int maxMetaCol, block, row, col, metaRow, metaCol, slideRow, slideCol, spAreaA, spAreaB;
int i, j, k, flagInt, flagIndex, blockIndex, colIndex, rowIndex, idIndex, nameIndex;
int f635m, b635m, f635s, f532m, f532s, b532m;
int numOfFiles;
int fSize;
BufferedWriter mevWriter = null;
BufferedWriter annoWriter = null;
FileOutputStream mevFileOut = null;
FileReading fileReader;
Vector genepixFile = null;
taskEnd = determineTaskEnd();
if(taskEnd == 1){
return;
}
taskEnd <<= 1;
counter = 0;
numOfFiles = inFileNames.size();
for(i=0; i
tuple -- all information in one row.
*
sat -- address for saturated pixels column.
*
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
*
sat -- address for saturated pixels.
*
backg -- address for background medien column
*
bgSub -- indicate if an intensity should subtract backgroud.
*
tuple -- all information in one row
*
med -- address for either channel A or B median column
*
backg -- address for background medien column
*
bgSub -- indicate if an intensity should subtract backgroud.
*
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.
*
str -- a line of the file that contains wave lengths.
*
fName --- ann file name to be written.
*
inName --- the input file name.
*
numSpots --- the number of rows in the input file.
*
wvs --- the wave lenghts.
***************************************************************************/
private void defineKeys(String[] wvs) {
chA = new String("\"F" + wvs[0] + " Median\"");
chB = new String("\"F" + wvs[1] + " Median\"");
chAs = new String("\"F" + wvs[0] + " % Sat.\"");
chBs = new String("\"F" + wvs[1] + " % Sat.\"");
bgChA = new String("\"B" + wvs[0] + " Median\"");
bgChB = new String("\"B" + wvs[1] + " Median\"");
chAn = new String("F" + wvs[0] + " Median");
chBn = new String("F" + wvs[1] + " Median");
chAsn = new String("F" + wvs[0] + " % Sat.");
chBsn = new String("F" + wvs[1] + " % Sat.");
bgChAn = new String("B" + wvs[0] + " Median");
bgChBn = new String("B" + wvs[1] + " Median");
}
/****************************************************************************
* Description:
* find the address of the column that is interested.
*
str -- a line of the file
*
key -- column name to be searched
*
noQuato -- column name withouth quato.
*
x --- the input to be checked.
*
x --- the input to be checked.
*
str --- the input to be checked.
*
tuple --- the information of one spot
*
sat --- the address of satureated pixels
*
indx --- the address of orginal flag
*