/* 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: *
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 2){ max = Integer.parseInt(colValues[blockIndex]); maxCol = Integer.parseInt(colValues[colIndex]); maxRow = Integer.parseInt(colValues[rowIndex]); } else { JOptionPane.showMessageDialog(null, "You might add extra space at the end of file.\n(" + inFileNamePath + "). \nPlease remove it and try again. Converting will continue " + "\nfor remaining files", title + " -- Gpr-Mev", JOptionPane.ERROR_MESSAGE); noError = false; counter += numOfFiles; } if(noError){ if(max <= 12){ maxMetaCol = 2; } else { maxMetaCol = 4; } // check if the original file has been modified. noError = true; if((max * maxCol * maxRow) + hLines != genepixFile.size()){ JOptionPane.showMessageDialog(null, "You might have dropped some of your spots in the file \n(" + inFileNamePath + ".\nThe converter requires an original GenePix file." + "\nConverting will continue for the remaining files", title + " -- Gpr-Mev", JOptionPane.ERROR_MESSAGE); noError = false; counter += numOfFiles; } if(noError){ flagIndex = findRightCol(colNames, FLAG, FLAG_N); fPixAddr = findRightCol(colNames, F_PIX, F_PIX_N); f635m = findRightCol(colNames, chA, chAn); f635s = findRightCol(colNames, chAs, chAsn); b635m = findRightCol(colNames, bgChA, bgChAn); f532m = findRightCol(colNames, chB, chBn); f532s = findRightCol(colNames, chBs, chBsn); b532m = findRightCol(colNames, bgChB, bgChBn); idIndex = findRightCol(colNames, ID, ID_N); nameIndex = findRightCol(colNames, NAME, NAME_N); try{ annoFileNamePath = IOUtil.dropExtension(mevFileName); annoFileNamePath += ".ann"; mevFileOut = new FileOutputStream(mevFileName); mevWriter = new BufferedWriter(new OutputStreamWriter(mevFileOut)); sortKeys = new int[NUM_SORT][fSize - hLines]; outFile = new String[fSize - hLines]; gprFileName = IOUtil.extractFileNameFromPath(inFileNamePath); // generate MEV file header mevFileHeader = generateHeader(gprFileName, fSize-hLines, true); for(j=0; jDescription: * calculates the spot area in terms of pixel number. *

Parameters: *
tuple -- all information in one row. *
sat -- address for saturated pixels column. *

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: *
tuple -- all information in one row *
backg -- address for background medien column *

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

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: *
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 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: *
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 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: *
str -- a line of the file that contains wave lengths. *

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

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

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

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; 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; } /**************************************************************************** *Description: * check if a input string is a number. *

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

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; iDescription: * check if a string contains wave length information. *

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

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: *
tuple --- the information of one spot *
sat --- the address of satureated pixels *
indx --- the address of orginal flag *

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