public class MetaUtil extends Object
Modifier and Type | Field and Description |
---|---|
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"
|
static String |
META_COLUMN_DELIM
Config property: "metadata.columnDelim" |
static String |
META_COMMENT_CHAR
Config property: "metadata.commentChar" |
static String |
META_FILE_PATH
Config String property: "metadata.filePath" |
static String |
META_FILENAME_COLUMN
Config property "metadata.fileNameColumn" |
static String |
META_NULL_VALUE
Config property: "metadata.nullValue" |
static String |
META_REQUIRED
Config Boolean property: "metadata.required" |
protected static String |
METADATA_COL_DELIM
Default column delimiter = tab character
|
static String |
USE_EVERY_ROW
Config Boolean property: "metadata.useEveryRow" |
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()
Check if metadata file exists
|
static boolean |
fieldValuesAreUnique(String field,
boolean ignoreNulls)
Determine if the given field has only unique values.
|
static String |
getColumnDelim() |
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 |
getNullValue(BioModule module)
Nulls left as empty cells do not process corrects in R, so a placeholder value must be defined (even if not
used).
|
static String |
getPath()
Return the metadata file path
|
static List<String> |
getRecord(String sampleId)
Get metadata row for a given Sample ID.
|
static Set<String> |
getSampleFileList() |
static String |
getSampleId(File file) |
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 boolean |
hasMetaColToSampleIdMap() |
static void |
initialize()
Check required properties are defined and unique.
|
static void |
refreshCache()
Refresh the metadata cache.
|
static void |
registerProps() |
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.
|
static boolean |
setSampleId(File file,
String sampleId) |
static boolean |
setSampleId(String filename,
String sampleId) |
static void |
tapSampleAssignmentMap()
A care-free wrapper for saveSampleAssignmentMap().
|
public static final String META_BARCODE_COLUMN
Config
property "metadata.barcodeColumn"
public static final String META_COLUMN_DELIM
Config
property: "metadata.columnDelim"public static final String META_COMMENT_CHAR
Config
property: "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"public static final String META_NULL_VALUE
Config
property: "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 METADATA_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 MetadataException, IOException, DockerVolCreationException
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 arg will be removed from the metadataMetadataException
- if errors occur attemptingto get/put metadata into cacheIOException
- if errors occur attempting to read metadata fileDockerVolCreationException
FileNotFoundException
- if metadata file not foundpublic static boolean exists()
public static boolean fieldValuesAreUnique(String field, boolean ignoreNulls) throws MetadataException
field
- Metadata columnignoreNulls
- if TRUE ignore duplicate "metadata.nullValue" valuesMetadataException
- if field not found in metadata filepublic static String getColumnDelim()
public static String getField(String sampleId, String field) throws MetadataException
sampleId
- Sample IDfield
- Field Name (column name in metadata file)MetadataException
- if field not found in the metadata for the given sample Id.public static List<String> getFieldNames()
public static List<String> getFieldValues(String field, boolean ignoreNulls) throws MetadataException
field
- Column nameignoreNulls
- if TRUE ignore duplicate "metadata.nullValue" valuesMetadataException
- if unable to find metadata filed valuespublic static String getFileName()
public static String getForcedColumnName(String name) throws MetadataException, FileNotFoundException, IOException, DockerVolCreationException
Config
."metadata.nullValue" values, return the name of that empty column to overwrite.name
- Base column nameMetadataException
- if metadata file not found and cannot be assignedIOException
- If unable to modify the system fileFileNotFoundException
- if metadata file path not foundDockerVolCreationException
public static String getID()
public static String getLatestColumnName(String name)
name
- Base column namepublic static File getMetadata() throws MetadataException
MetadataException
- if attempt to assign new metadata file failspublic static String getNullValue(BioModule module)
Config
?"metadata.nullValue". If undefined, use
"NA"module
- BioModule calling MetaUtilpublic static String getPath()
public static List<String> getRecord(String sampleId) throws MetadataException
sampleId
- Sample IDMetadataException
- if Sample ID not found or metadata file doesn't existpublic static List<String> getSampleIds()
public static String getSystemMetaCol(BioModule module, String col) throws MetadataException, FileNotFoundException, IOException, DockerVolCreationException
module
- BioModulecol
- Column nameMetadataException
- if metadata file not found and cannot be assignedIOException
- If unable to modify the system fileFileNotFoundException
- if metadata file path not foundDockerVolCreationException
public static Set<String> getUniqueFieldValues(String field, boolean ignoreNulls) throws MetadataException
field
- Column headerignoreNulls
- if TRUE ignore duplicate "metadata.nullValue" valuesMetadataException
- if field not foundpublic static boolean hasColumn(String columnName)
columnName
- Column namepublic static void initialize() throws Exception
Exception
public static boolean hasMetaColToSampleIdMap() throws ConfigFormatException, ConfigViolationException, MetadataException
public static boolean setSampleId(String filename, String sampleId) throws ConfigViolationException, ConfigFormatException, MetadataException, IOException
filename
- sampleId
- ConfigViolationException
ConfigFormatException
MetadataException
- if methods attempts to assign an existing file name to a different sampleIOException
public static boolean setSampleId(File file, String sampleId) throws ConfigViolationException, ConfigFormatException, MetadataException, IOException
public static void refreshCache() throws MetadataException
MetadataException
- if unable to refresh cachepublic static void removeColumn(String colName, File fileDir) throws FileNotFoundException, IOException, MetadataException, DockerVolCreationException
colName
- Name of column to removefileDir
- File representing output directory for new metadata fileMetadataException
- if metadata file not found and cannot be assignedIOException
- If unable to modify the system fileFileNotFoundException
- if metadata file path not foundDockerVolCreationException
public static void setFile(File file) throws MetadataException, DockerVolCreationException
file
- New metadata fileMetadataException
- if null parameter is passedDockerVolCreationException
public static void tapSampleAssignmentMap()
public static void registerProps() throws API_Exception
API_Exception