/* Copyright @ 2003, The Institute for Genomic Research (TIGR). All rights reserved. */ /***************************************************************************** * Description: A class that reads a set of ImaGene (txt) files and write to * MEV files. * Company: TIGR * @author Jianwei (Jerry) Li * @version 1.0 * @Date: Created: 04/04/2003 and modified: 06/29/2004 *****************************************************************************/ 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 ImaGeneMev extends MevConverter implements ImaGeneAttributes, MevAttributes{ private JFrame parent; private String ch1FileName, ch2FileName; private String title; // the massege showed on the bars of all windows. private Vector ig2FileNames; private int fPixAddr, gAnnType; private final String TAB = "\t"; private final String PAN = "#"; /**************************************************************************** *Constructor: *
Parameters:
*
gfName --- the name of GenePix file to be converted.
*
mfName --- the name of .mev file that is an output.
*****************************************************************************/
public ImaGeneMev(String gfName, String mfName) {
inFileNames = new Vector(1);
outFileNames = new Vector(1);
inFileNames.add(gfName);
outFileNames.add(mfName);
title = new String("Genepix vs Mev");
msg = new String("");
ready = false;
wantSort = true;
fetalError = false;
minorError = false;
}
/****************************************************************************
*Constructor:
*
Parameters:
* Parameters:
* 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 integrate intensity for a channel with signal median method
* Parameters:
* Return: the intensity
***************************************************************************/
private String calculateIntegrateIntensity(String[] tuple, int med, int backg,
int sArea, boolean bgSub){
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]);
if(bgSub){
temp = (int)((signal - bg) * area);
} else {
temp = (int)(signal * area);
}
den += temp;
} catch (NumberFormatException nfex) {
minorError = true;
den = "null";
msg += "**********\n";
msg += "There is a null value for either Signal Median or Background Median ";
msg += "and the intensity was set to null.\n";
}
return den;
}
/****************************************************************************
* Description:
* calculate integrate intensity for a channel with signal total method
* Parameters:
* Return: the density
***************************************************************************/
private String calculateIntegrateIntensity(String[] tuple, int sigTot, int bgTot,
int bgArea, int sArea, boolean bgSub){
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]);
if(bgSub){
temp = (int)(st - (bt/ba) * area);
} else {
temp = (int)(st);
}
den += temp;
return den;
}
/****************************************************************************
* Description:
* calculate median intensity for a channel
* Parameters:
* Return: the density
***************************************************************************/
private String calculateMedianIntensity(String[] tuple, int med, int backg,
boolean bgSub){
float fMedian, bMedian;
float temp;
String den = new String("");
try{
fMedian = Float.parseFloat(tuple[med]);
bMedian = Float.parseFloat(tuple[backg]);
if(bgSub){
temp = fMedian - bMedian;
} else {
temp = fMedian;
}
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 with signal total method
* Parameters:
* Return: the density
***************************************************************************/
private String calculateMedianIntensity(String[] tuple, int sigTot, int bgTot,
int bgArea, int sArea, boolean bgSub){
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]);
if(bgSub){
temp = (int)(st/area - bt/ba);
} else {
temp = (int)(st/area);
}
den += temp;
return den;
}
/****************************************************************************
* Description:
* creates a header for both mev and dat(annotation) file.
* Parameter:
* Return: the header as an array.
**************************************************************************/
private String[] generateHeader(String fName, int numRow){
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.getCurrentDateAndTime('.'));
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 ImaGene files: " + fName);
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 +
FLAGA + TAB + FLAGB + 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 +
FLAGA + TAB + FLAGB + TAB + SAA + TAB + SAB + TAB + MEDA + TAB + MEDB;
}
return tempHeader;
}
/****************************************************************************
* Description:
* determine the end line of row data
* Parameters:
* Return: the index of the end.
****************************************************************************/
private int getDataEndLine(String[] dataFile){
int end, i, j;
end = 0;
String line, temp, elements[];
for(i=dataFile.length-1; i>0; i--){
line = (String)dataFile[i];
elements = separateLine(line);
end = i;
for(j=0; j Parameters:
* Return: the number of header lines.
****************************************************************************/
private int getHeaderLines(String[] dataFile){
int numLine, i, j;
String line, temp, elements[];
numLine = 0;
for(i=0; i Parameters:
* 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);
annoFileHeader[5] = UID + TAB + R + TAB + C;
for(int i=0; i Parameters:
* 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; i Parameter:
* Return: the number of spots (rows)
* ************************************************************************/
private int[] noSpotDropped(String fName, String[] 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[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:
* check if a parameter is a character.
* Parameter:
* 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 flag based on the flag values in the original file
* Parameters:
* 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;
}
}
frame -- the parent that uses this class.
*
ig1Names --- the names of ImaGene files for channel 1.
*
ig2Names --- the names of ImaGene files for channel 2.
*
mfNames --- the names of .mev files that are output.
*
barTitle --- the string showed on the bar.
*
annNum --- the ann file type, one for one / many for one.
*****************************************************************************/
public ImaGeneMev(JFrame frame, Vector ig1Names, Vector ig2Names, Vector mfNames,
String barTitle, int annNum) {
parent = frame;
inFileNames = ig1Names;
ig2FileNames = ig2Names;
outFileNames = mfNames;
msg = new String("");
title = barTitle;
gAnnType = annNum;
ready = false;
wantSort = true;
fetalError = false;
minorError = false;
}
public int getTaskEnd() { return taskEnd; }
public int getCurrent() { return counter; }
public String getErrorMsg() { return msg; }
public String getFileName() { return ch1FileName; }
/***************************************************************************
* 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 flagA = new String("");
String flagB = new String("");
String ident = new String("");
String spAreaA = new String("");
String spAreaB = new String("");
String bgA = new String(""); // background info for channel A
String bgB = new String(""); // background info for channel B
String medA = new String("");
String medB = new String("");
String mevFileName;
//String annoFileNamePath;
String inputFileName;
//String extraInfo = new String("");
String mevFileHeader[];
//String annoFileHeader[];
//String annoFile[] = null;
String f1ColNames[], f2ColNames[];
String f1ColValues[], f2ColValues[];
StringBuffer mevLine = new StringBuffer(200);
int ch1HeaderLines, ch2HeaderLines; // the number of header lines for the data input file.
int mRowIndex, mColIndex; // meta row and column indices;
int f1SignalArea, f2SignalArea;
int f1SignalMedian, f2SignalMedian;
int f1BgMedian, f2BgMedian;
int f1SignalTotal, f2SignalTotal;
int f1BgTotal, f2BgTotal, f1BgArea, f2BgArea;
int[] ch1NumSpotsAndMaxMetaCol, ch2NumSpotsAndMaxMetaCol;
int maxRow = 0;
int maxCol = 0;
int maxMetaCol, row, col, metaRow, metaCol, slideRow, slideCol;
int i, j, k, f1FlagIndex, f2FlagIndex, flagInt, colIndex, rowIndex, geneIndex;
int f532m;
int numOfFiles, numSpots;
BufferedWriter mevWriter = null;
// BufferedWriter annoWriter = null;
FileOutputStream mevFileOut = null;
//FileOutputStream annoFileOut = null;
String[] ch1File, ch2File;
taskEnd = determineTaskEnd();
if(taskEnd == 1){
return;
}
taskEnd <<= 1;
counter = 0;
numOfFiles = inFileNames.size();
for(i=0; i
tuple -- all information in one row
*
backg -- address for background medien column
*
area -- address of Spot Area column.
*
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.
*
bgSub -- indicate if an intensity should subtract backgroud.
*
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.
*
bgSub -- indicate if an intensity should subtract backgroud.
*
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.
*
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.
*
bgSub -- indicate if an intensity should subtract backgroud.
*
fName -- the mev file name that should be written to the file.
*
numRow -- the number of spots (genes/row).
*
dataFile -- the data file as vector
*
dataFile -- the data file as a String array
*
fName --- ann file name to be written.
*
inName --- the input file name.
*
numSpots --- the number of rows in the input file.
*
str -- a line of the file
*
key -- column name to be searched
*
dataFile -- the input file.
*
dataStart -- the starting line of data
*
x --- the input to be checked.
*
tuple --- the information of one spot
*
indx --- the address of orginal flag
*