Package op

Class NucleotideSequenceGenerator

java.lang.Object
op.NucleotideSequenceGenerator
All Implemented Interfaces:
SequenceGenerator
Direct Known Subclasses:
AminoacidSequenceGenerator

public class NucleotideSequenceGenerator extends Object implements SequenceGenerator
The NucleotideSequenceGenerator class is responsible for generating nucleotide sequences based on genomic data contained in a Storage instance.

This class is initialized with a fixed Contig and optionally a Feature. It can be restricted to specific sample identifiers and automatically handles the option specified by Storage.Parameters.maskFiltered.

  • Constructor Details

    • NucleotideSequenceGenerator

      public NucleotideSequenceGenerator(Storage storage, Contig contig, boolean conserved, boolean aligned, Set<String> sampleIdentifiers) throws IOException, MusialException
      Constructs a new instance of the NucleotideSequenceGenerator class.

      This constructor initializes the generator for a given contig and optional sample identifiers. It sets the interval to cover the entire contig and determines whether the sequence generation should include conserved sites and/or align sequences.

      If sample identifiers are provided, the sequence generation will be restricted to those samples.

      The constructor validates the contig to ensure it exists in the storage and meets the requirements for conserved sequence generation, if applicable.

      Parameters:
      storage - The storage object containing genomic data.
      contig - The contig associated with the sequence generation.
      conserved - A flag indicating whether the sequence generation includes conserved sites.
      aligned - A flag indicating whether the generated sequences are aligned.
      sampleIdentifiers - Optional sample identifiers to restrict the sequence generation.
      Throws:
      IOException - If an error occurs during sequence retrieval.
      MusialException - If an error occurs during context generation.
    • NucleotideSequenceGenerator

      public NucleotideSequenceGenerator(Storage storage, Contig contig, int from, int to, boolean conserved, boolean aligned, Set<String> sampleIdentifiers) throws IOException, MusialException
      Constructs a new instance of the NucleotideSequenceGenerator class with a specified interval.

      This constructor initializes the generator for a given contig and interval, along with optional sample identifiers. It sets the interval to the specified range and determines whether the sequence generation should include conserved sites and/or align sequences.

      If sample identifiers are provided, the sequence generation will be restricted to those samples.

      The constructor validates the contig to ensure it exists in the storage and meets the requirements for conserved sequence generation, if applicable.

      Parameters:
      storage - The storage object containing genomic data.
      contig - The contig associated with the sequence generation.
      from - The start position of the interval for sequence generation.
      to - The end position of the interval for sequence generation.
      conserved - A flag indicating whether the sequence generation includes conserved sites.
      aligned - A flag indicating whether the generated sequences are aligned.
      sampleIdentifiers - Optional sample identifiers to restrict the sequence generation.
      Throws:
      IOException - If an error occurs during sequence retrieval.
      MusialException - If an error occurs during context generation.
    • NucleotideSequenceGenerator

      public NucleotideSequenceGenerator(Storage storage, Contig contig, Feature feature, boolean conserved, boolean aligned, Set<String> sampleIdentifiers) throws IOException, MusialException
      Constructs a new instance of the NucleotideSequenceGenerator class with a specified feature.

      This constructor initializes the generator for a given contig and feature, along with optional sample identifiers. It sets the interval to the range defined by the feature and determines whether the sequence generation should include conserved sites and/or align sequences.

      If sample identifiers are provided, the sequence generation will be restricted to those samples.

      The constructor validates the contig and feature to ensure they exist in the storage and meet the requirements for conserved sequence generation, if applicable.

      Parameters:
      storage - The storage object containing genomic data.
      contig - The contig associated with the sequence generation.
      feature - The feature associated with the sequence generation.
      conserved - A flag indicating whether the sequence generation includes conserved sites.
      aligned - A flag indicating whether the generated sequences are aligned.
      sampleIdentifiers - Optional sample identifiers to restrict the sequence generation.
      Throws:
      IOException - If an error occurs during sequence retrieval.
      MusialException - If an error occurs during context generation or feature validation.
  • Method Details

    • getName

      public String getName(boolean forFile)
      Retrieves the name of the sequence generator.

      The name is derived from the associated feature name or contig ID, depending on the context in which the sequence generator was initialized.

      Specified by:
      getName in interface SequenceGenerator
      Parameters:
      forFile - true to return a file-friendly name, false for the standard name.
      Returns:
      A String representing the name of the sequence generator.
    • getSequence

      public String getSequence(String sampleIdentifier) throws MusialException
      Retrieves the nucleotide sequence for a given sample identifier.

      This method determines whether the sequence should be generated based on a feature or a contig. If a feature is defined, the sequence is generated using the `fromFeature` method. Otherwise, the sequence is generated using the `fromContig` method.

      Specified by:
      getSequence in interface SequenceGenerator
      Parameters:
      sampleIdentifier - The identifier of the sample for which the sequence is generated.
      Returns:
      A String representing the nucleotide sequence for the given sample.
      Throws:
      MusialException - If an error occurs during sequence generation