/* Copyright @ 2003, The Institute for Genomic Research (TIGR). All rights reserved. */ /*************************************************************************** * Author: Jianwei (Jerry) Li and Joe White * Name: TavConverter (Version 1.3) * Date: Created: 03/29/2002 and modified: 04/04/2003 * Descp: A Java class that reads a GenePix file and write it as a .tav file * 07/10/02: Modified calculateDensity() to make correct intensisty * 07/31/02: To meet the new version (4.0) of grp file, modified to automatically * pick up the required values for conversion. * 09/25/02: The wave-lengths in the header could be changed based on what kind * of filter is used for scanning. So the key for densities is not * stable and program should dynamically change the key. * 11/22/02: Because .tav file alway has Cy3-Cy5 order for 7-8 columns, modifed * the order of 532 and 635 to follow the way. Here we suppose 532 is * for Cy3 and 635 for Cy5. * 02/10/03: Added a contructor to accept mutiple files to process at one time. ***************************************************************************/ 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 TavConverter extends Converter { private String bgChA, bgChB, bgChAn, bgChBn, bgChAmean, bgChAnMean, bgChBnMean, bgChBmean; private String chA, chAn, chB, chBn, chAMean, chAnMean, chBMean, chBnMean; private String chAMedian, chBMedian, chAnMedian, chBnMedian; private String chAs, chAsn, chBs, chBsn; private String gpFileName; private int fPixAddr; private boolean keepAll; private boolean useMean; private boolean tavIntensity; // the output needs to calculation. 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"; /**************************************************************************** *Constructor: *

Parameters: *
gfName --- the name of GenePix file to be converted. *
tfName --- the name of .tav file that is an output. *****************************************************************************/ public TavConverter(String gfName, String tfName) { super(); inFileNames = new Vector(1); outFileNames = new Vector(1); inFileNames.add(gfName); outFileNames.add(tfName); msg = new String(""); ready = false; wantSort = true; keepAll = true; fetalError = false; minorError = false; useMean = true; tavIntensity = true; } /**************************************************************************** *Constructor: *

Parameters: *
gfNames --- the names of GenePix files to be converted. *
tfNames --- the names of .tav files that is an output. *****************************************************************************/ public TavConverter(Vector gfNames, Vector tfNames) { super(); inFileNames = gfNames; outFileNames = tfNames; msg = new String(""); ready = false; wantSort = true; keepAll = true; fetalError = false; minorError = false; useMean = true; tavIntensity = true; } public int getTaskEnd() { return taskEnd; } public int getCurrent() { return counter; } public String getErrorMsg() { return msg; } public String getFileName() { return gpFileName; } public void useMeanForIntensity(boolean b) { useMean = b; } /*************************************************************************** * 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 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 tavFileName; String colValues[]; String extraInfo = new String(""); String colNames[]; String waves[] = new String[2]; // first for channel A and second for B. int hLines; int max = 0; int maxRow = 0; int maxCol = 0; int maxMetaCol, block, row, col, metaRow, metaCol, slideRow, slideCol, spAreaA, spAreaB; int i, j, k, flagInt, flagIndex, blockIndex, colIndex, rowIndex; int f635m, b635m, f635s, f532m, f532s, b532m; int bgCh1Mean, bgCh2Mean, fCh1Mean, fCh2Mean, fCh1Median, fCh2Median; int numOfFiles; int fSize; BufferedWriter bufWriter = null; FileOutputStream fileOut = null; FileReading fileReader; Vector genepixFile; 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(" + gpFileName + "). \nPlease remove it and try again. Converting will continue " + "\nfor remaining files", "GenePix-Tav Converter", 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(" + gpFileName + ".\nThe converter requires an original GenePix file." + "\nConverting will continue for the remaining files", "GenePix-Tav Converter", 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); fCh1Mean = findRightCol(colNames, chAMean, chAnMean); fCh1Median = findRightCol(colNames, chAMedian, chAnMedian); b635m = findRightCol(colNames, bgChA, bgChAn); bgCh1Mean = findRightCol(colNames, bgChAmean, bgChAnMean); f532m = findRightCol(colNames, chB, chBn); f532s = findRightCol(colNames, chBs, chBsn); fCh2Mean = findRightCol(colNames, chBMean, chBnMean); fCh2Median = findRightCol(colNames, chBMedian, chBnMedian); b532m = findRightCol(colNames, bgChB, bgChBn); bgCh2Mean = findRightCol(colNames, bgChBmean, bgChBnMean); try{ fileOut = new FileOutputStream(tavFileName); bufWriter = new BufferedWriter(new OutputStreamWriter(fileOut)); sortKeys = new int[NUM_SORT][fSize - hLines]; outFile = new String[fSize - hLines]; counter += hLines; for(j = hLines, k=0; jDescription: * 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 intensity was set to null.\n"; } return bg; } /***************************************************************************** * Description: * 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 density for a channel *

Parameters: *
tuple -- all information in one row *
med -- address for either channel A or B median column *
area -- spot area in number of pixels *
backg -- address for background medien column *

Return: the density ***************************************************************************/ // private String calculateDensity(String[] tuple, int med, int area, int backg){ private String calculateDensity(String[] tuple, int med, int sat, int backg){ float fMedian, bMedian, fPix, bPix, fSat; int temp; String den = new String(""); try{ fMedian = Float.parseFloat(tuple[med]); bMedian = Float.parseFloat(tuple[backg]); //temp = (int)((fMedian - bMedian) * area); fPix = Float.parseFloat(tuple[fPixAddr]); fSat = Float.parseFloat(tuple[sat]); fSat = fSat / 100; temp = (int)(fPix * (fMedian - bMedian) * ( 1 - fSat)); //temp = (fPix * (fMedian - bMedian) * ( 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: * 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: * 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\""); chAMean = new String("\"F" + wvs[0] + " Mean - B" + wvs[0] + "\""); chBMean = new String("\"F" + wvs[1] + " Mean - B" + wvs[1] + "\""); chAMedian = new String("\"F" +wvs[0] + " Median - B" + wvs[0] + "\""); chBMedian = new String("\"F" + wvs[1] + " Median - B" + wvs[1] + "\""); 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\""); bgChAmean = new String("\"B" + wvs[0] + " Mean\""); bgChBmean = new String("\"B" + wvs[1] + " Mean\""); chAn = new String("F" + wvs[0] + " Median"); chBn = new String("F" + wvs[1] + " Median"); chAnMean = new String("F" + wvs[0] + " Mean - B" + wvs[0]); chBnMean = new String("F" + wvs[1] + " Mean - B" + wvs[1]); chAnMedian = new String("F" + wvs[0] + " Median - B" + wvs[0]); chBnMedian = new String("F" + wvs[1] + " Median - B" + wvs[1]); 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"); bgChAnMean = new String("B" + wvs[0] + " Mean"); bgChBnMean = new String("B" + wvs[1] + " Mean"); } /**************************************************************************** * 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 all other annotation information to a string for attaching *

Parameters: *
val --- all info of a spot *
fAddr --- the index for the flag *

RETRUNED: the annotation info ***************************************************************************/ private String setAnnotaionInfo(String[] val, int fAddr){ StringBuffer temp = new StringBuffer(); int i; for(i=3; iDESCRIPTION: * 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; } }