/*************************************************************************** * Author: Jianwei(Jerry) Li. * Name: ScanArrayTav (Version 1.0) * Date: Created: 04/04/2002 and modified: 04/04/2002 * Descp: A Java class that reads a ScanArray file and write it 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 ScanArrayTav extends Converter { private JFrame parent; private String bgChA, bgChB; private String chA, chB; private String chApixel, chBpixel; private String saFileName; private String tavFileName; private FileReading fileReader; private int numSpot; private int areaPixel; // area in pixels private int quantWay; private boolean keepAll, gSwap; private final int TOTAL = 1; private final int MEAN = 2; private final int MODE = 3; private final int MEDIAN = 4; private final String ARRAY_ROW = "Array Row"; private final String ARRAY_COL = "Array Column"; private final String BEGIN_DATA = "Begin Data"; private final String COLUMN = "Column"; private final String END_DATA = "End Data"; private final String RW = "Row"; private final String INTENSITY = "Intensity"; private final String BKG = "Background"; private final String AREA = "Area"; private final String NULL = "null"; /**************************************************************************** *Constructor: *

Parameters: *
sfName --- the name of ScanArray file to be converted. *
tfName --- the name of .tav file that is an output. *
way -- the protocol to generate the intensity in ScanArray file. *****************************************************************************/ public ScanArrayTav(String sfName, String tfName, int way) { inFileNames = new Vector(1); outFileNames = new Vector(1); inFileNames.add(sfName); outFileNames.add(tfName); ready = false; wantSort = true; keepAll = true; gSwap = false; fetalError = false; minorError = false; quantWay = way; } /**************************************************************************** *Constructor: *

Parameters: *
gfNames --- the names of GenePix files to be converted. *
tfNames --- the names of .tav files that is an output. *****************************************************************************/ public ScanArrayTav(JFrame p, Vector sfNames, Vector tfNames, int way) { parent = p; inFileNames = sfNames; outFileNames = tfNames; msg = new String(""); ready = false; wantSort = true; keepAll = true; gSwap = false; fetalError = false; minorError = false; quantWay = way; } public int getTaskEnd() { return taskEnd; } public String getFileName() { return saFileName; } public int getCurrent() { return counter; } public String getErrorMsg() { return msg; } /*************************************************************************** * 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 colValues[]; String extraInfo = new String(""); String colNames[]; String channels[] = {"ch1", "ch2"}; String dataStart[], dataEnd[]; int numOfFiles; int hLines; // the index of header of data section int lastLine; // the index of last line of data int max = 0; int maxRow = 0; int maxCol = 0; int maxArrayRow = 0; // meta row int maxArrayCol = 0; // meta column int row, col, metaRow, metaCol, slideRow, slideCol; int i, j, k, flagInt, arrayRowIndex, arrayColIndex, colIndex, rowIndex; int ch1IntenLoc, ch1Bkg, ch1AreaLoc, ch2IntenLoc, ch2Bkg, ch2AreaLoc; int spAreaA, spAreaB; int needLoc[] = new int[10]; Vector scanArrayFile; BufferedWriter bufWriter = null; FileOutputStream fileOut = null; FileReading fileReader; taskEnd = determineTaskEnd(); if(taskEnd == 1){ return; } taskEnd <<= 1; counter = 0; numOfFiles = inFileNames.size(); for(i=0; i 2){ maxArrayRow = Integer.parseInt(colValues[arrayRowIndex]); maxArrayCol = Integer.parseInt(colValues[arrayColIndex]); maxCol = Integer.parseInt(colValues[colIndex]); maxRow = Integer.parseInt(colValues[rowIndex]); max = maxArrayRow * maxArrayCol; } else { JOptionPane.showMessageDialog(parent, "You might add extra space at the end of file.\nPlease " + "remove it and try again.", parent.getTitle(), JOptionPane.ERROR_MESSAGE); noError = false; counter += numOfFiles; } if(noError){ // check if the original file has been modified. //System.out.println("numSpot: " + numSpot + " max: " + max + " maxCol: " + maxCol + " maxRow: " + maxRow); if((max * maxCol * maxRow) != numSpot){ JOptionPane.showMessageDialog(parent, "You might have dropped some of your spots.\nThe converter " + "requires an original ScanArray file.", parent.getTitle(), JOptionPane.ERROR_MESSAGE); noError = false; counter += numOfFiles; } if(noError){ ch1IntenLoc = findRightCol(colNames, chA); ch1Bkg = findRightCol(colNames, bgChA); ch2IntenLoc = findRightCol(colNames, chB); ch2Bkg = findRightCol(colNames, bgChB); needLoc[0] = ch1IntenLoc; needLoc[1] = ch1Bkg; needLoc[2] = ch1AreaLoc; needLoc[3] = ch2IntenLoc; needLoc[4] = ch2Bkg; needLoc[5] = ch2AreaLoc; needLoc[6] = arrayRowIndex; needLoc[7] = arrayColIndex; needLoc[8] = rowIndex; needLoc[9] = colIndex; try{ fileOut = new FileOutputStream(tavFileName); bufWriter = new BufferedWriter(new OutputStreamWriter(fileOut)); sortKeys = new int[NUM_SORT][numSpot]; outFile = new String[numSpot]; counter += hLines; for(j = hLines + 1, k=0; j<=lastLine; j++, k++){ aLine = (String)scanArrayFile.elementAt(j); colValues = separateLine(aLine); metaRow = Integer.parseInt(colValues[arrayRowIndex]); metaCol = Integer.parseInt(colValues[arrayColIndex]); col = Integer.parseInt(colValues[colIndex]); row = Integer.parseInt(colValues[rowIndex]); // channel A is always for Cy3 and B for Cy5 in .tav file if(gSwap){ spAreaA = calculateSpotArea(colValues, ch2AreaLoc); spAreaB = calculateSpotArea(colValues, ch1AreaLoc); bgA = calculateBackground(colValues, ch2Bkg); bgB = calculateBackground(colValues, ch1Bkg); if(quantWay != 1){ densA = calculateDensity(colValues, ch2IntenLoc, ch2Bkg, ch2AreaLoc); densB = calculateDensity(colValues, ch1IntenLoc, ch1Bkg, ch1AreaLoc); } else { densA = "" + (int)(Float.parseFloat(colValues[ch2IntenLoc])); densB = "" + (int)Float.parseFloat(colValues[ch1IntenLoc]); } } else { spAreaA = calculateSpotArea(colValues, ch1AreaLoc); spAreaB = calculateSpotArea(colValues, ch2AreaLoc); bgA = calculateBackground(colValues, ch1Bkg); bgB = calculateBackground(colValues, ch2Bkg); if(quantWay != 1){ densA = calculateDensity(colValues, ch1IntenLoc, ch1Bkg, ch1AreaLoc); densB = calculateDensity(colValues, ch2IntenLoc, ch2Bkg, ch2AreaLoc); } else { densA = "" + (int)(Float.parseFloat(colValues[ch1IntenLoc])); densB = "" + (int)Float.parseFloat(colValues[ch2IntenLoc]); } } flagA = NULL; flagB = NULL; 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){ extraInfo = setAnnotaionInfo(colValues, needLoc); tavLine += extraInfo.toString(); } outFile[k] = new String(tavLine); sortKeys[0][k] = k; sortKeys[1][k] = slideRow; sortKeys[2][k] = slideCol; counter++; } if(wantSort){ sorted = sortRowCol(maxArrayCol, maxCol); // write to file for(j = 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[areaPixel]); 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 to calculate background;\n"; msg += "and the background was set to null.\n"; } return bg; } /**************************************************************************** * Description: * calculate 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 *

Return: the density ***************************************************************************/ private String calculateDensity(String[] tuple, int med, int backg, int areaIndx){ float fMedian, bMedian, fPix, fSat; int temp; //float temp; String den = new String(""); try{ fMedian = Float.parseFloat(tuple[med]); bMedian = Float.parseFloat(tuple[backg]); fPix = Float.parseFloat(tuple[areaIndx]); fPix = fPix / 100; temp = (int)((fMedian - bMedian) * fPix); 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 spot area in the number of pixels. *

Parameters: *
tuple -- all information in one row *
areaIndx -- address for spot area. *

Return: the area. ***************************************************************************/ private int calculateSpotArea(String[] tuple, int areaIndx){ float area; int temp; area = Float.parseFloat(tuple[areaIndx]); area = area / 100; temp = (int) area; return temp; } /***************************************************************************** *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: * assignes values to the keys for searching right columns. *

Parameter: *
chs --- the names of channels. ***************************************************************************/ private void defineKeys(String[] chs) { chA = new String(chs[0] + " " + INTENSITY); chB = new String(chs[1] + " " + INTENSITY); chApixel = new String(chs[0] + " " + AREA); chBpixel = new String(chs[1] + " " + AREA); bgChA = new String(chs[0] + " " + BKG); bgChB = new String(chs[1] + " " + BKG); } /**************************************************************************** * 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; } /***************************************************************************** *DESCRIPTION: * set all other annotation information to a string for attaching *

Parameters: *
val --- all info of a spot *

RETRUNED: the annotation info ***************************************************************************/ private String setAnnotaionInfo(String[] val, int[] noNeed){ StringBuffer temp = new StringBuffer(); int i, j; boolean want = true; for(i=0; i