/// <summary>
        ///     Validate aligned sequence instance using different aligners
        /// </summary>
        /// <param name="nodeName">xml node name</param>
        /// <param name="aligner">sw/nw/pw aligners</param>
        private void ValidateAlignedSequence(string nodeName, ISequenceAligner aligner)
        {
            IAlphabet alphabet = Utility.GetAlphabet(this.utilityObj.xmlUtil.GetTextValue(nodeName,
                                                                                          Constants.AlphabetNameNode));
            string origSequence1 = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceNode1);
            string origSequence2 = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceNode2);

            // Create input sequences
            var inputSequences = new List <ISequence>();

            inputSequences.Add(new Sequence(alphabet, origSequence1));
            inputSequences.Add(new Sequence(alphabet, origSequence2));

            // Get aligned sequences
            IList <ISequenceAlignment> alignment = aligner.Align(inputSequences);

            // Create AlignedSequence instance
            IAlignedSequence sequence = alignment[0].AlignedSequences[0];

            // Validate the alignedsequence properties
            Assert.AreEqual(alignment[0].AlignedSequences[0].Sequences, sequence.Sequences);
            Assert.AreEqual(alignment[0].AlignedSequences[0].Metadata, sequence.Metadata);

            ApplicationLog.WriteLine(@"Alignment BVT : Validation of aligned sequence completed successfully");
        }
Exemple #2
0
        /// <summary>
        /// Clear the view
        /// </summary>
        public void Clear()
        {
            this.sequences       = null;
            this.alignedSequence = null;
            this.contig          = null;

            this.Children.Clear();
        }
Exemple #3
0
        /// <summary>
        /// Set dource data for the panel
        /// This will trigger a redraw of this panel
        /// </summary>
        /// <param name="sourceList">Alignment to plot</param>
        /// <param name="maximumWidthInChars">Maximum span of the sequences</param>
        public void SetDataSource(IAlignedSequence alignedSequence, int maximumWidthInChars)
        {
            this.sequences       = null;
            this.contig          = null;
            this.contigSequences = null;
            this.alignedSequence = alignedSequence;
            this.maxLength       = maximumWidthInChars;

            InvalidateMeasure();
        }
Exemple #4
0
        /// <summary>
        /// Set dource data for the panel
        /// This will trigger a redraw of this panel
        /// </summary>
        /// <param name="sourceList">List of seuqences to plot</param>
        /// <param name="maximumWidthInChars">Maximum span of the sequences</param>
        public void SetDataSource(IList <ISequence> sourceList, int maximumWidthInChars)
        {
            this.contig          = null;
            this.alignedSequence = null;
            this.contigSequences = null;
            this.sequences       = sourceList;
            this.maxLength       = maximumWidthInChars;

            InvalidateMeasure();
        }
Exemple #5
0
        /// <summary>
        /// Set dource data for the panel
        /// This will trigger a redraw of this panel
        /// </summary>
        /// <param name="sourceList">Contig to plot</param>
        /// <param name="maximumWidthInChars">Maximum span of the sequences</param>
        /// <param name="basePaddingLeft">Padding to be added to left of all sequences</param>
        public void SetDataSource(Contig contig, int maximumWidthInChars, int basePaddingLeft)
        {
            this.sequences       = null;
            this.alignedSequence = null;
            this.contig          = contig;
            this.basePaddingLeft = basePaddingLeft;
            this.maxLength       = maximumWidthInChars;
            contigSequences      = contig.Sequences.OrderBy(s => s.Position);

            InvalidateMeasure();
        }
Exemple #6
0
        /// <summary>
        /// Used to set datasource if the control is to display the output of an assembly.
        /// </summary>
        /// <param name="alignment">Contig retrieved after doing the assembly.</param>
        public void SetDataSource(IAlignedSequence alignment)
        {
            this.referenceSequence      = null;
            this.sequenceList           = new List <ISequence>();
            this.sequencePropertiesList = new List <SequenceProperties>();
            List <int> startOffsets = null;
            List <int> endOffsets   = null;

            if (alignment.Metadata.ContainsKey(StartOffsetString))
            {
                startOffsets = alignment.Metadata[StartOffsetString] as List <int>;
            }

            if (alignment.Metadata.ContainsKey(EndOffsetString))
            {
                endOffsets = alignment.Metadata[EndOffsetString] as List <int>;
            }

            if (startOffsets == null || startOffsets.Count != alignment.Sequences.Count) // remove offset info if the counts are not matching
            {
                startOffsets = null;
                endOffsets   = null;
                this.sequencePropertiesList = null;
            }

            for (int i = 0; i < alignment.Sequences.Count; i++)
            {
                ISequence currentSeq = alignment.Sequences[i];
                sequenceList.Add(currentSeq);

                if (startOffsets != null && endOffsets != null)
                {
                    sequencePropertiesList.Add(new SequenceProperties
                    {
                        AlignPosition          = startOffsets[i],
                        ReadStartAlignPosition = 0,
                        AlignmentLength        = startOffsets[i] + currentSeq.Count,
                        IsComplemented         = false,
                        IsReversed             = false,
                        IsAlignment            = true
                    });
                }
            }

            DataSourceUpdated();
        }
Exemple #7
0
        public void ValidateReadOnlyAlignedSeqCopyTo()
        {
            ReadOnlyAlignedSequenceCollection readOnlyAlignedSeq =
                GetReadOnlyAlignedSequence(Constants.SAMFileWithAllFieldsNode);

            IAlignedSequence[] IAlignedSeqArray = new
                                                  IAlignedSequence[readOnlyAlignedSeq.Count];

            readOnlyAlignedSeq.CopyTo(IAlignedSeqArray, 0);

            for (int index = 0; index < readOnlyAlignedSeq.Count; index++)
            {
                Assert.AreEqual(IAlignedSeqArray[index].Sequences[0].ToString(),
                                readOnlyAlignedSeq[index].Sequences[0].ToString());
            }

            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "ReadOnlyAlignedSeqCollection Bvt : Validated the ReadOnlyAlignedSeq CopyTo"));
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            "ReadOnlyAlignedSeqCollection Bvt : Validated the ReadOnlyAlignedSeq CopyTo"));
        }
Exemple #8
0
        /// <summary>
        /// Writes SAMAlignedSequence to specified text writer.
        /// </summary>
        /// <param name="alignedSequence">SAM aligned sequence to write</param>
        /// <param name="writer">Text writer.</param>
        public static void WriteSAMAlignedSequence(IAlignedSequence alignedSequence, TextWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            if (alignedSequence == null)
            {
                throw new ArgumentNullException("alignedSequence");
            }

            SAMAlignedSequenceHeader alignedHeader = alignedSequence.Metadata[Helper.SAMAlignedSequenceHeaderKey] as SAMAlignedSequenceHeader;

            if (alignedHeader == null)
            {
                throw new ArgumentException(Resource.SAM_AlignedSequenceHeaderMissing);
            }

            ISequence sequence = alignedSequence.Sequences[0];

            if (sequence.Alphabet != Alphabets.DNA)
            {
                throw new ArgumentException(Resource.SAMFormatterSupportsDNAOnly);
            }


            List <int> dotSymbolIndices   = new List <int>(alignedHeader.DotSymbolIndices);
            List <int> equalSymbolIndices = new List <int>(alignedHeader.EqualSymbolIndices);
            string     seq = "*";

            if (sequence.Count > 0)
            {
                char[] symbols = new char[sequence.Count];
                for (int i = 0; i < sequence.Count; i++)
                {
                    char symbol = sequence[i].Symbol;

                    if (dotSymbolIndices.Count > 0)
                    {
                        if (dotSymbolIndices.Contains(i))
                        {
                            symbol = '.';
                            dotSymbolIndices.Remove(i);
                        }
                    }

                    if (equalSymbolIndices.Count > 0)
                    {
                        if (equalSymbolIndices.Contains(i))
                        {
                            symbol = '=';
                            equalSymbolIndices.Remove(i);
                        }
                    }

                    symbols[i] = symbol;
                }

                seq = new string(symbols);
            }

            string qualValues = "*";

            QualitativeSequence qualSeq = sequence as QualitativeSequence;

            if (qualSeq != null)
            {
                byte[] bytes = qualSeq.Scores;
                qualValues = System.Text.ASCIIEncoding.ASCII.GetString(bytes);
            }


            writer.Write(AlignedSequenceFormat,
                         alignedHeader.QName, (int)alignedHeader.Flag, alignedHeader.RName,
                         alignedHeader.Pos, alignedHeader.MapQ, alignedHeader.CIGAR,
                         alignedHeader.MRNM.Equals(alignedHeader.RName) ? "=" : alignedHeader.MRNM,
                         alignedHeader.MPos, alignedHeader.ISize, seq, qualValues);

            for (int j = 0; j < alignedHeader.OptionalFields.Count; j++)
            {
                writer.Write(OptionalFieldFormat, alignedHeader.OptionalFields[j].Tag,
                             alignedHeader.OptionalFields[j].VType, alignedHeader.OptionalFields[j].Value);
            }

            writer.WriteLine();
        }
 /// <summary>
 /// Initializes a new instance of the AlignedSequence class
 /// Internal constructor to create AlignedSequence instance from IAlignedSequence.
 /// </summary>
 /// <param name="alignedSequence">IAlignedSequence instance.</param>
 internal AlignedSequence(IAlignedSequence alignedSequence)
 {
     this.Metadata  = alignedSequence.Metadata;
     this.Sequences = new List <ISequence>(alignedSequence.Sequences);
 }
        /// <summary>
        /// Writes SAMAlignedSequence to specified text writer.
        /// </summary>
        /// <param name="alignedSequence">SAM aligned sequence to write</param>
        /// <param name="writer">Text writer.</param>
        public static void WriteSAMAlignedSequence(IAlignedSequence alignedSequence, TextWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            if (alignedSequence == null)
            {
                throw new ArgumentNullException("alignedSequence");
            }

            SAMAlignedSequenceHeader alignedHeader = alignedSequence.Metadata[Helper.SAMAlignedSequenceHeaderKey] as SAMAlignedSequenceHeader;

            if (alignedHeader == null)
            {
                throw new ArgumentException(Properties.Resource.SAM_AlignedSequenceHeaderMissing);
            }

            ISequence sequence = alignedSequence.Sequences[0];

            if (!(sequence.Alphabet is DnaAlphabet))
            {
                throw new ArgumentException(Properties.Resource.SAMFormatterSupportsDNAOnly);
            }

            string seq = "*";

            if (sequence.Count > 0)
            {
                char[] symbols = new char[sequence.Count];
                for (int i = 0; i < sequence.Count; i++)
                {
                    symbols[i] = (char)sequence[i];
                }

                seq = new string(symbols);
            }

            string qualValues = "*";

            QualitativeSequence qualSeq = sequence as QualitativeSequence;

            if (qualSeq != null)
            {
                byte[] bytes = qualSeq.GetEncodedQualityScores();

                // if FormatType is not sanger then convert the quality scores to sanger.
                if (qualSeq.FormatType != FastQFormatType.Sanger)
                {
                    bytes = QualitativeSequence.ConvertEncodedQualityScore(qualSeq.FormatType, FastQFormatType.Sanger, bytes);
                }

                qualValues = System.Text.ASCIIEncoding.ASCII.GetString(bytes);
            }

            writer.Write(AlignedSequenceFormat,
                         alignedHeader.QName, (int)alignedHeader.Flag, alignedHeader.RName,
                         alignedHeader.Pos, alignedHeader.MapQ, alignedHeader.CIGAR,
                         alignedHeader.MRNM.Equals(alignedHeader.RName) ? "=" : alignedHeader.MRNM,
                         alignedHeader.MPos, alignedHeader.ISize, seq, qualValues);

            foreach (var j in alignedHeader.OptionalFields)
            {
                writer.Write(OptionalFieldFormat, j.Tag,
                             j.VType, j.Value);
            }

            writer.WriteLine();
        }
 /// <summary>
 /// Initializes a new instance of the PairwiseAlignedSequence class
 /// Internal constructor for creating new instance of
 /// PairwiseAlignedSequence from specified IAlignedSequence.
 /// </summary>
 /// <param name="alignedSequence">IAlignedSequence instance.</param>
 internal PairwiseAlignedSequence(IAlignedSequence alignedSequence)
     : base(alignedSequence)
 {
     // Impl.
 }
Exemple #12
0
 /// <summary>
 /// Initializes a new instance of the AlignedSequence class
 /// Internal constructor to create AlignedSequence instance from IAlignedSequence.
 /// </summary>
 /// <param name="alignedSequence">IAlignedSequence instance.</param>
 internal AlignedSequence(IAlignedSequence alignedSequence)
 {
     this.Metadata = alignedSequence.Metadata;
     this.Sequences = new List<ISequence>(alignedSequence.Sequences);
 }
 /// <summary>
 /// Получить значение весовой функции выровненных последовательностей.
 /// </summary>
 public static long GetScore(this IAlignedSequence alignedSequence)
 {
     return(alignedSequence.Metadata.TryGetValue("Score", out var score)
                         ? (long)score
                         : long.MinValue);
 }
Exemple #14
0
        /// <summary>
        /// Writes SAMAlignedSequence to specified text writer.
        /// </summary>
        /// <param name="writer">Text writer.</param>
        /// <param name="alignedSequence">SAM aligned sequence to write</param>
        public static void WriteSAMAlignedSequence(TextWriter writer, IAlignedSequence alignedSequence)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            if (alignedSequence == null)
            {
                throw new ArgumentNullException("alignedSequence");
            }

            SAMAlignedSequenceHeader alignedHeader = alignedSequence.Metadata[Helper.SAMAlignedSequenceHeaderKey] as SAMAlignedSequenceHeader;
            if (alignedHeader == null)
            {
                throw new ArgumentException(Properties.Resource.SAM_AlignedSequenceHeaderMissing);
            }

            ISequence sequence = alignedSequence.Sequences[0];
            if (!(sequence.Alphabet is DnaAlphabet))
            {
                throw new ArgumentException(Properties.Resource.SAMFormatterSupportsDNAOnly);
            }

            string seq = "*";
            if (sequence.Count > 0)
            {
                char[] symbols = new char[sequence.Count];
                for (int i = 0; i < sequence.Count; i++)
                {
                   symbols[i]  = (char)sequence[i];
                }

                seq = new string(symbols);
            }
         
            string qualValues = "*";

            QualitativeSequence qualSeq = sequence as QualitativeSequence;
            if (qualSeq != null)
            {
                byte[] bytes = qualSeq.GetEncodedQualityScores();

                // if FormatType is not sanger then convert the quality scores to sanger.
                if (qualSeq.FormatType != FastQFormatType.Sanger)
                {
                    bytes = QualitativeSequence.ConvertEncodedQualityScore(qualSeq.FormatType, FastQFormatType.Sanger, bytes);
                }

                qualValues = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
            }
          
            writer.Write(AlignedSequenceFormat,
                alignedHeader.QName, (int)alignedHeader.Flag, alignedHeader.RName,
                alignedHeader.Pos, alignedHeader.MapQ, alignedHeader.CIGAR,
                alignedHeader.MRNM.Equals(alignedHeader.RName) ? "=" : alignedHeader.MRNM,
                alignedHeader.MPos, alignedHeader.ISize, seq, qualValues);

            foreach (SAMOptionalField t in alignedHeader.OptionalFields)
            {
                writer.Write(OptionalFieldFormat, t.Tag,
                    t.VType, t.Value);
            }

            writer.WriteLine();
        }
 /// <summary>
 /// Initializes a new instance of the PairwiseAlignedSequence class
 /// Internal constructor for creating new instance of 
 /// PairwiseAlignedSequence from specified IAlignedSequence.
 /// </summary>
 /// <param name="alignedSequence">IAlignedSequence instance.</param>
 internal PairwiseAlignedSequence(IAlignedSequence alignedSequence)
     : base(alignedSequence)
 {
     // Impl.
 }