Package datastructure

Class Storage.Factory

java.lang.Object
datastructure.Storage.Factory
Enclosing class:
Storage

public static final class Storage.Factory extends Object
Factory class for creating and managing instances of Storage.

This class provides methods to load storage from command line interface (CLI) parameters, files, and to save storage to files. It also handles the initialization of transient properties and manages the loading of reference sequences, features, and sample information.

  • Constructor Details

    • Factory

      public Factory()
  • Method Details

    • fromCLI

      public static Storage fromCLI() throws MusialException, IOException
      Initializes a Storage from CLI parameters.

      This method initializes a new Storage instance using parameters from the command line interface (CLI). It also loads reference sequences, features, and sample information from the CLI parameters.

      Returns:
      A Storage object representing the loaded data.
      Throws:
      MusialException - If an error occurs while loading or validating the data.
      IOException - If an error occurs while reading files or parsing data.
    • fromFile

      public static Storage fromFile(File file) throws IOException
      Initializes a Storage from a file.

      This method loads the storage from a specified file in JSON format. It handles both compressed and uncompressed files. The method also initializes transient properties after loading.

      Parameters:
      file - The file to load the storage from.
      Returns:
      A Storage object representing the loaded data.
      Throws:
      IOException - If an error occurs while reading the file or parsing the JSON data.
    • toFile

      public static void toFile(Storage storage, File file) throws IOException
      Writes the given `Storage` object to a file in JSON format.

      This method ensures that the file has the correct extension (`.json` or `.json.gz` for GZIP-compressed files), converts the `Storage` object to a JSON string, and writes it to the specified file. If the file path ends with `.gz`, the JSON data is compressed using GZIP before writing.

      Parameters:
      storage - The `Storage` object to be serialized and written to the file.
      file - The `File` object representing the target file.
      Throws:
      IOException - If an error occurs during file operations, such as writing or compression.
    • setSampleInformation

      public static void setSampleInformation(Storage storage, File file) throws IOException
      Sets sample information in the storage from a specified file.

      This method reads a tabular file containing sample metadata and populates the `sampleInfo` map in the provided `Storage` instance. The file is expected to be in a format that can be parsed into a nested map structure, where the outer map keys represent sample names and the inner map contains attribute-value pairs for each sample.

      Parameters:
      storage - The Storage instance where the sample information will be stored.
      file - The File object representing the input file containing sample metadata.
      Throws:
      IOException - If an error occurs while reading or parsing the file.
    • setVcfFiles

      public static void setVcfFiles(Storage storage, List<String> paths) throws MusialException, IOException
      Sets the VCF files in the storage from a list of file paths.

      This method processes a list of file paths, adding valid VCF files or directories containing VCF files to the storage's `vcfFiles` list. It supports both uncompressed `.vcf` files and compressed `.vcf.gz` files. If no valid VCF files are found, an exception is thrown.

      Parameters:
      storage - The Storage instance where the VCF files will be stored.
      paths - A list of file paths to process. Each path can be a file or a directory.
      Throws:
      MusialException - If no valid VCF files are found in the provided paths.
      IOException - If an error occurs while accessing the file system.