use of org.broadinstitute.hellbender.tools.exome.CreateAllelicPanelOfNormals in project gatk-protected by broadinstitute.
the class AllelicPanelOfNormals method read.
/**
* Reads an allelic panel of normals from an HDF5 or tab-separated file (file type is automatically detected).
* Tab-separated files should have global hyperparameter values alpha and beta specified by comment lines
* denoted by {@code GLOBAL_ALPHA_COMMENT_STRING} and {@code GLOBAL_BETA_COMMENT_STRING}:
* <p>
* #GLOBAL_ALPHA=...<br>
* #GLOBAL_BETA=...
* </p>
* followed by lines specifying hyperparameter values at each site,
* with column headers as in {@link AllelicPanelOfNormalsTableColumn}:
* <p>
* CONTIG \t POSITION \t ALPHA \t BETA
* </p>
*
* Note that we opt for a static read method as opposed to a constructor that takes a file parameter because
* the former allows us to return the static {@code EMPTY_PON} if the allelic panel of normals is not present in
* an HDF5 file.
* @param inputFile HDF5 file containing a coverage panel of normals created by {@link CreatePanelOfNormals}
* and an allelic panel of normals created and set by {@link CreateAllelicPanelOfNormals}
* ({@code EMPTY_PON} is returned if the latter was never set), or a
* tab-separated file that contains global hyperparameters in comment lines and lines specifying hyperparameter values at each site
*/
public static AllelicPanelOfNormals read(final File inputFile) {
IOUtils.canReadFile(inputFile);
if (isHDF5File(inputFile)) {
//construct from HDF5 file
try (final HDF5File hdf5File = new HDF5File(inputFile)) {
final AllelicPanelOfNormals allelicPoN = HDF5AllelicPoNUtils.read(hdf5File);
logger.info(String.format("Loaded allelic panel of normals from HDF5 file: %s.", inputFile));
return allelicPoN;
}
} else {
//construct from TSV file
try (final AllelicPanelOfNormalsReader reader = new AllelicPanelOfNormalsReader(inputFile)) {
//parse comment lines for global hyperparameter values
final AllelicPanelOfNormals.HyperparameterValues globalHyperparameterValues = parseGlobalHyperparameterValues(inputFile);
//parse data lines for local hyperparameter values
final Map<SimpleInterval, HyperparameterValues> siteToHyperparameterValuesMap = new HashMap<>();
reader.stream().forEach(s -> siteToHyperparameterValuesMap.put(s.getKey(), s.getValue()));
final AllelicPanelOfNormals allelicPoN = new AllelicPanelOfNormals(globalHyperparameterValues, siteToHyperparameterValuesMap);
logger.info(String.format("Loaded allelic panel of normals from TSV file: %s.", inputFile));
return allelicPoN;
} catch (final IOException | UncheckedIOException ex) {
throw new UserException.CouldNotReadInputFile(inputFile, ex);
}
}
}
use of org.broadinstitute.hellbender.tools.exome.CreateAllelicPanelOfNormals in project gatk by broadinstitute.
the class AllelicPanelOfNormals method read.
/**
* Reads an allelic panel of normals from an HDF5 or tab-separated file (file type is automatically detected).
* Tab-separated files should have global hyperparameter values alpha and beta specified by comment lines
* denoted by {@code GLOBAL_ALPHA_COMMENT_STRING} and {@code GLOBAL_BETA_COMMENT_STRING}:
* <p>
* #GLOBAL_ALPHA=...<br>
* #GLOBAL_BETA=...
* </p>
* followed by lines specifying hyperparameter values at each site,
* with column headers as in {@link AllelicPanelOfNormalsTableColumn}:
* <p>
* CONTIG \t POSITION \t ALPHA \t BETA
* </p>
*
* Note that we opt for a static read method as opposed to a constructor that takes a file parameter because
* the former allows us to return the static {@code EMPTY_PON} if the allelic panel of normals is not present in
* an HDF5 file.
* @param inputFile HDF5 file containing a coverage panel of normals created by {@link CreatePanelOfNormals}
* and an allelic panel of normals created and set by {@link CreateAllelicPanelOfNormals}
* ({@code EMPTY_PON} is returned if the latter was never set), or a
* tab-separated file that contains global hyperparameters in comment lines and lines specifying hyperparameter values at each site
*/
public static AllelicPanelOfNormals read(final File inputFile) {
IOUtils.canReadFile(inputFile);
if (isHDF5File(inputFile)) {
//construct from HDF5 file
try (final HDF5File hdf5File = new HDF5File(inputFile)) {
final AllelicPanelOfNormals allelicPoN = HDF5AllelicPoNUtils.read(hdf5File);
logger.info(String.format("Loaded allelic panel of normals from HDF5 file: %s.", inputFile));
return allelicPoN;
}
} else {
//construct from TSV file
try (final AllelicPanelOfNormalsReader reader = new AllelicPanelOfNormalsReader(inputFile)) {
//parse comment lines for global hyperparameter values
final AllelicPanelOfNormals.HyperparameterValues globalHyperparameterValues = parseGlobalHyperparameterValues(inputFile);
//parse data lines for local hyperparameter values
final Map<SimpleInterval, HyperparameterValues> siteToHyperparameterValuesMap = new HashMap<>();
reader.stream().forEach(s -> siteToHyperparameterValuesMap.put(s.getKey(), s.getValue()));
final AllelicPanelOfNormals allelicPoN = new AllelicPanelOfNormals(globalHyperparameterValues, siteToHyperparameterValuesMap);
logger.info(String.format("Loaded allelic panel of normals from TSV file: %s.", inputFile));
return allelicPoN;
} catch (final IOException | UncheckedIOException ex) {
throw new UserException.CouldNotReadInputFile(inputFile, ex);
}
}
}
Aggregations