/*************************************************************************** * Author: Jianwei(Jerry) Li. * Name: AlignetMev (Version 1.0) * Date: Created: 07/01/2004 and modified: 07/01/2004 * Descp: A Java class that reads an Agilent file and write it as a .mev file ***************************************************************************/ 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 AgilentMev extends MevConverter implements MevAttributes{ final String BG_MED_SIGNAL = "BGMedianSignal"; final String BG_NUM_PIX = "BGNumPix"; final String COL = "Col"; final String DESC = "Description"; final String FEATURES = "FEATURES"; final String FEATURE_NUM = "FeatureNum"; final String MED_SIGNAL = "MedianSignal"; final String NUM_PIX = "NumPix"; final String POS_X = "PositionX"; final String RW = "Row"; String gBkgMedSignalA, gBkgMedSignalB; String gBkgPixelA, gBkgPixelB; String gChApixel, gChBpixel; String gMedSignalA, gMedSignalB; private JFrame parent; private String inFileNamePath; private String mevFileName; private String barTitle; int gAnnType; int gPosX, gColIndex; private final int TOTAL = 0; private final int MEAN = 1; private final int MODE = 2; private final int MEDIAN = 3; /**************************************************************************** *Constructor: *

Parameters: *
afName --- the name of Agilent file to be converted. *
mfName --- the name of mev file that is an output. *
title -- the string showed on the window bar. *****************************************************************************/ public AgilentMev(String afName, String mfName, String title) { super(); inFileNames = new Vector(1); outFileNames = new Vector(1); inFileNames.add(afName); outFileNames.add(mfName); barTitle = title; } /**************************************************************************** *Constructor: *

Parameters: *
afNames --- the names of Agilent 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 AgilentMev(JFrame p, Vector afNames, Vector mfNames, String title, int annNum) { super(); parent = p; inFileNames = afNames; outFileNames = mfNames; barTitle = title; gAnnType = annNum; } /*************************************************************************** * 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 bgA = new String(""); // background info for channel A String bgB = new String(""); // background info for channel B String medA = new String("null"); String medB = new String("null"); String unid = new String(""); String spAreaA, spAreaB; String annoFileNamePath; String aligentFileName; String colValues[]; String colNames[]; String channels[] = {"g", "r"}; String dataStart[]; String annoFile[] = null; String mevFileHeader[]; StringBuffer mevLine = new StringBuffer(200); StringBuffer extraInfo = new StringBuffer(200); int numOfFiles; int hLines; // the index of header of data section int lastLine; // the index of last line of data int row, col, metaRow, metaCol, slideRow, slideCol, unidLoc; int i, j, k, flagInt, rowIndex, annAddr; int ch1IntenLoc, ch1Bkg, ch1AreaLoc, ch2IntenLoc, ch2Bkg, ch2AreaLoc; int ch1BkgArea, ch2BkgArea; int numSpot; Vector aligentFile; BufferedWriter mevWriter = null; BufferedWriter annoWriter = null; FileOutputStream mevFileOut = null; FileReading fileReader; taskEnd = determineTaskEnd(); if(taskEnd == 1){ return; } taskEnd <<= 1; counter = 0; numOfFiles = inFileNames.size(); for(i=0; iDescription: * calculate background for a channel with bg = median * area *

Parameters: *
tuple -- all information in one row *
backg -- address for background medien column *
area -- the address of GBNumPix. *

Return: the background information ***************************************************************************/ private String calculateBackground(String[] tuple, int backg, int area){ float fPix, bMedian, temp; String bg = new String(""); try{ fPix = Float.parseFloat(tuple[area]); bMedian = Float.parseFloat(tuple[backg]); temp = bMedian * fPix; bg += (int)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: * calculates median density for a channel *

Parameters: *
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. *

Return: the density ***************************************************************************/ private String getMedianIntensity(String[] tuple, int med, int backg, boolean bgSub){ float fMedian, bMedian; String den = new String(""); try{ fMedian = Float.parseFloat(tuple[med]); bMedian = Float.parseFloat(tuple[backg]); if(bgSub){ den += (int)(fMedian - bMedian); } else { den += (int)fMedian; } } 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: *
cNames -- the header of agilent 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. *

Return: the header as an array. **************************************************************************/ private String[] generateHeader(String[] cNames, String fName, int numRow, boolean mev){ int i; 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 + barTitle); tempHeader[4] = new String(PAN + SPACE + ROW_COUNT + COLON + numRow); tempHeader[5] = new String(PAN + " converted from Agilent 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 + 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 + SAA + TAB + SAB + TAB + MEDA + TAB + MEDB; } } else { tempHeader[6] = UID + TAB + R + TAB + C + TAB; for(i=gColIndex+1; i<(gPosX-1); i++){ tempHeader[6] += cNames[i] + TAB; } tempHeader[6] += cNames[i]; } return tempHeader; } /**************************************************************************** * Description: * calculates integrate density for a channel *

Parameters: *
tuple -- all information in one row *
med -- address for median column for either of the channels. *
backg -- address for background medien column *
areaIndx -- the address for spot area column. *
bgSub -- indicate if an intensity should subtract backgroud. *

Return: the density ***************************************************************************/ private String getIntegrateIntensity(String[] tuple, int med, int backg, int areaIndx, boolean bgSub){ float median, bMed, pix, temp; String den = new String(""); try{ median = Float.parseFloat(tuple[med]); bMed = Float.parseFloat(tuple[backg]); pix = Float.parseFloat(tuple[areaIndx]); if(bgSub){ temp = (median - bMed) * pix; } else { temp = median * pix; } 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: * retrieve a value from the ScanArray file base on the passed key. *

Parameter: *
fileCont --- whole content of file. *
key --- to match the wanted value. *

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; iDescription: * instantiates a writer object for ann file writing. *

Parameters: *
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. *

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; iDescription: * assignes values to the keys for searching right columns. *

Parameter: *
chs --- the names of channels, g = chA; r = chB. ***************************************************************************/ private void defineKeys(String[] chs) { gMedSignalA = new String(chs[0] + MED_SIGNAL); gMedSignalB = new String(chs[1] + MED_SIGNAL); gChApixel = new String(chs[0] + NUM_PIX); gChBpixel = new String(chs[1] + NUM_PIX); gBkgMedSignalA = new String(chs[0] + BG_MED_SIGNAL); gBkgMedSignalB = new String(chs[1] + BG_MED_SIGNAL); gBkgPixelA = new String(chs[0] + BG_NUM_PIX); gBkgPixelB = new String(chs[1] + BG_NUM_PIX); } /**************************************************************************** * Description: * find the address of the column that is interested. *

Parameters: *
str -- a line of the file *
key -- column name to be searched *

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; iDescription: * check if a parameter is a character. *

Parameter: *
x --- the input to be checked. *

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; } }