/// <summary> /// Constructs sequence statistics by iterating through a list of sequences. /// </summary> /// <param name="sequences">The list of sequences to construct statistics for.</param> internal SequenceStatistics(IList <ISequence> sequences) { _alphabet = sequences[0].Alphabet; _countHash = new Dictionary <char, int>(); _totalCount = 0; foreach (ISequence seq in sequences) { SequenceStatistics seqStats = seq.Statistics; if (seqStats._alphabet != _alphabet) { throw new Exception("Cannot create statistics for list of sequences with different alphabets."); } foreach (char symbol in seqStats._countHash.Keys) { if (_countHash.ContainsKey(symbol)) { _countHash[symbol] += seqStats._countHash[symbol]; } else { _countHash.Add(symbol, seqStats._countHash[symbol]); } } _totalCount += seqStats._totalCount; } }
/// <summary> /// Creates a sparse sequence based on the specified parameters. /// /// The item parameter must contain an alphabet as specified in the alphabet parameter, /// else an exception will occur. /// /// The index parameter value must be a non negative value. /// Count property of an instance created by this constructor will be set to value of index + 1. /// </summary> /// <param name="alphabet"> /// The alphabet the sequence uses (e.g. Alphabets.DNA or Alphabets.RNA or Alphabets.Protein)</param> /// <param name="index">Position of the specified sequence item.</param> /// <param name="item">A sequence item which is known by the alphabet.</param> public SparseSequence(IAlphabet alphabet, int index, byte item) : this(alphabet) { if (alphabet == null) { throw new ArgumentNullException("alphabet"); } if (index < 0 || index == int.MaxValue) { throw new ArgumentOutOfRangeException( Properties.Resource.ParameterNameIndex, Properties.Resource.SparseSequenceConstructorIndexOutofRange); } if (!alphabet.ValidateSequence(new[] { item }, 0, 1)) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, Properties.Resource.InvalidSymbol, item)); } Statistics = new SequenceStatistics(alphabet); sparseSeqItems.Add(index, item); Statistics.Add((char)item); Count = index + 1; }
/// <summary> /// Copy constructor. /// </summary> /// <param name="that">The sequence statistics to copy from.</param> internal SequenceStatistics(SequenceStatistics that) { _alphabet = that._alphabet; _countHash = new Dictionary <char, int>(); foreach (char symbol in that._countHash.Keys) { _countHash.Add(symbol, that._countHash[symbol]); } _totalCount = that._totalCount; }
/// <summary> /// Creates a SparseSequence with no sequence data. /// /// Count property of SparseSequence instance created by using this constructor will be /// set a value specified by size parameter. /// /// For working with sequences that never have sequence data, but are /// only used for metadata storage (like keeping an ID or various features /// but no direct sequence data) consider using the VirtualSequence /// class instead. /// </summary> /// <param name="alphabet"> /// The alphabet the sequence uses (e.g.. Alphabets.DNA or Alphabets.RNA or Alphabets.Protein) /// </param> /// <param name="size">A value indicating the size of this sequence.</param> public SparseSequence(IAlphabet alphabet, int size) { if (alphabet == null) { throw new ArgumentNullException("alphabet"); } if (size < 0) { throw new ArgumentOutOfRangeException(Properties.Resource.ParameterNameSize, Properties.Resource.ParameterMustNonNegative); } Count = size; Alphabet = alphabet; Statistics = new SequenceStatistics(alphabet); }
/// <summary> /// Creates a sparse sequence based on the specified parameters. /// The sequenceItems parameter must contain sequence items known by the specified alphabet, /// else an exception will occur. /// /// The index parameter value must be a non negative. /// </summary> /// <param name="alphabet"> /// The alphabet the sequence uses (e.g.. Alphabets.DNA or Alphabets.RNA or Alphabets.Protein)</param> /// <param name="index">A non negative value which indicates the start position of the specified sequence items.</param> /// <param name="sequenceItems"> /// A sequence which contain items known by the alphabet.</param> public SparseSequence(IAlphabet alphabet, int index, IEnumerable <byte> sequenceItems) : this(alphabet) { if (alphabet == null) { throw new ArgumentNullException("alphabet"); } if (index < 0 || index == int.MaxValue) { throw new ArgumentOutOfRangeException( Properties.Resource.ParameterNameIndex, Properties.Resource.SparseSequenceConstructorIndexOutofRange); } if (sequenceItems == null) { throw new ArgumentNullException(Properties.Resource.ParameterNameSequenceItems); } var sequenceArray = sequenceItems.ToArray(); if (!alphabet.ValidateSequence(sequenceArray, 0, sequenceArray.LongLength)) { throw new ArgumentOutOfRangeException("sequenceItems"); } Statistics = new SequenceStatistics(alphabet); int position = index; foreach (byte sequenceItem in sequenceItems) { sparseSeqItems.Add(position, sequenceItem); Statistics.Add((char)sequenceItem); position++; } if (sequenceItems.Count() > 0) { Count = index + sequenceItems.Count(); } }
/// <summary> /// Creates a sparse sequence based on the specified parameters. /// The sequenceItems parameter must contain sequence items known by the specified alphabet, /// else an exception will occur. /// /// The index parameter value must be a non negative. /// </summary> /// <param name="alphabet"> /// The alphabet the sequence uses (e.g.. Alphabets.DNA or Alphabets.RNA or Alphabets.Protein)</param> /// <param name="index">A non negative value which indicates the start position of the specified sequence items.</param> /// <param name="sequenceItems"> /// A sequence which contain items known by the alphabet.</param> public SparseSequence(IAlphabet alphabet, int index, IEnumerable<byte> sequenceItems) : this(alphabet) { if (alphabet == null) { throw new ArgumentNullException("alphabet"); } if (index < 0 || index == int.MaxValue) { throw new ArgumentOutOfRangeException( Properties.Resource.ParameterNameIndex, Properties.Resource.SparseSequenceConstructorIndexOutofRange); } if (sequenceItems == null) { throw new ArgumentNullException(Properties.Resource.ParameterNameSequenceItems); } var sequenceArray = sequenceItems.ToArray(); if (!alphabet.ValidateSequence(sequenceArray, 0, sequenceArray.GetLongLength())) { throw new ArgumentOutOfRangeException("sequenceItems"); } Statistics = new SequenceStatistics(alphabet); int position = index; foreach (byte sequenceItem in sequenceArray) { sparseSeqItems.Add(position, sequenceItem); Statistics.Add((char)sequenceItem); position++; } if (sequenceArray.Any()) { Count = index + sequenceArray.Length; } }