/*************************************************************************** * Author: Jianwei(Jerry) Li. * Name: ScanArrayMev (Version 1.0) * Date: Created: 04/07/2002 and modified: 04/07/2002 * Descp: A Java class that reads a ScanArray 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 ScanArrayMev extends MevConverter implements MevAttributes{ private JFrame parent; private boolean gSwap; private String bgChA, bgChB; private String chA, chB; private String chApixel, chBpixel; private String inFileNamePath; private String mevFileName; private String barTitle; private int areaPixel; // area in pixels private int quantWay; private int gAnnType; private final int TOTAL = 0; private final int MEAN = 1; private final int MODE = 2; private final int MEDIAN = 3; 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 NAME = "Name"; private final String RW = "Row"; private final String INTENSITY = "Intensity"; private final String BKG = "Background"; private final String AREA = "Area"; private final String TAB = "\t"; private final String PAN = "#"; /**************************************************************************** *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. *
title -- the string showed on the window bar. *****************************************************************************/ public ScanArrayMev(String sfName, String tfName, int way, String title) { super(); inFileNames = new Vector(1); outFileNames = new Vector(1); inFileNames.add(sfName); outFileNames.add(tfName); gSwap = false; quantWay = way; barTitle = title; } /**************************************************************************** *Constructor: *

Parameters: *
sfNames --- the names of ScanArray files to be converted. *
tfNames --- the names of mev files that is an output. *
way -- the protocol to generate the intensity in ScanArray file. *
title -- the string showed on the window bar. *
annNum --- the ann file type, one for one / many for one. *****************************************************************************/ public ScanArrayMev(JFrame p, Vector sfNames, Vector tfNames, int way, String title, int annNum) { super(); parent = p; inFileNames = sfNames; outFileNames = tfNames; quantWay = way; gSwap = false; barTitle = title; gAnnType = annNum; } public void needSwapChannels(boolean b) { gSwap = b; } /*************************************************************************** * 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 annoFileNamePath; String scanArrayFileName; String colValues[]; String extraInfo = new String(""); String colNames[]; String channels[] = {"ch1", "ch2"}; String dataStart[], dataEnd[]; String annoFile[] = null; String mevFileHeader[]; StringBuffer mevLine = new StringBuffer(200); 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, nameIndex; int ch1IntenLoc, ch1Bkg, ch1AreaLoc, ch2IntenLoc, ch2Bkg, ch2AreaLoc; int spAreaA, spAreaB; int numSpot; Vector scanArrayFile; 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; 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. 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); nameIndex = findRightCol(colNames, NAME); try{ annoFileNamePath = IOUtil.dropExtension(mevFileName); annoFileNamePath += ".ann"; mevFileOut = new FileOutputStream(mevFileName); mevWriter = new BufferedWriter(new OutputStreamWriter(mevFileOut)); sortKeys = new int[NUM_SORT][numSpot]; outFile = new String[numSpot]; scanArrayFileName = IOUtil.extractFileNameFromPath(inFileNamePath); // generate MEV file header mevFileHeader = generateHeader(scanArrayFileName, numSpot, true); 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; } /**************************************************************************** * Descriqption: * calculate integrate 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 calculateIntegrateIntensity(String[] tuple, int med, int backg, boolean bgSub){ float fMedian, bMedian, temp; 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: * calculate integrate 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 *
areaIndx -- the address for spot area column. *
bgSub -- indicate if an intensity should subtract backgroud. *

Return: the density ***************************************************************************/ private String calculateIntegrateIntensity(String[] tuple, int med, int backg, int areaIndx, boolean bgSub){ float fMedian, bMedian, fPix, temp; String den = new String(""); try{ fMedian = Float.parseFloat(tuple[med]); bMedian = Float.parseFloat(tuple[backg]); fPix = Float.parseFloat(tuple[areaIndx]); fPix = fPix / 100; if(bgSub){ temp = (fMedian - bMedian) * fPix; } else { temp = fMedian * fPix; } 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: * calculate 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 calculateMedianIntensity(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: * 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: * 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 + barTitle); tempHeader[4] = new String(PAN + SPACE + ROW_COUNT + COLON + numRow); tempHeader[5] = new String(PAN + " converted from ScanArray 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 + NAME; } return tempHeader; } /***************************************************************************** *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: *
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: *
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; } }