Last update: 2011-06-23

org.proteios.io
Class FilenameParseUtil

java.lang.Object
  extended by org.proteios.io.FilenameParseUtil

public class FilenameParseUtil
extends Object

This class supports simple extraction of data from filenames. Used e.g. to parse the data in a gel mass spectrometry filename.

Version:
2.0
Author:
Olle
Last modified
$Date: 2007-01-15 13:37:53 +0100 (Thu, 09 Nov 2006) $

Field Summary
protected static org.apache.log4j.Logger log
          Logger used.
 
Constructor Summary
FilenameParseUtil()
          Default constructor.
 
Method Summary
 String convertToLocalWellNotation(String wellname, String prototypeName)
          Converts a well position of standard notation of type "A12" to local notation.
 String convertWellNotation(String wellname)
          Converts a well position to standard notation of type "A12", where the uppercase letter notates the column and the number the row.
 String fetchBasename(String filename)
          Fetches the basename from a filename, i.e. part of the filename before an optional file extension separated by a dot ".".
 String fetchBaseString(String inStr, String separationStr)
          Fetches the base string from an input string given a separation string.
 String fetchCounter(String filename)
          Fetches the counter string from filename, i.e. part of the filename after the target id and date, excluding the position, e.g. filename "FL1_060306_2@A1.txt" will give counter "2".
 String fetchDate(String filename)
          Fetches the date from filename, i.e. part of the filename after the target id starting with a number character, e.g. filename "FL1_060306_2@A1.txt" will give date "060306".
 String fetchExperimenter(String filename)
          Fetches the experimenter from filename, i.e. part of the target id before any number characters, e.g. filename "FL1_060306_2@A1.txt" will give experimenter "FL".
 String fetchExperimenterFromTarget(String targetId)
          Fetches the experimenter from a target id, i.e. part of the target id before any number characters, e.g. target id "FL1" will give experimenter "FL".
 String fetchFileExtension(String filename)
          Fetches the file extension from a filename, i.e. part of the filename after an optional separation dot ".".
 int fetchFirstNonNumCharIndex(String inStr)
          Fetches the position index of the first non-numerical character in a string.
 int fetchFirstNumCharIndex(String inStr)
          Fetches the position index of the first numerical character in a string.
 int fetchLastNonNumCharIndex(String inStr)
          Fetches the position index of the last non-numerical character in a string.
 int fetchLastNumCharIndex(String inStr)
          Fetches the position index of the last numerical character in a string.
 String fetchNonPositionName(String filename)
          Fetches the pure basename excluding plate position from a filename, i.e. part of the filename before any optional dot "." and "@" characters, e.g. filename "FL1_060306_2@A1.txt" will give "FL1_060306_1".
 String fetchPartAfterEndCut(String inStr, String separationStr, boolean firstCut, boolean firstPart)
          Fetches the first or last part of an input string, after it has been cut in two pieces by the first or last occurrence of a separation string.
 String fetchPlatePosition(String filename)
          Fetches the plate position from filename, i.e. part of the basename after an "@" character, e.g. filename "FL1_060306_2@A1.txt" will give "A1".
 String fetchPureBasename(String filename)
          Fetches the pure basename from a filename, i.e. part of the filename before any optional dots ".".
 String fetchPureBaseString(String inStr, String separationStr)
          Fetches the pure base string from an input string given a separation string.
 String fetchPureFileExtension(String filename)
          Fetches the pure file extension from a filename, i.e. part of the filename after any optional dots ".".
 String fetchPureResidueString(String inStr, String separationStr)
          Fetches the pure residue string from an input string given a separation string.
 String fetchRegexResult(String inStr, String regexStr)
          Fetches the resulting string after parsing an input string with an input regex pattern.
 String fetchResidueString(String inStr, String separationStr)
          Fetches the residue string from an input string given a separation string.
 String fetchTargetId(String filename)
          Fetches the target id from a filename, i.e. part of the filename before any optional underscore "_", dot "
 String fetchTargetIdFromSHWFilename(String filename)
          Fetches the target id from a Spot Handling Worksatation (SHW) filename, i.e. part of the filename after string "18115042" and before any optional underscore "_", dot "
 String fetchTargetNumber(String filename)
          Fetches the target number from filename, i.e. part of the target id starting with a number character, e.g. filename "FL1_060306_2@A1.txt" will give target number "1".
 String fetchTargetNumberFromTarget(String targetId)
          Fetches the target number from a target id, i.e. part of the target id starting with a number character, e.g. target id "FL1" will give target number "1".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log
Logger used. Used to log specific events.

Constructor Detail

FilenameParseUtil

public FilenameParseUtil()
Default constructor.

Method Detail

fetchRegexResult

public String fetchRegexResult(String inStr,
                               String regexStr)
Fetches the resulting string after parsing an input string with an input regex pattern.

Parameters:
inStr - String the input string to parse.
regexStr - String The regex pattern string to use for parsing.
Returns:
String The resulting string.

fetchPartAfterEndCut

public String fetchPartAfterEndCut(String inStr,
                                   String separationStr,
                                   boolean firstCut,
                                   boolean firstPart)
Fetches the first or last part of an input string, after it has been cut in two pieces by the first or last occurrence of a separation string.

Parameters:
inStr - String the input string to parse.
separationStr - String the separation string.
firstCut - boolean true for cut is at first occurrence of the separation string, else last.
firstPart - boolean true for first part after cut at separation string, else last.
Returns:
String the first or last part of the cut string.

fetchPureBaseString

public String fetchPureBaseString(String inStr,
                                  String separationStr)
Fetches the pure base string from an input string given a separation string. The pure base string is the substring before the first occurrence of the separation string, i.e. input string "FL1_060306_2@A1.txt" and separation string "_" will give "FL1".

Parameters:
inStr - String the input string to parse.
separationStr - String the separation string.
Returns:
String the pure base string.

fetchBaseString

public String fetchBaseString(String inStr,
                              String separationStr)
Fetches the base string from an input string given a separation string. The base string is the substring before the last occurrence of the separation string, i.e. input string "FL1_060306_2@A1.txt" and separation string "_" will give "FL1_060306".

Parameters:
inStr - String the input string to parse.
separationStr - String the separation string.
Returns:
String the base string.

fetchPureResidueString

public String fetchPureResidueString(String inStr,
                                     String separationStr)
Fetches the pure residue string from an input string given a separation string. The pure residue string is the substring after the last occurrence of the separation string, i.e. input string "FL1_060306_2@A1.txt" and separation string "_" will give "2@A1.txt".

Parameters:
inStr - String the input string to parse.
separationStr - String the separation string.
Returns:
String the pure residue string.

fetchResidueString

public String fetchResidueString(String inStr,
                                 String separationStr)
Fetches the residue string from an input string given a separation string. The residue string is the substring after the first occurrence of the separation string, i.e. input string "FL1_060306_2@A1.txt" and separation string "_" will give "060306_2@A1.txt".

Parameters:
inStr - String the input string to parse.
separationStr - String the separation string.
Returns:
String the residue string.

fetchFirstNumCharIndex

public int fetchFirstNumCharIndex(String inStr)
Fetches the position index of the first numerical character in a string. Returns -1 if no numerical character is found.

Parameters:
inStr - String the string to parse.
Returns:
int index of the first numerical character, or -1 if none.

fetchLastNumCharIndex

public int fetchLastNumCharIndex(String inStr)
Fetches the position index of the last numerical character in a string. Returns -1 if no numerical character is found.

Parameters:
inStr - String the string to parse.
Returns:
int index of the last numerical character, or -1 if none.

fetchFirstNonNumCharIndex

public int fetchFirstNonNumCharIndex(String inStr)
Fetches the position index of the first non-numerical character in a string. Returns -1 if no non-numerical character is found.

Parameters:
inStr - String the string to parse.
Returns:
int index of the first non-numerical character, or -1 if none.

fetchLastNonNumCharIndex

public int fetchLastNonNumCharIndex(String inStr)
Fetches the position index of the last non-numerical character in a string. Returns -1 if no non-numerical character is found.

Parameters:
inStr - String the string to parse.
Returns:
int index of the last non-numerical character, or -1 if none.

fetchBasename

public String fetchBasename(String filename)
Fetches the basename from a filename, i.e. part of the filename before an optional file extension separated by a dot ".". If several dots exist in the filename, all but the last are considered part of the basename, e.g. filename "example.tar.gz" has basename "example.tar".

Parameters:
filename - String the filename to parse.
Returns:
String the basename. if found, else (String)null.

fetchPureBasename

public String fetchPureBasename(String filename)
Fetches the pure basename from a filename, i.e. part of the filename before any optional dots ".". If several dots exist in the filename, none are considered part of the pure basename, e.g. filename "example.tar.gz" has pure basename "example".

Parameters:
filename - String the filename to parse.
Returns:
String the pure basename. if found, else (String)null.

fetchFileExtension

public String fetchFileExtension(String filename)
Fetches the file extension from a filename, i.e. part of the filename after an optional separation dot ".". If several dots exist in the filename, all but the first are considered part of the file extension, e.g. filename "example.tar.gz" has file extension "tar.gz".

Parameters:
filename - String the filename to parse.
Returns:
String the file extension. if found, else (String)null.

fetchPureFileExtension

public String fetchPureFileExtension(String filename)
Fetches the pure file extension from a filename, i.e. part of the filename after any optional dots ".". If several dots exist in the filename, none are considered part of the pure file extension, e.g. filename "example.tar.gz" has pure file extension "gz".

Parameters:
filename - String the filename to parse.
Returns:
String the pure file extension. if found, else (String)null.

fetchNonPositionName

public String fetchNonPositionName(String filename)
Fetches the pure basename excluding plate position from a filename, i.e. part of the filename before any optional dot "." and "@" characters, e.g. filename "FL1_060306_2@A1.txt" will give "FL1_060306_1".

Parameters:
filename - String the filename to parse.
Returns:
String the pure basename excluding plate position.

fetchTargetId

public String fetchTargetId(String filename)
Fetches the target id from a filename, i.e. part of the filename before any optional underscore "_", dot ".", and "@" characters, e.g. filename "FL1_060306_2@A1.txt" will give "FL1".

Parameters:
filename - String the filename to parse.
Returns:
String the target id.

fetchTargetIdFromSHWFilename

public String fetchTargetIdFromSHWFilename(String filename)
Fetches the target id from a Spot Handling Worksatation (SHW) filename, i.e. part of the filename after string "18115042" and before any optional underscore "_", dot ".", and "@" characters, e.g. filename "18115042FL1" will give "FL1".

Parameters:
filename - String the SHW filename to parse.
Returns:
String the target id.

fetchExperimenterFromTarget

public String fetchExperimenterFromTarget(String targetId)
Fetches the experimenter from a target id, i.e. part of the target id before any number characters, e.g. target id "FL1" will give experimenter "FL".

Parameters:
targetId - String the target id to parse.
Returns:
String the experimenter string.

fetchTargetNumberFromTarget

public String fetchTargetNumberFromTarget(String targetId)
Fetches the target number from a target id, i.e. part of the target id starting with a number character, e.g. target id "FL1" will give target number "1".

Parameters:
targetId - String the target id to parse.
Returns:
String the target number string.

fetchExperimenter

public String fetchExperimenter(String filename)
Fetches the experimenter from filename, i.e. part of the target id before any number characters, e.g. filename "FL1_060306_2@A1.txt" will give experimenter "FL".

Parameters:
filename - String the filename to parse.
Returns:
String the experimenter string.

fetchTargetNumber

public String fetchTargetNumber(String filename)
Fetches the target number from filename, i.e. part of the target id starting with a number character, e.g. filename "FL1_060306_2@A1.txt" will give target number "1".

Parameters:
filename - String the filename to parse.
Returns:
String the target number string.

fetchDate

public String fetchDate(String filename)
Fetches the date from filename, i.e. part of the filename after the target id starting with a number character, e.g. filename "FL1_060306_2@A1.txt" will give date "060306".

Parameters:
filename - String the filename to parse.
Returns:
String the date string.

fetchCounter

public String fetchCounter(String filename)
Fetches the counter string from filename, i.e. part of the filename after the target id and date, excluding the position, e.g. filename "FL1_060306_2@A1.txt" will give counter "2".

Parameters:
filename - String the filename to parse.
Returns:
String the counter string.

fetchPlatePosition

public String fetchPlatePosition(String filename)
Fetches the plate position from filename, i.e. part of the basename after an "@" character, e.g. filename "FL1_060306_2@A1.txt" will give "A1".

Parameters:
filename - String the filename to parse.
Returns:
String the plate position string.

convertWellNotation

public String convertWellNotation(String wellname)
Converts a well position to standard notation of type "A12", where the uppercase letter notates the column and the number the row. Accepts well positions notations of the following types, where 'A' or 'a' is a single upper- or lowercase letter describing the row, and "12" a number describing the column (no leading zero for numbers < 10): "A12", "a12", "A-12", "a-12", "A,12", "a,12", "12-A", "12-a", "12,A", "12,a".

Parameters:
wellname - String the well position notation to convert.
Returns:
String the well position string in notation type "A12".

convertToLocalWellNotation

public String convertToLocalWellNotation(String wellname,
                                         String prototypeName)
Converts a well position of standard notation of type "A12" to local notation. Accepts local prototype notations of the following types, where 'A' or 'a' is a single upper- or lowercase letter describing the row, and "12" a number describing the column (no leading zero for numbers < 10): "A12", "a12", "A-12", "a-12", "A,12", "a,12", "12-A", "12-a", "12,A", "12,a". As an example, wellname "A12" in standard notation and prototype name "6,c" will result in conversion of "A12" to "12,a".

Parameters:
wellname - String the well position standard notation to convert.
prototypeName - String An example (prototype) of the local notation.
Returns:
String the well position string in local notation type.

Last update: 2011-06-23