/*************************************************************************** * Author: Jianwei (Jerry) Li * Name: ImaGeneTav (Version 1.0) * Date: Created: 03/28/2003 and modified: 03/28/2003 * Descp: A Java class that reads a pair of ImaGene output files and write them * 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 ImaGeneTav extends Converter implements ImaGeneAttributes{ private JFrame parent; private String ch1FileName, ch2FileName; private Vector ig2FileNames, tavFileNames; private StringSplitter spliter; private boolean keepAll; private final int NUM_SORT = 3; // array size for sorting key private final int ROW = 1; private final int COL = 2; /**************************************************************************** *Constructor: *

Parameters: *
gfName --- the name of GenePix file to be converted. *
tfName --- the name of .tav file that is an output. *****************************************************************************/ public ImaGeneTav(String gfName, String tfName) { super(); tavFileNames = new Vector(1); inFileNames.add(gfName); tavFileNames.add(tfName); keepAll = true; } /**************************************************************************** *Constructor: *

Parameters: *
ig1Names --- the names of GenePix files to be converted. *
tfNames --- the names of .tav files that is an output. *****************************************************************************/ public ImaGeneTav(JFrame frame, Vector ig1Names, Vector ig2Names, Vector tfNames) { super(); parent = frame; inFileNames = ig1Names; ig2FileNames = ig2Names; tavFileNames = tfNames; keepAll = true; } public void attachGeneId(boolean b){ keepAll = b; } public String getFileNameForChannel1() { return ch1FileName; } /*************************************************************************** * 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 spAreaA = new String(""); String spAreaB = new String(""); String tavFileName; String f1ColValues[], f2ColValues[]; String geneId = new String(""); String f1ColNames[], f2ColNames[]; int ch1HeaderLines, ch2HeaderLines; // the number of header lines for the data input file. int ch1DataEnd, ch2DataEnd; int f1SignalArea, f2SignalArea; int maxRow = 0; int maxCol = 0; int row, col, metaRow, metaCol, slideRow, slideCol; int i, j, k, f1FlagIndex, f2FlagIndex, geneIndex; int mRowIndex, mColIndex; // meta row and column indices; int colIndex, rowIndex; int f1SignalMedian, f2SignalMedian; int f1SignalTotal, f2SignalTotal; int f1BgMedian, f2BgMedian; int f1BgTotal, f2BgTotal, f1BgArea, f2BgArea; int numOfFiles, numSpots; int[] ch1NumSpotsAndMaxMetaCol, ch2NumSpotsAndMaxMetaCol; // numbers of spots and the maximum meta columns for each data file. BufferedWriter bufWriter = null; FileOutputStream fileOut = null; Vector ch1File, ch2File; taskEnd = determineTaskEnd(); if(taskEnd == 1){ return; } taskEnd <<= 1; counter = 0; numOfFiles = inFileNames.size(); for(i=0; i 1 && f2SignalMedian > 1){ // converting based on signal median for(j = ch1HeaderLines+2, k=0; j < numSpots; j++, k++){ aLine = (String)ch1File.elementAt(j); f1ColValues = separateLine(aLine); aLine = (String)ch2File.elementAt(j); f2ColValues = separateLine(aLine); metaRow = Integer.parseInt(f1ColValues[mRowIndex]); metaCol = Integer.parseInt(f1ColValues[mColIndex]); col = Integer.parseInt(f1ColValues[colIndex]); row = Integer.parseInt(f1ColValues[rowIndex]); densA = calculateDensity(f1ColValues, f1SignalMedian, f1BgMedian, f1SignalArea); densB = calculateDensity(f2ColValues, f2SignalMedian, f2BgMedian, f2SignalArea); spAreaA = f1ColValues[f1SignalArea]; spAreaB = f2ColValues[f2SignalArea]; bgA = calculateBackground(f1ColValues, f1BgMedian, f1SignalArea); bgB = calculateBackground(f2ColValues, f2BgMedian, f2SignalArea); flagA = setFlag(f1ColValues, f1FlagIndex); flagB = setFlag(f2ColValues, f2FlagIndex); maxRow = ch1NumSpotsAndMaxMetaCol[2]; maxCol = ch1NumSpotsAndMaxMetaCol[3]; slideRow = (metaRow - 1) * maxRow + row; slideCol = (metaCol -1 ) * maxCol + col; tavLine = slideRow +"\t"+ slideCol +"\t"+ metaRow +"\t"+ metaCol +"\t"+ row +"\t"+ col +"\t"+ densA +"\t"+ densB + "\t" + spAreaA + "\t" + spAreaB + "\tnull\tnull\tnull\t" + bgA + "\t" + bgB + "\t" + flagA + "\t" + flagB; if(keepAll){ geneId = f1ColValues[geneIndex]; tavLine += "\t" + geneId; } outFile[k] = new String(tavLine); sortKeys[0][k] = k; sortKeys[1][k] = slideRow; sortKeys[2][k] = slideCol; counter++; } // end of the for loop for a single file. } else { // converting based on signal total for(j = ch1HeaderLines+2, 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 *
area -- address of Spot Area column. *

Return: the background information ***************************************************************************/ private String calculateBackground(String[] tuple, int backg, int area){ float fPix, bMedian; int temp; String bg = new String(""); try{ fPix = Float.parseFloat(tuple[area]); bMedian = Float.parseFloat(tuple[backg]); temp = (int)(bMedian * fPix); bg += temp; } catch (NumberFormatException nfex) { minorError = true; bg = "null"; msg += "**********\n"; msg += "There is an unacceptable value for either Signal Area or Backgroud Median; and the background was set to null.\n"; } return bg; } /**************************************************************************** * Description: * calculate density for a channel with signal median method *

Parameters: *
tuple -- all information in one row *
med -- address of Siganl Median for either of files *
backg -- address of Background Medien column. *
sArea -- address of Signal Area column. *

Return: the density ***************************************************************************/ private String calculateDensity(String[] tuple, int med, int backg, int sArea){ float signal, bg, area; int temp; String den = new String(""); try { signal = Float.parseFloat(tuple[med]); bg = Float.parseFloat(tuple[backg]); area = Float.parseFloat(tuple[sArea]); temp = (int)((signal - bg) * area); den += temp; } catch (NumberFormatException nfex) { minorError = true; den = "null"; msg += "**********\n"; msg += "There is an unacceptable value for either Signal or Backgroud Median; and the intensity was set to null.\n"; } return den; } /**************************************************************************** * Description: * calculate density for a channel with signal total method *

Parameters: *
tuple -- all information in one row *
sigTot -- address of Siganl Total for either of files *
bgTot -- address of Background Total column. *
bgArea -- address of Background Area column. *
sArea -- address of Signal Area column. *

Return: the density ***************************************************************************/ private String calculateDensity(String[] tuple, int sigTot, int bgTot, int bgArea, int sArea){ float st, bt, ba, area; String den = new String(""); int temp; st = Float.parseFloat(tuple[sigTot]); bt = Float.parseFloat(tuple[bgTot]); ba = Float.parseFloat(tuple[bgArea]); area = Float.parseFloat(tuple[sArea]); temp = (int)(st - (bt/ba) * area); den += temp; return den; } /**************************************************************************** * Description: * determine the end line of row data *

Parameters: *
dataFile -- the data file as vector *

Return: the index of the end. ****************************************************************************/ private int getDataEndLine(Vector dataFile){ int end, i, j; end = 0; String line, temp, elements[]; for(i=dataFile.size()-1; i>0; i--){ line = (String)dataFile.elementAt(i); elements = separateLine(line); end = i; for(j=0; jDescription: * determine the number of header lines *

Parameters: *
dataFile -- the data file as vector *

Return: the number of header lines. ****************************************************************************/ private int getHeaderLines(Vector dataFile){ int numLine, i, j; String line, temp, elements[]; numLine = 0; for(i=0; iDescription: * 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; } /**************************************************************************** *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: * checks if the input file is original without any modification. *

Parameter: *
dataFile -- the input file. *
dataStart -- the starting line of data *

Return: the number of spots (rows) * ************************************************************************/ private int[] noSpotDropped(String fName, Vector dataFile, int dataStart, int mRow, int mCol, int row, int col){ int num[] = new int[5]; int dataEnd, heading; int maxMetaRow, maxMetaCol, maxCol, maxRow; String tempLine, vecVal[]; heading = dataStart; dataEnd = getDataEndLine(dataFile); tempLine = (String)dataFile.elementAt(dataEnd); vecVal = separateLine(tempLine); maxMetaRow = Integer.parseInt(vecVal[mRow]); maxMetaCol = Integer.parseInt(vecVal[mCol]); maxRow = Integer.parseInt(vecVal[row]); maxCol = Integer.parseInt(vecVal[col]); num[0] = maxMetaRow * maxMetaCol * maxRow * maxCol; num[1] = maxMetaCol; num[2] = maxRow; num[3] = maxCol; num[4] = dataEnd; if(num[0] != (dataEnd - heading - 1)){ JOptionPane.showMessageDialog(null, "You might have dropped some of your spots in the file \n(" + fName + ".\nThe converter requires an original ImaGene output file." + "\nConverting will continue for the remaining files", parent.getTitle(), JOptionPane.ERROR_MESSAGE); num[0] = -1; } return num; } /**************************************************************************** * Description: * reads an input file and return the contents as a vector. ***************************************************************************/ private Vector readInput(String inName){ Vector tempVec = new Vector(); FileReading fileReader; try{ fileReader = new FileReading(inName); if(fileReader.done){ tempVec = fileReader.getFileContentInLines(); } else { fetalError = true; msg += "**********\n"; msg += fileReader.getProcessMessage() + "\n"; taskEnd = 1; counter = 1; } } catch (IOException ie){ } return tempVec; } /***************************************************************************** *DESCRIPTION: * set flag based on the flag values in the original file *

Parameters: *
tuple --- the information of one spot *
indx --- the address of orginal flag *

Return: the flag. ***************************************************************************/ private String setFlag(String[] tuple, int indx){ String f = new String(""); int flagInt; flagInt = Integer.parseInt(tuple[indx]); if(flagInt != 0){ f = "X"; } else { f = "B"; } return f; } }