/* Copyright @ 2003, The Institute for Genomic Research (TIGR). All rights reserved. */ /***************************************************************************** * Description: a base class for convert one file format to the other. * Company: TIGR * @author Jianwei (Jerry) Li * @version 1.0 * @Date: Created: 05/12/2003 and modified: 05/12/2003 *****************************************************************************/ package org.tigr.microarray.converter; import java.io.IOException; import java.util.Vector; import org.tigr.util.StringSplitter; import org.tigr.util.io.MyIni; import org.tigr.util.FileReading; public class Converter extends Thread { public static boolean ready; public static boolean fetalError; public static boolean minorError; protected final int NUM_SORT = 3; // array size for sorting key protected final int ROW = 1; protected final int COL = 2; protected Vector inFileNames, outFileNames; protected String msg, inFileNamePath; protected String[] outFile; protected boolean wantSort; protected int taskEnd; protected int counter; protected int[][] sortKeys; protected int[] sorted; protected int[][] oneGroup; public Converter() { msg = new String(""); inFileNamePath = new String(""); wantSort = true; ready = false; fetalError = false; minorError = false; } public int getCurrent() { return counter; } public String getErrorMsg() { return msg; } public String getFileName() { return inFileNamePath; } public int getTaskEnd() { return taskEnd; } public void setSortSpots(boolean b){ wantSort = b; } /*************************************************************************** *Description: * set the index in order base on the sorted slide_row and slide_col *

Parameters: *
start --- the beginning of the index to be ordered. *
end --- the end of the index to be ordered. *
keys --- the indecies to be ordered *

Return: the ordered indecies. **************************************************************************/ protected int[] arrangeKeys(int start, int end, int[] keys){ int temp[]; int i, size, pIndex; temp = keys; size = end - start + 1; pIndex = start; for(i=0; iDescription: * calculates the end of entire task for a batch of files. *

Return: the end of the task. ***************************************************************************/ protected int determineTaskEnd(){ int tempEnd, numFiles, i; FileReading fileReader; Vector fileContent = new Vector(); numFiles = inFileNames.size(); tempEnd = 0; for(i=0; iDescription: * separates a group of number to be sorted into two group based on a number. *

Parameters: *
left --- the minimum boundary. *
right --- the maximum boundary. *
pivot --- the number as the middle point for partition. *
sel --- the selection for slide_row or slide_col. *

Return: the minimum after the patition. *****************************************************************************/ protected int partitionIt(int left, int right, int pivot, int sel){ int leftNum, rightNum; leftNum = left - 1; rightNum = right; while(true){ if(sel == ROW) { while(sortKeys[1][++leftNum] < pivot); while(rightNum > 0 && sortKeys[1][--rightNum] > pivot); } else { while(oneGroup[2][++leftNum] < pivot); while(rightNum > 0 && oneGroup[2][--rightNum] > pivot); } if(leftNum >= rightNum){ break; } else { swap(leftNum, rightNum, sel); } } swap(leftNum, right, sel); return leftNum; } /***************************************************************************** *Description: * sorts a group of number with quick sort algorithm. *

Parameters: *
left --- the minimum boundary. *
right --- the maximum boundary. *
sel --- the selection for slide_row or slide_col. *****************************************************************************/ protected void quickSort(int left, int right, int sel){ int pivot, partition; if(right - left <= 0){ return; } else { if(sel == ROW){ pivot = sortKeys[1][right]; } else { pivot = oneGroup[2][right]; } partition = partitionIt(left, right, pivot, sel); quickSort(left, partition - 1, sel); quickSort(partition+1, right, sel); } } /**************************************************************************** *Description: * splits a string and set the elemet to an array. *

Parameter: *
str --- the input to be splited. *
num --- the number of columns. *

Return: the name. ****************************************************************************/ protected String[] separateLine(String str){ StringSplitter spliter; String name[]; String tempStr = new String(""); spliter = new StringSplitter(str, "\t"); int num = spliter.countTokens(); int length = 0; name = new String[num]; if(num > 0){ while(spliter.hasMoreTokens()){ tempStr = spliter.nextToken(); tempStr = MyIni.removeAllEndSpaces(tempStr); tempStr = MyIni.removeAllHeadSpaces(tempStr); name[length++] = tempStr; } } return name; } protected void setErrorMessage(String eMsg){ fetalError = true; System.out.println(eMsg); ExpressConverter.logFileContent.add("\n***********\n" + eMsg); msg += "*********\n"; msg += eMsg + "\n"; } /***************************************************************************** *DESCRIPTION: * sort slide_row and then slide_col *

Parameters: *
bNum --- the number of block *
bSize --- the number of columns per block *

RETRUNED: the sorted address for the outFile. ***************************************************************************/ protected int[] sortRowCol(int bNum, int bSize) { int temp, ready[], max, min, i, j, numGroup, gSize, head, tail=0; max = outFile.length-1; min = sortKeys[1][0]; quickSort(min, max, ROW); numGroup = outFile.length/(bNum*bSize); gSize = bNum*bSize; oneGroup = new int[3][gSize]; max = gSize; ready = new int[outFile.length]; for(i=0; iDESCRIPTION: * sorts slide_row and then slide_col. Some of slide_row and slide_col could * miss in one block. *

Parameters: *

RETRUNED: the sorted address for the outFile. ***************************************************************************/ protected int[] sortUnbalancedRowCol() { int temp, max, min, i, gSize, head, tail=0; int[] colSize, ready; max = outFile.length-1; min = sortKeys[1][0]; quickSort(min, max, ROW); ready = new int[outFile.length]; colSize = new int[2]; colSize[0] = 0; colSize[1] = min; do{ colSize = getColNumber(colSize[0]); gSize = colSize[1]; oneGroup = new int[3][gSize]; head = colSize[0] - colSize[1]; for(i=0; i= 0){ quickSort(min, max, COL); ready = arrangeKeys(head, tail, ready); } } while(colSize[0] > 0); return ready; } /***************************************************************************** *Description: * exchanges the contents of two elements to be sorted *

Parameters: *
dexl --- the offset of one element. *
dex2 --- the offset of another element. *
sel --- the selection for slide_row or slide_col. *****************************************************************************/ protected void swap(int dex1, int dex2, int sel){ int[] temp = new int[3]; for(int i=0; iDescription:
* counts the number of columns for each row *

Parameters: *
offset --- the offset of starting new colums. *

Return: the number of columns and the start point of next column. *****************************************************************************/ private int[] getColNumber(int offset){ boolean go = true; int[] temp = new int[2]; int ctr = 0; int addr = offset; int val; if(addr >= sortKeys[1].length){ temp[0] = -1; return temp; } else { val = sortKeys[1][addr]; } while(go){ if(addr >= sortKeys[1].length){ go = false; addr++; } else if(val == sortKeys[1][addr++]){ ctr++; } else { go = false; } } temp[0] = addr - 1; temp[1] = ctr; return temp; } }