Class JTVconvert

java.lang.Object
  extended by JTVconvert

public class JTVconvert
extends java.lang.Object

Class JTVconvert to convert a Java Tree View (JTV) set of input sub directories of JTV files to a remapped Array Name labels of the .cdt files to a corresponding set of output JTV sub directories with renamed (.atr,.cdt,.gtr) files. This code was developed for use of mAdb JTV clustered heatmap data with the Group STAT Project (GSP) database.

[REFACTOR] to separate JTVconverter program from HTMLtools.

 List of Methods
=================== JTVconvert() - Constructor convertAllJTVfiles() - convert a list of sub directories of JTV getUnzippedJTVzipFileData() - get array of name & data for zip file. getJTVsubDirData() - get array of name & data for the JTV directory. cvtJTVfileSet() - convert a sub directory JTV file set createTableFromStr() - create Table by parsing tab-delim. string createTableFromFile() - create Table from file tab-delim. string. createTableAtKeywordLine() - create Table starting at hdr keyword. makeMapTable() - create map Table from ftL2S and ftMAS. applyMapTableToCDT() - map 'mAdb ID's to CDT array names. reorderNAMEsubfieldsInCDT() - reorder 'NAME' subfields in CDT all data rows copyJTVjarFilesToJTVOutputDir() - copy JTV jar files to JTVOutputDir. reZipConvertedFiles() - ReZip converted files to output JTV directory.

This code is available at the HTMLtools project on SourceForge at http://htmltools.sourceforge.org/ under the "Common Public License Version 1.0" http://www.opensource.org/licenses/cpl1.0.php.

It was derived and refactored from the open source MAExplorer (http://maexplorer.sourceforge.org/), and Open2Dprot (http://Open2Dprot.sourceforge.net/) Table modules.

$Date: 2009/07/13 11:45:56 $ $Revision: 1.28 $
Copyright 2008, 2009 by Peter Lemkin E-Mail: lemkin@users.sourceforge.net http://lemkingroup.com/


Field Summary
 HTMLtools cvt
           
 FileTable fio
          Global fileTable instance
 
Constructor Summary
JTVconvert(HTMLtools cvt)
          JTVconvert() - Constructor
 
Method Summary
private  boolean applyMapTableToCDT(FileTable ftM, FileTable ftCDT, int idx_useToName_M, int idx_mAdbID_M)
          applyMapTableToCDT() - map 'mAdb ID's to CDT array names.
 boolean convertAllJTVfiles()
          convertAllJTVfiles() - convert a list of sub directories of JTV file sets by reading the three files from the each of the sub directories in the jtvInputDir directory.
private  boolean copyJTVjarFilesToJTVOutputDir()
          copyJTVjarFilesToJTVOutputDir() - copy JTV jar files to JTVOutputDir.
private  FileTable createTableAtKeywordLine(java.lang.String filePath, java.lang.String tblName, java.lang.String keyword)
          createTableAtKeywordLine() - create Table starting at hdr keyword.
private  FileTable createTableFromFile(java.lang.String filePath, java.lang.String tblName)
          createTableFromFile() - create Table from file tab-delim.
private  FileTable createTableFromStr(java.lang.String tblStr, java.lang.String tblName)
          createTableFromStr() - create Table by parsing tab-delim.
private  boolean cvtJTVfileSet(java.lang.String jtvInputFilePath, java.lang.String jtvFileBaseName, java.lang.String jtvInputDir, java.lang.String jtvOutputDir, int fromL2SmapColIdx, int toL2SmapColIdx, java.lang.String jtv_mAdbArraySummaryFile, java.lang.String jtv_mapHdrNamesFile)
          cvtJTVfileSet() - convert a sub directory JTV file set by reading the three files from the (jtvInputDir+inputSubDir) sub directory with (.atr,.cdt,.gtr) file extensions.
private  java.lang.String[][] getJTVsubDirData(java.lang.String inputSubDir)
          getJTVsubDirData() - get array of name & data for the JTV directory.
private  java.lang.String[][] getUnzippedJTVzipFileData(java.lang.String jtvZipFileNamePath)
          getUnzippedJTVzipFileData() - get array of name & data for zip file.
private  FileTable makeMapTable(FileTable ftL2S, FileTable ftMAS, int fromL2SmapColIdx, int toL2SmapColIdx, java.lang.String tblName)
          makeMapTable() - create map Table from ftL2S and ftMAS.
private  boolean reorderNAMEsubfieldsInCDT(FileTable ftCDT)
          reorderNAMEsubfieldsInCDT() - reorder 'NAME' subfields in CDT all data rows to improve usability in JTV browser.
private  boolean reZipConvertedFiles(java.lang.String baseDirToZip)
          reZipConvertedFiles() - ReZip the converted files in the output JTV directory baseDataDir in a file with the same name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cvt

public HTMLtools cvt

fio

public FileTable fio
Global fileTable instance

Constructor Detail

JTVconvert

public JTVconvert(HTMLtools cvt)
JTVconvert() - Constructor

Method Detail

convertAllJTVfiles

public boolean convertAllJTVfiles()
convertAllJTVfiles() - convert a list of sub directories of JTV file sets by reading the three files from the each of the sub directories in the jtvInputDir directory. It maps the .cdt file in each sub directory to use the toHdrName column of the equivalent mapHdrFile map Table instead of the "EID:'mAdb ID'" as generated by mAdb. The mapping between "mAdb ID" and short array names is done using the jtv_mAdbArraySummaryFile Table map. It then writes out the JTV subset to a created sub directory in jtvOutputDir which has the same base name as the input JTV sub directory being processed. The arguments are in the Global variables

 The full switch is four arguments:
   '-jtvNamesMap:{mAdbArraySummaryFile,mapHdrFile,fromHdrName,toHdrName}'.
 The optional switches are: '-jtvInputDir:{jtvInputDir}' and
 '-jtvOutputDir:{jtvOutputSubDir}' to set the directories to
 other than the defaults ("JTVinput" and "JTVoutput").
 The JTV Global variable definitions are:
   jtvInputDir - where JTV input sub directories are found 
   jtvOutputDir - where JTV output sub directories are written
   jtvUseMapColName - column name used when remap the 'mAdb ID' data
   jtv_mAdbArraySummaryFile - mAdb Array Summary file Table of "mAdb ID"s
   jtv_mapHdrNamesFile - long to short Affy name mapping Table.
   

Returns:
true if write out all of the files, false if there is an error or abortProcessingFlag was set..

getUnzippedJTVzipFileData

private java.lang.String[][] getUnzippedJTVzipFileData(java.lang.String jtvZipFileNamePath)
getUnzippedJTVzipFileData() - get array of name & data for zip file. There should be 3 files in the zip file ending in [0]".atr", [1].cdt", [2]".gtr"
 Unzip the JTV data into dataList[0:nEntries-1][0:1].
 where:
    dataList[*][0] = file names
    dataList[*][1] = unzipped data for each file 

Parameters:
zipFileName - is a JTV zip file to read
Returns:
true if succeed

getJTVsubDirData

private java.lang.String[][] getJTVsubDirData(java.lang.String inputSubDir)
getJTVsubDirData() - get array of name & data for the JTV directory. There should be 3 files in the unzipped directory ending in ".atr", .cdt", ".gtr"
 Return the JTV data in dataList[0:nEntries-1][0:1].
 where:
    dataList[*][0] = file names
    dataList[*][1] = data for each file 

Parameters:
inputSubDir - is a JTV subdiredtory to read
Returns:
true if succeed

cvtJTVfileSet

private boolean cvtJTVfileSet(java.lang.String jtvInputFilePath,
                              java.lang.String jtvFileBaseName,
                              java.lang.String jtvInputDir,
                              java.lang.String jtvOutputDir,
                              int fromL2SmapColIdx,
                              int toL2SmapColIdx,
                              java.lang.String jtv_mAdbArraySummaryFile,
                              java.lang.String jtv_mapHdrNamesFile)
cvtJTVfileSet() - convert a sub directory JTV file set by reading the three files from the (jtvInputDir+inputSubDir) sub directory with (.atr,.cdt,.gtr) file extensions. It then maps the .cdt file to use the jtvUseMapColNbr column of the equivalent jtv_mapHdrNamesFile instead of the "EID:'mAdb ID'" as generated for the JTV by mAdb. The mapping between "mAdb ID" and short array names is done using the jtv_mAdbArraySummaryFile Table map. It then writes out the JTV subset to a created sub directory (jtvOutputDir+inputSubDir) which has the same base name as the input directory.

[REFACTOR] to separate JTVconverter program from HTMLtools.

Parameters:
jtvInputFilePath - - is the input sub directory to process (not the full path - need to preface with jtvInputDir to get the full path). If the inputSubDir is a file ending in .zip, then read the dataList by unzipping that file. *
jtvFileBaseName - is the single JTV directory or zip file base name
jtvInputDir - - directory to find the set of input JTV sub directories, each with (.atr,.cdt,.gtr) extension files.
jtvOutputDir - - directory to write the converted JTV output sub directory.
fromL2SmapColIdx - - column index used when remap the 'mAdb ID' data FROM a mapping data name with this column in the jtv_mapHdrNamesFile map.
toL2SmapColIdx - - column index used when remap the 'mAdb ID' data TO a new data name with this column in the jtv_mapHdrNamesFile map.
jtv_mAdbArraySummaryFile - - name of the mAdb Array Summary file that contains a (MAS) Table with "mAdb ID" and the corresponding "Array Name".
jtv_mapHdrNamesFile - - is the name of the Long to Short array name mapping file that contains a (L2S)Table with the array names as well as the alternate array names that are used in the mapping.
Returns:
true if succeed,

createTableFromStr

private FileTable createTableFromStr(java.lang.String tblStr,
                                     java.lang.String tblName)
createTableFromStr() - create Table by parsing tab-delim. string

Parameters:
tblStr - - a tab-delimited string
tblName - - of the table
Returns:
the FileTable created, else null

createTableFromFile

private FileTable createTableFromFile(java.lang.String filePath,
                                      java.lang.String tblName)
createTableFromFile() - create Table from file tab-delim. string.

Parameters:
filePath - - full path of the table file to read
tblName - - of the table
Returns:
the FileTable created, else null

createTableAtKeywordLine

private FileTable createTableAtKeywordLine(java.lang.String filePath,
                                           java.lang.String tblName,
                                           java.lang.String keyword)
createTableAtKeywordLine() - create Table starting at hdr keyword. It starts parsing the tab-delimited string read from the file at the header row that contains the keyword.

Parameters:
filePath - - full path of the table file to read
tblName - - of the table
keyword - - contained in the table header row.
Returns:
the FileTable created, else null

makeMapTable

private FileTable makeMapTable(FileTable ftL2S,
                               FileTable ftMAS,
                               int fromL2SmapColIdx,
                               int toL2SmapColIdx,
                               java.lang.String tblName)
makeMapTable() - create map Table from ftL2S and ftMAS. Create Map Table ftM from the ftL2S Table by adding the "mAdb ID" data in ftL2S to the matching array name row in ftL2S using the ftMAS "Array Name". Note: This mapping depends on formats of: 1) mAdb "Array Summary Table" .CEL file name in field "Array Name" and the 2) GSP "LongToShortMap" generated from the "Affy .CEL file" field in the individual "EGxxx" Tables. Because of the special dependence on the mAdb "Array Summary Table" this uses special [HACK]s.

Parameters:
ftL2S - - LongToShortMap Table
ftMAS - - mAdb Array Summary Table
fromL2SmapColIdx - - column index used when remap the 'mAdb ID' data FROM a mapping data name with this column in the jtv_mapHdrNamesFile map.
toL2SmapColIdx - - column index used when remap the 'mAdb ID' data TO a new data name with this column in the jtv_mapHdrNamesFile map.
tblName - - of the table
Returns:
the FileTable map (ftM) created, else null

applyMapTableToCDT

private boolean applyMapTableToCDT(FileTable ftM,
                                   FileTable ftCDT,
                                   int idx_useToName_M,
                                   int idx_mAdbID_M)
applyMapTableToCDT() - map 'mAdb ID's to CDT array names. Map Table ftM "mAdbID" data to map the header names doing partial match of the ftCDT.tFields[] data of the form "EID:#" where the # is the matching ftM "mAdbID" data for ftM row rM. For each match, replace the header with ftM jtvUseMapColNbr data for row rM.

Parameters:
ftM - - name Mapping Table
ftCDT - - CDT Table to map the sample names in the ftCDT.tFields
idx_useToName_M - - ftM index of the TO data name
idx_mAdbID_M - - ftM index of the FROM data name
Returns:
true if mapped the ftCDT header names

reorderNAMEsubfieldsInCDT

private boolean reorderNAMEsubfieldsInCDT(FileTable ftCDT)
reorderNAMEsubfieldsInCDT() - reorder 'NAME' subfields in CDT all data rows to improve usability in JTV browser.
 Reorder:
   "WID:... || xxxxxx_at || MAP:... || gene -- geneDescr. || RID:..."
 to
   "gene -- geneDescr. || xxxxxx_at || WID:... ||  MAP:... || RID:..."
 

Parameters:
ftCDT - - CDT table containing rows of data to reorder NAME field.
Returns:
true if succeed

copyJTVjarFilesToJTVOutputDir

private boolean copyJTVjarFilesToJTVOutputDir()
copyJTVjarFilesToJTVOutputDir() - copy JTV jar files to JTVOutputDir. If doing 'jtvHTMLgenerate', then you can use the '-jtvCopyJTVjars:{JTV jars directory}' option to copy the JTV jar files and plugins to the jtvOutputDir.

Returns:
true if succeed

reZipConvertedFiles

private boolean reZipConvertedFiles(java.lang.String baseDirToZip)
reZipConvertedFiles() - ReZip the converted files in the output JTV directory baseDataDir in a file with the same name. Set by '-jtvReZipConvertedFiles'. Note: we do not want to copy the JTVoutput/ as part of the zip files, so temporarily change the Java current directory so we don't do this AND change it back when we are done.

[DEBUG] problem with directory level in FileTable.writeZipFile(). It contains the parent directory in the Zip file.

Parameters:
baseDirToZip - is the base directory to zip in current directory but save it in the cvt.jtvInputDir directory.
Returns:
true if succeed