/* Copyright @ 2003, The Institute for Genomic Research (TIGR). All rights reserved. */ /***************************************************************************** * Description: A class that reads a set of ArrayVision files and write to * MEV files. * Company: TIGR * @author Jianwei (Jerry) Li * @version 1.0 * @Date: Created: 06/07/2004 and modified: 08/12/2004 * Modified History *****************************************************************************/ package org.tigr.microarray.converter; import java.io.IOException; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.util.Vector; import javax.swing.JOptionPane; import org.tigr.microarray.MevAttributes; import org.tigr.util.FileReading; import org.tigr.util.MyTimer; import org.tigr.util.io.IOUtil; public class ArrayVersionMev extends MevConverter implements MevAttributes{ final String AREA = "Area - mm2"; final String BKGD = "Bkgd"; final String DATA_1 = "Data 1"; final String DATA_2 = "Data 2"; final String FLAG = "Flag"; final String SPOT_LABEL = "Spot labels"; final String VOL = "VOL - Levels x mm2"; final String AR_VOL = "AR VOL - Levels x mm2"; final int M_VOL = 0; final int M_AR_VOL = 1; final int M_DENS = 2; final int M_MTM_DENS = 3; final int M_ARM_DNES = 4; final int M_MED_DENS = 5; int gMeasureType; String title; String gChannelNames[]; /**************************************************************************** * Constructor: *

Parameters: *
inNames --- the names of ArrayVersion files to be converted. *
mfNames --- the names of .mev files that is an output. *
barTitle --- the string showed on the window bar. *****************************************************************************/ public ArrayVersionMev(Vector inNames, Vector mfNames, String barTitle) { super(); inFileNames = inNames; outFileNames = mfNames; title = barTitle; } /*************************************************************************** * Description: * overrides an abstract method to implement the main function of class. **************************************************************************/ public void run () { boolean noSpotArea = false; String mevFileName; String aLine = new String(""); String bgA = new String(""); // background info for channel A String bgB = new String(""); // background info for channel B String densA = new String(""); String densB = new String(""); String flagA = new String(""); String flagB = new String(""); String medA = new String("0"); String medB = new String("0"); String avFileName; String colNames[], colValues[]; String mevFileHeader[], annoFileHeader[]; String avFile[]; StringBuffer mevLine = new StringBuffer(150); int numOfFiles, fSize, hLine, flag; int i, j, k; int flag1Index, flag2Index, inten1Addr, inten2Addr, sa1Addr, sa2Addr; int bg1Addr, bg2Addr, labelIndex; int spAreaA = 0; int spAreaB = 0; FileReading fileReader; BufferedWriter mevWriter = null; FileOutputStream mevFileOut = null; taskEnd = determineTaskEnd(); if(taskEnd == 1){ return; } counter = 0; numOfFiles = inFileNames.size(); for(i=0; iDescription: * calculate background for a channel with bg = median * area *

Parameters: *
tuple -- all information in one row *
backg -- address for background medien colum. *

Return: the background information ***************************************************************************/ private String calculateBackground(String[] tuple, int backg){ float bkg; String bg = new String(""); try{ bkg = Float.parseFloat(tuple[backg]); bg += (int)bkg; } catch (NumberFormatException nfex) { minorError = true; bg = "null"; msg += "**********\n"; msg += "There is an unacceptable value for " + BKGD + ";\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 *
volIndx -- address for either channel A or B density column *
bkgIndx -- address for background volum. *
bgSub -- indicate if an intensity should subtract backgroud. *

Return: the density ***************************************************************************/ private String calculateIntegrateDensity(String[] tuple, int volIndx, int bkgIndx, boolean bgSub){ float vol, bg, temp; String den = new String(""); try{ vol = Float.parseFloat(tuple[volIndx]); bg = Float.parseFloat(tuple[bkgIndx]); if(bgSub){ temp = vol - bg; } else { temp = vol; } 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 intensity for a channel *

Parameters: *
tuple -- all information in one row *
volIndx -- address for either channel A or B density column *
bkgIndx -- address for background volum. *
areaIndx -- address for spot area (mm2). *
bgSub -- indicate if an intensity should subtract backgroud. *

Return: the density ***************************************************************************/ private String calculateMedianIntensity(String[] tuple, int volIndx, int bkgIndx, int areaIndx, boolean bgSub){ float vol, bg, area, temp; String den = new String(""); try{ vol = Float.parseFloat(tuple[volIndx]); bg = Float.parseFloat(tuple[bkgIndx]); area = Float.parseFloat(tuple[areaIndx]) * 10000; if(bgSub){ temp = (vol - bg) / area; } else { temp = vol/area; } 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: * calculates the spot area in terms of pixel number. *

Parameters: *
tuple -- all information in one row. *
indx -- address for Area. *

Return: the spot area. ***************************************************************************/ private int calculateSpotArea(String[] tuple, int indx){ float fPix = Float.parseFloat(tuple[indx]); int temp = (int)(fPix * 10000); return temp; } /**************************************************************************** * Description: * checks what the principal measure the data file used. *

Parameters: *
hd -- the header names. *

Return: the address of the density column; otherwise -1; ***************************************************************************/ private int determineMeasureType(String[] hd, String channel){ int addr = -1; addr = findRightCol(hd, VOL, channel); if(addr != 0){ gMeasureType = M_VOL; } else { addr = findRightCol(hd, AR_VOL, channel); if(addr != 0){ gMeasureType = M_AR_VOL; } else { addr = -1; } } return addr; } /**************************************************************************** * Description: * find the address of the column that is interested. *

Parameters: *
str -- a line of the file *
key -- column name to be searched *
start -- the starting column to be checked. *

Return: the index of the column ****************************************************************************/ private int findRightCol(String str[], String key, int start){ int addr = 0; for(int i=start; iDescription: * find the address of the column that is interested. *

Parameters: *
str -- a line of the file *
key -- column name to be searched *
chName -- channel name. *

Return: the index of the column ****************************************************************************/ private int findRightCol(String str[], String key, String chName){ int addr = findRightCol(str, key, 0); String temp = gChannelNames[addr]; if(temp.equalsIgnoreCase(chName)){ return addr; } else { addr = findRightCol(str, key, addr + 1); } return addr; } /**************************************************************************** * Description: * creates a header for both mev and dat(annotation) file. *

Parameter: *
fName -- the ArrayVersion file name that should be converted. *
numRow -- the number of spots (genes/row). *

Return: the header as an array. **************************************************************************/ private String[] generateHeader(String fName, int numRow, boolean noSA){ String[] tempHeader = new String[8]; String bkgVal; 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.getCurrentDate('.')); 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 ArrayVersion file: " + fName); tempHeader[6] = new String(PAN + SPACE + BKG_CORRECT + COLON + bkgVal); if(noSA){ if(gUseMedian){ tempHeader[7] = UID + TAB + MEDA + TAB + MEDB + TAB + BKGA + TAB + BKGB + TAB + FLAGA + TAB + FLAGB + TAB + IA + TAB + IB; } else { tempHeader[7] = UID + TAB + IA + TAB + IB + TAB + BKGA + TAB + BKGB + TAB + FLAGA + TAB + FLAGB + TAB + MEDA + TAB + MEDB; } } else { if(gUseMedian){ tempHeader[7] = UID + TAB + MEDA + TAB + MEDB + 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 + BKGA + TAB + BKGB + TAB + FLAGA + TAB + FLAGB + TAB + SAA + TAB + SAB + TAB + MEDA + TAB + MEDB; } } return tempHeader; } /************************************************************************** * Description: * asignes value to flag. * Parameters: *
f -- the flag the value to be assigned. *
val -- the value from the original file. *

Return: the value. **************************************************************************/ private String getFlagValue(String f, int val){ if(val == 0){ f = "B"; } else { f = "X"; } return f; } }