public class MetaUtil extends Object
Modifier and Type | Field and Description |
---|---|
protected static String |
DEFAULT_COL_DELIM
Default column delimiter = tab character
|
protected static String |
DEFAULT_COMMENT_CHAR
Default comment character for any new metadata file created by a BioModule: ""
|
protected static String |
DEFAULT_NULL_VALUE
Default field value to represent null-value: "NA"
|
static String |
META_BARCODE_COLUMN
Config property "metadata.barcodeColumn" defines metadata column with identifying barcode |
static String |
META_COLUMN_DELIM
Config property that defines how metadata columns are separated: "metadata.columnDelim"
Typically files are tab or comma separated. |
static String |
META_COMMENT_CHAR
Config property to set metadata file comment indicator: "metadata.commentChar"Empty string is a valid option indicating no comments in metadata file |
static String |
META_FILE_PATH
Config String property: "metadata.filePath"If absolute file path, use file as metadata. If directory path, must find exactly 1 file within, to use as metadata. |
static String |
META_FILENAME_COLUMN
Config property "metadata.fileNameColumn" defines metadata column with input file names |
static String |
META_NULL_VALUE
Config property to set metadata file empty cell: "metadata.nullValue" |
static String |
META_REQUIRED
Config Boolean property: "metadata.required"If Y, require metadata row for each sample with sequence data in "input.dirPaths". If N, samples without metadata are ignored. |
static String |
USE_EVERY_ROW
Config Boolean property: "metadata.useEveryRow"If Y, require a sequence file for every SampleID (every row) in "metadata.filePath". If N, metadata can include extraneous SampleIDs. |
Modifier and Type | Method and Description |
---|---|
static void |
addColumn(String colName,
Map<String,String> map,
File fileDir,
boolean removeMissingIds)
Adds a column to the metadata file.
|
static boolean |
exists()
Determine if metadata file exists
|
static boolean |
fieldValuesAreUnique(String field,
boolean ignoreNulls)
Determine if the given field has only unique values.
|
static String |
getField(String sampleId,
String field)
Get metadata field value for given sampleId.
|
static List<String> |
getFieldNames()
Get a list of all metadata fields (metadata file column names except the 1st).
|
static List<String> |
getFieldValues(String field,
boolean ignoreNulls)
Get metadata column for given field name.
|
static String |
getFileName()
Get the metadata file name, if it exists, otherwise return projectName.tsv
|
static String |
getForcedColumnName(String name)
Used to generate a guaranteed to be unique column name.
|
static String |
getID()
Get the metadata file ID column name.
|
static String |
getLatestColumnName(String name)
Returns the latest version of the given column.
|
static File |
getMetadata()
Metadata file getter.
|
static String |
getPath()
Return the metadata file path
|
static List<String> |
getRecord(String sampleId)
Get metadata row for a given Sample ID.
|
static List<String> |
getSampleIds()
Get the first column from the metadata file.
|
static String |
getSystemMetaCol(BioModule module,
String col)
Return a system generated metadata column name based on the module status.
|
static Set<String> |
getUniqueFieldValues(String field,
boolean ignoreNulls)
Count the number of unique values in the given field.
|
static boolean |
hasColumn(String columnName)
Check if columnName exists in the current metadata file.
|
static void |
initialize()
Check dependencies used to handle the metadata file are defined and unique.
|
static void |
refreshCache()
Refresh the metadata cache.
|
static void |
removeColumn(String colName,
File fileDir)
Remove the metadata column from the metadata file
|
static void |
setFile(File file)
Set a new metadata file.
|
public static final String META_BARCODE_COLUMN
Config
property "metadata.barcodeColumn" defines metadata column with identifying barcodepublic static final String META_COLUMN_DELIM
Config
property that defines how metadata columns are separated: "metadata.columnDelim"
Typically files are tab or comma separated.public static final String META_COMMENT_CHAR
Config
property to set metadata file comment indicator: "metadata.commentChar"public static final String META_FILE_PATH
Config
String property: "metadata.filePath"public static final String META_FILENAME_COLUMN
Config
property "metadata.fileNameColumn" defines metadata column with input file namespublic static final String META_NULL_VALUE
Config
property to set metadata file empty cell: "metadata.nullValue"public static final String META_REQUIRED
Config
Boolean property: "metadata.required"public static final String USE_EVERY_ROW
Config
Boolean property: "metadata.useEveryRow"protected static final String DEFAULT_COL_DELIM
protected static final String DEFAULT_COMMENT_CHAR
protected static final String DEFAULT_NULL_VALUE
public static void addColumn(String colName, Map<String,String> map, File fileDir, boolean removeMissingIds) throws Exception
colName
- Name of new columnmap
- Map relates Sample ID to a field valuefileDir
- File representing output directory for new metadata fileremoveMissingIds
- if TRUE, sampleIds not include in the map param will be removed from the metadataException
- if unable to add the new columnpublic static boolean exists() throws Exception
Exception
- if error occurs trying to read metadata filepublic static boolean fieldValuesAreUnique(String field, boolean ignoreNulls) throws Exception
field
- Metadata columnignoreNulls
- if TRUE ignore duplicate "metadata.nullValue" valuesException
- if runtime errors occurpublic static String getField(String sampleId, String field) throws Exception
sampleId
- Sample IDfield
- Field Name (column name in metadata file)Exception
- if parameters are invalidpublic static List<String> getFieldNames() throws Exception
Exception
- if unable to read metadata filepublic static List<String> getFieldValues(String field, boolean ignoreNulls) throws Exception
field
- Column nameignoreNulls
- if TRUE ignore duplicate "metadata.nullValue" valuesException
- if metadata file or column name not foundpublic static String getFileName()
public static String getForcedColumnName(String name) throws Exception
Config
."metadata.nullValue" values, return the name of that empty column to overwrite.name
- Base column nameException
- if errors occurpublic static String getID()
public static String getLatestColumnName(String name) throws Exception
name
- Base column nameException
- if errors occurpublic static File getMetadata() throws Exception
Exception
- if any errors occurpublic static String getPath()
public static List<String> getRecord(String sampleId) throws Exception
sampleId
- Sample IDException
- if Sample ID not found or metadata file doesn't existpublic static List<String> getSampleIds()
public static String getSystemMetaCol(BioModule module, String col) throws Exception
module
- BioModulecol
- Column nameException
- if errors occurpublic static Set<String> getUniqueFieldValues(String field, boolean ignoreNulls) throws Exception
field
- Column headerignoreNulls
- if TRUE ignore duplicate "metadata.nullValue" valuesException
- if errors occurpublic static boolean hasColumn(String columnName)
columnName
- Column namepublic static void initialize() throws Exception
Exception
- if invalid Config properties are detectedpublic static void refreshCache() throws Exception
Exception
- if unable to refresh cachepublic static void removeColumn(String colName, File fileDir) throws Exception
colName
- Name of column to removefileDir
- File representing output directory for new metadata fileException
- if errors occur