Beispiel #1
0
        // parses sequence.
        private void ParseSequences(SequenceAlignmentMap seqAlignment, BioTextReader bioReader, bool isReadOnly)
        {
            while (bioReader.HasLines && !bioReader.Line.StartsWith(@"@", StringComparison.OrdinalIgnoreCase))
            {
                string[]           tokens     = bioReader.Line.Split(tabDelim, StringSplitOptions.RemoveEmptyEntries);
                SAMAlignedSequence alignedSeq = new SAMAlignedSequence();

                alignedSeq.QName = tokens[0];
                alignedSeq.Flag  = SAMAlignedSequenceHeader.GetFlag(tokens[1]);
                alignedSeq.RName = tokens[2];
                alignedSeq.Pos   = int.Parse(tokens[3], CultureInfo.InvariantCulture);
                alignedSeq.MapQ  = int.Parse(tokens[4], CultureInfo.InvariantCulture);
                alignedSeq.CIGAR = tokens[5];
                alignedSeq.MRNM  = tokens[6].Equals("=") ? alignedSeq.RName : tokens[6];
                alignedSeq.MPos  = int.Parse(tokens[7], CultureInfo.InvariantCulture);
                alignedSeq.ISize = int.Parse(tokens[8], CultureInfo.InvariantCulture);
                string message = alignedSeq.IsValidHeader();

                if (!string.IsNullOrEmpty(message))
                {
                    throw new FormatException(message);
                }

                ISequence refSeq = null;

                if (RefSequences != null && RefSequences.Count > 0)
                {
                    refSeq = RefSequences.FirstOrDefault(R => string.Compare(R.ID, alignedSeq.RName, StringComparison.OrdinalIgnoreCase) == 0);
                }

                ParseQualityNSequence(alignedSeq, Alphabet, Encoding, tokens[9], tokens[10], refSeq, isReadOnly);
                SAMOptionalField optField = null;
                for (int i = 11; i < tokens.Length; i++)
                {
                    optField = new SAMOptionalField();
                    string optionalFieldRegExpn = OptionalFieldLinePattern;
                    if (!Helper.IsValidRegexValue(optionalFieldRegExpn, tokens[i]))
                    {
                        message = string.Format(CultureInfo.CurrentCulture, Resource.InvalidOptionalField, tokens[i]);
                        throw new FormatException(message);
                    }

                    string[] opttokens = tokens[i].Split(colonDelim, StringSplitOptions.RemoveEmptyEntries);
                    optField.Tag   = opttokens[0];
                    optField.VType = opttokens[1];
                    optField.Value = opttokens[2];
                    message        = optField.IsValid();
                    if (!string.IsNullOrEmpty(message))
                    {
                        throw new FormatException(message);
                    }

                    alignedSeq.OptionalFields.Add(optField);
                }

                seqAlignment.QuerySequences.Add(alignedSeq);
                bioReader.GoToNextLine();
            }
        }