biggests.gui
Class BiggestsIO

java.lang.Object
  extended by biggests.gui.BiggestsIO

public class BiggestsIO
extends java.lang.Object

Title: BiGGEsTS's Input/Output

Description: Provides methods for reading data from and writing data to files, for copying, deleting and creating directories and files. Restoring and saving sessions. Downloading, compressing/decompressing files.

Copyright: Copyright (C) 2007 Joana Gonçalves This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.


Field Summary
static int BUF_SIZE
          The size of the buffer.
static java.lang.String JPG
          Image format: JPG
static int MAX_HEIGHT
          Maximum image height.
static int MAX_WIDTH
          Maximum image width.
static java.lang.String PNG
          Image format: PNG
static java.lang.String SVG
          Image format: SVG
 
Constructor Summary
BiggestsIO()
           
 
Method Summary
static void copy(de.schlichtherle.io.File source, de.schlichtherle.io.File destination)
          Copies a file to another location.
static void deleteFolderContent(java.lang.String pathToFolder)
          Deletes a directory content.
static void download(java.lang.String address, java.lang.String localFilePath, ProgressBarFrame progressFrame, java.lang.String message)
          Downloads the file from the Internet located in the specified address.
static void downloadGeneAssociationFile(java.lang.String geneAssociationFilesURL, java.lang.String pathToGOFiles, java.lang.String geneAssociationFileName, ProgressBarFrame progressFrame)
          Downloads gene association file.
static void downloadGeneOntologyFile(java.lang.String geneOntologyFilesURL, java.lang.String pathToGOFiles, java.lang.String geneOntologyFileName, ProgressBarFrame progressFrame)
          Downloads gene ontology file.
static void exportComponentToImage(java.awt.Component component, int x, int y, int width, int height, java.lang.String format, java.lang.String filePath)
          Exports a GUI component to an image file.
static void exportComponentToImage(java.awt.Component component, java.lang.String format, java.lang.String filePath)
          Exports a GUI component to an image file.
static java.lang.String findFileExtensionInDirectoryPath(java.lang.String fileExtension, java.lang.String directoryPath)
          Finds the first file with a specific file extension in some specific directory.
static java.lang.String findFileInDirectoryPath(java.lang.String filename, java.lang.String directoryPath)
          Finds for a specific filename in a specific directory path.
static boolean getStop()
          Returns the value of stop flag.
static void gunzipFile(de.schlichtherle.io.File file_input, de.schlichtherle.io.File dir_output)
          Gunzips the input archive.
static void initializeFolders(java.lang.String[] paths)
          Creates a set of directories with the specified paths.
static java.lang.String[][] readConversionEntriesFromFileTXT(java.lang.String filePath, char separator)
          Reads conversion file entries from a text file.
static java.lang.Object[][] readExpressionDataFromFileTXT(java.lang.String file, char separator, float missingValue)
          Reads gene expression data from a txt file.
static void restoreSession(BiggestsFrame frame, java.lang.String pathToSessionArchive)
          Restores a session from a .zip archive file.
static void restoreSession2(BiggestsFrame frame, java.lang.String pathToSessionArchive)
          Restores a session from a .zip archive file.
static void saveSession(DatasetTree tree, java.lang.String pathToFunctionResults, java.lang.String pathToSessionArchive)
          Saves a session to a .zip archive file.
static void saveSession2(DatasetTree tree, java.lang.String pathToFunctionResults, java.lang.String pathToSessionArchive)
          Saves a session to a .zip archive file.
static void setStop(boolean st)
          Sets stop flag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUF_SIZE

public static final int BUF_SIZE
The size of the buffer.

See Also:
Constant Field Values

PNG

public static final java.lang.String PNG
Image format: PNG

See Also:
Constant Field Values

JPG

public static final java.lang.String JPG
Image format: JPG

See Also:
Constant Field Values

SVG

public static final java.lang.String SVG
Image format: SVG

See Also:
Constant Field Values

MAX_WIDTH

public static final int MAX_WIDTH
Maximum image width.

See Also:
Constant Field Values

MAX_HEIGHT

public static final int MAX_HEIGHT
Maximum image height.

See Also:
Constant Field Values
Constructor Detail

BiggestsIO

public BiggestsIO()
Method Detail

setStop

public static void setStop(boolean st)
Sets stop flag.

Parameters:
st - the boolean value

getStop

public static boolean getStop()
Returns the value of stop flag.

Returns:
the boolean value of stop flag

initializeFolders

public static void initializeFolders(java.lang.String[] paths)
                              throws java.io.IOException
Creates a set of directories with the specified paths.

Parameters:
paths - the String[] paths of the directories to be created
Throws:
java.io.IOException - when some directory could not be created

deleteFolderContent

public static void deleteFolderContent(java.lang.String pathToFolder)
Deletes a directory content.

Parameters:
pathToFolder - the String path to the specified directory
See Also:
#deleteRecursively(File[] files)

findFileInDirectoryPath

public static java.lang.String findFileInDirectoryPath(java.lang.String filename,
                                                       java.lang.String directoryPath)
                                                throws java.io.IOException,
                                                       java.lang.Exception
Finds for a specific filename in a specific directory path. Returns the absolute path for the file, if it was found, or null othwerwise.

Parameters:
filename - the filename String to search for
directoryPath - the directory path String, where to search for the given filename
Returns:
the absolute file path String
Throws:
java.io.IOException - if the directory does not exist
java.lang.Exception - if the directory path is not valid

findFileExtensionInDirectoryPath

public static java.lang.String findFileExtensionInDirectoryPath(java.lang.String fileExtension,
                                                                java.lang.String directoryPath)
                                                         throws java.io.IOException,
                                                                java.lang.Exception
Finds the first file with a specific file extension in some specific directory. A file extension starts with ".". Returns the absolute file path for the file, if it was found, or a null pointer othwerwise.

Parameters:
fileExtension - the String which contains the file extension to search for; must start with "."
directoryPath - the String which contains the path to the directory where to search for the file
Returns:
the file path String
Throws:
java.io.IOException - if the directory does not exist
java.lang.Exception - if the directory path or the file extension is not valid

copy

public static void copy(de.schlichtherle.io.File source,
                        de.schlichtherle.io.File destination)
                 throws java.io.IOException
Copies a file to another location. If the destination file dores not exist, it is created.

Parameters:
source - the File to copy to another location
destination - the File which is the destination target
Throws:
java.io.IOException - when it is not possible to copy the file

readExpressionDataFromFileTXT

public static java.lang.Object[][] readExpressionDataFromFileTXT(java.lang.String file,
                                                                 char separator,
                                                                 float missingValue)
                                                          throws java.io.FileNotFoundException,
                                                                 java.io.IOException
Reads gene expression data from a txt file. Some rows may contain conditions' names and some columns may contain genes' IDs.

Parameters:
file - String the filepath which contains the file to read
separator - the character that delimits the data
missingValue - float the value to fill missings
Returns:
Object[][] the expression data read from the given file
Throws:
java.io.FileNotFoundException
java.io.IOException

readConversionEntriesFromFileTXT

public static java.lang.String[][] readConversionEntriesFromFileTXT(java.lang.String filePath,
                                                                    char separator)
                                                             throws java.io.FileNotFoundException,
                                                                    java.io.IOException
Reads conversion file entries from a text file. Conversion entries must be in a two column format, for which the first element is the probeset ID and the second one is the GO gene ID, both delimited by the separator character.

Parameters:
filePath - String the path of the file with conversion entries to read
separator - the character that delimits the data
Returns:
String[][] the conversion entries read from the given file
Throws:
java.io.FileNotFoundException
java.io.IOException

saveSession

public static void saveSession(DatasetTree tree,
                               java.lang.String pathToFunctionResults,
                               java.lang.String pathToSessionArchive)
                        throws java.io.NotSerializableException,
                               java.io.FileNotFoundException,
                               java.io.IOException
Saves a session to a .zip archive file.

Parameters:
tree - the DatasetTree which contains datasets loaded and manipulated in the session
pathToFunctionResults - String the path to directory which contains the files resulting from function analysis
pathToSessionArchive - String the path to the resulting archive file
Throws:
java.io.NotSerializableException - if one of the objects that system tried to write to a file is not serializable
java.io.FileNotFoundException - if files could not be found
java.io.IOException - if could not write/read from files

saveSession2

public static void saveSession2(DatasetTree tree,
                                java.lang.String pathToFunctionResults,
                                java.lang.String pathToSessionArchive)
                         throws java.io.NotSerializableException,
                                java.io.FileNotFoundException,
                                java.io.IOException
Saves a session to a .zip archive file.

Parameters:
tree - the DatasetTree which contains datasets loaded and manipulated in the session
pathToFunctionResults - String the path to directory which contains the files resulting from function analysis
pathToSessionArchive - String the path to the resulting archive file
Throws:
java.io.NotSerializableException - if one of the objects that system tried to write to a file is not serializable
java.io.FileNotFoundException - if files could not be found
java.io.IOException - if could not write/read from files

restoreSession

public static void restoreSession(BiggestsFrame frame,
                                  java.lang.String pathToSessionArchive)
                           throws java.lang.Exception
Restores a session from a .zip archive file. Zip file must contain a file named tree.big with an object of type DatasetTree and a directory named Function_Results which contains resulting files from function analysis.

Parameters:
frame - the BiGGEsTS main window
pathToSessionArchive - String the path to the zip archive which contains the files of the session to restore
Throws:
java.lang.Exception - if the format of the session files could not be recognized

restoreSession2

public static void restoreSession2(BiggestsFrame frame,
                                   java.lang.String pathToSessionArchive)
                            throws java.lang.Exception
Restores a session from a .zip archive file. Zip file must contain a file named tree.big with an object of type DatasetTree and a directory named Function_Results which contains resulting files from function analysis.

Parameters:
frame - the BiGGEsTS main window
pathToSessionArchive - String the path to the zip archive which contains the files of the session to restore
Throws:
java.lang.Exception - if the format of the session files could not be recognized

downloadGeneOntologyFile

public static void downloadGeneOntologyFile(java.lang.String geneOntologyFilesURL,
                                            java.lang.String pathToGOFiles,
                                            java.lang.String geneOntologyFileName,
                                            ProgressBarFrame progressFrame)
                                     throws java.lang.Exception
Downloads gene ontology file.

Parameters:
geneOntologyFilesURL - String the URL where gene ontology files can be found
pathToGOFiles - String the path to gene ontology files directory/folder
geneOntologyFileName - String the name of the gene ontology file to be downloaded (usually gene_ontology.obo)
progressFrame - ProgressBarFrame the progress bar to send information about the progress of the operation
Throws:
java.lang.Exception

downloadGeneAssociationFile

public static void downloadGeneAssociationFile(java.lang.String geneAssociationFilesURL,
                                               java.lang.String pathToGOFiles,
                                               java.lang.String geneAssociationFileName,
                                               ProgressBarFrame progressFrame)
                                        throws java.lang.Exception
Downloads gene association file.

Parameters:
geneAssociationFilesURL - String the URL where gene association files can be found
pathToGOFiles - String the path to gene ontology files directory/folder
geneAssociationFileName - String the name of the gene ontology file to be downloaded (usually gene_ontology.obo)
progressFrame - ProgressBarFrame the progress bar to send information about the progress of the operation
Throws:
java.lang.Exception

download

public static void download(java.lang.String address,
                            java.lang.String localFilePath,
                            ProgressBarFrame progressFrame,
                            java.lang.String message)
                     throws java.io.IOException,
                            java.lang.Exception
Downloads the file from the Internet located in the specified address. The downloaded file is stored in localFilePath (this path already contains the name of the file).

Parameters:
address - String the address of the file to download
localFilePath - String the local file path to store the downloaded file
progressFrame - ProgressBarFrame
message - String
Throws:
java.io.IOException - if input and/or output stream could not be closed
java.lang.Exception - if file could not be downloaded

gunzipFile

public static void gunzipFile(de.schlichtherle.io.File file_input,
                              de.schlichtherle.io.File dir_output)
                       throws java.io.IOException,
                              java.lang.Exception
Gunzips the input archive. Sends the output to the directory specified by dir_output. Assumes that the input file name ends with ".gz"

Parameters:
file_input - the input gzipped File
dir_output - File directory to send the gunzipped file to
Throws:
java.io.IOException
java.lang.Exception

exportComponentToImage

public static void exportComponentToImage(java.awt.Component component,
                                          java.lang.String format,
                                          java.lang.String filePath)
                                   throws java.io.IOException
Exports a GUI component to an image file. Supported image file types are: PNG and JPG. The image will be created with the dimensions of the original component's image. The path of the image file is given in filePath and must contain the appropriate file extension.

Parameters:
component - Component the component to export to image
format - String the format of the image (PNG or JPG)
filePath - String the path to the image file
Throws:
java.io.IOException - if the component cannot be exported to the image file

exportComponentToImage

public static void exportComponentToImage(java.awt.Component component,
                                          int x,
                                          int y,
                                          int width,
                                          int height,
                                          java.lang.String format,
                                          java.lang.String filePath)
                                   throws java.io.IOException
Exports a GUI component to an image file. Supported image file types are: PNG and JPG. The image will be created from x- and y-coordinates (left-most top corner), with width width and height height from the original component's image. The path of the file is given in filePath and must contain the appropriate file extension.

Parameters:
component - Component the component to export to image
x - int the initial x-coordinate of the original image from which the final image will be produced (left-most top corner)
y - int the initial y-coordinate of the original image from which the final image will be produced (left-most top corner)
width - int the width of the image to produce
height - int the height of the image to produce
format - String the format of the image (PNG or JPG)
filePath - String the path to the image file
Throws:
java.io.IOException - if the component cannot be exported to the image file