Esempio n. 1
0
        /// <summary>
        /// Returns a sparse sequence composed of one of the two alleles for the current
        /// chromosome pointed to by the SnpReader. If ParseAlleleOne is set to true (default),
        /// this parses AlleleOne, else AlleleTwo.
        ///
        /// The Sequence Items correspond to AlleleOne or Two in the reader and their position
        /// in the sparse sequence corresponds to their Position in the SnpItem.
        ///
        /// This starts parsing from the current line and continues until EOF or the chromosome
        /// number changes.
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="isReadOnly">
        /// Flag to indicate whether the resulting sequence should be in readonly mode or not.
        /// If this flag is set to true then the resulting sequence's isReadOnly property
        /// will be set to true, otherwise it will be set to false.
        /// </param>
        /// <returns>Returns a SparseSequence containing Snp items from the first contiguous
        /// chromosome number read from the reader, retaining the same position in the sparse sequence
        /// as the chromosome position.</returns>
        public ISequence ParseOne(TextReader reader, bool isReadOnly)
        {
            ISnpReader snpReader = GetSnpReader(reader);

            snpReader.MoveNext();
            return(ParseOne(snpReader, isReadOnly));
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a sparse sequence composed of one of the two alleles for the current
        /// chromosome pointed to by the SnpReader. If ParseAlleleOne is set to true (default),
        /// this parses AlleleOne, else AlleleTwo.
        ///
        /// The Sequence Items correspond to AlleleOne or Two in the reader and their position
        /// in the sparse sequence corresponds to their Position in the SnpItem.
        ///
        /// This starts parsing from the current line and continues until EOF or the chromosome
        /// number changes.
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="isReadOnly">
        /// Flag to indicate whether the resulting sequence should be in readonly mode or not.
        /// If this flag is set to true then the resulting sequence's isReadOnly property
        /// will be set to true, otherwise it will be set to false.
        /// </param>
        /// <returns>Returns a SparseSequence containing Snp items from the first contiguous
        /// chromosome number read from the reader, retaining the same position in the sparse sequence
        /// as the chromosome position.</returns>
        public ISequence ParseOne(TextReader reader, bool isReadOnly)
        {
            // Check input arguments
            if (reader == null)
            {
                throw new ArgumentNullException("reader", "Text reader to read SNP sequence from cannot be null");
            }

            ISnpReader snpReader = GetSnpReader(reader);

            snpReader.MoveNext();
            return(ParseOne(snpReader, isReadOnly));
        }
Esempio n. 3
0
        /// <summary>
        /// Parses a list of sparse sequences from the reader, one per contiguous
        /// chromosome present in the reader. There is one SequenceItem per SnpItem with
        /// either of the two alleles in the SnpItem (determined by the ParseAlleleOne property)
        /// and at the same position in the sequence as the SnpItem.Position.
        /// </summary>
        /// <param name="reader">Text reader to read the Snpitems from using a SnpReader created for it</param>
        /// <param name="isReadOnly">
        /// Flag to indicate whether the resulting sequences should be in readonly mode or not.
        /// If this flag is set to true then the resulting sequences's isReadOnly property
        /// will be set to true, otherwise it will be set to false.
        /// </param>
        /// <returns>Returns a list of sparse sequences containing Snp items that were read
        /// from the reader, one sequence per contiguous chromosome number and
        /// retaining the same position in the sequence as the chromosome position.</returns>
        public IList <ISequence> Parse(TextReader reader, bool isReadOnly)
        {
            ISnpReader snpReader = GetSnpReader(reader);

            snpReader.MoveNext();

            List <ISequence> sequenceList = new List <ISequence>();

            while (snpReader.Current != null)
            {
                sequenceList.Add(ParseOne(snpReader, isReadOnly));
            }
            return(sequenceList);
        }
Esempio n. 4
0
        /// <summary>
        /// The common ParseOne method called for parsing SNPs
        /// NOTE: The snpReader.MoveNext must have already been called and
        /// the ISnpReader.Current have the first SnpItem to parse into the sequence
        /// </summary>
        /// <param name="snpReader">The ISnpReader to read a Snp chromosome sequence from</param>
        /// <param name="isReadOnly">
        /// Flag to indicate whether the resulting sequence should be in readonly mode or not.
        /// If this flag is set to true then the resulting sequence's isReadOnly property
        /// will be set to true, otherwise it will be set to false.
        /// </param>
        /// <returns>Returns a SparseSequence containing Snp items from the first contiguous
        /// chromosome number read from the snp reader.</returns>
        protected ISequence ParseOne(ISnpReader snpReader, bool isReadOnly)
        {
            // Check input arguments
            if (snpReader == null)
            {
                throw new ArgumentNullException("snpReader", "SNP Reader to read SNP sequences from cannot be null");
            }

            if (snpReader.Current == null)
            {
                return new SparseSequence(Alphabet)
                       {
                           ID = "Empty"
                       }
            }
            ;

            int            sequenceChromosome = snpReader.Current.Chromosome;
            SparseSequence sequence           = new SparseSequence(Alphabet);

            sequence.ID = ("Chr" + sequenceChromosome);

            do
            {
                SnpItem snp = snpReader.Current;

                // increase the size of the sparse sequence
                if (sequence.Count <= snp.Position)
                {
                    sequence.Count = snp.Position + 1;
                }
                sequence[snp.Position] = ParseAlleleOne
                                             ? Alphabet.LookupBySymbol(snp.AlleleOne)
                                             : Alphabet.LookupBySymbol(snp.AlleleTwo);
            } while (snpReader.MoveNext() && snpReader.Current.Chromosome == sequenceChromosome);

            sequence.IsReadOnly = isReadOnly;
            return(sequence);
        }

        #endregion Protected Methods of SnpParser
    }
Esempio n. 5
0
        /// <summary>
        /// Parses a list of sparse sequences from the reader, one per contiguous
        /// chromosome present in the reader. There is one SequenceItem per SnpItem with
        /// either of the two alleles in the SnpItem (determined by the ParseAlleleOne property)
        /// and at the same position in the sequence as the SnpItem.Position.
        /// </summary>
        /// <param name="reader">Text reader to read the Snpitems from using a SnpReader created for it</param>
        /// <param name="isReadOnly">
        /// Flag to indicate whether the resulting sequences should be in readonly mode or not.
        /// If this flag is set to true then the resulting sequences's isReadOnly property
        /// will be set to true, otherwise it will be set to false.
        /// </param>
        /// <returns>Returns a list of sparse sequences containing Snp items that were read
        /// from the reader, one sequence per contiguous chromosome number and
        /// retaining the same position in the sequence as the chromosome position.</returns>
        public IList <ISequence> Parse(TextReader reader, bool isReadOnly)
        {
            // Check input arguments
            if (reader == null)
            {
                throw new ArgumentNullException("reader", "Text reader to read SNP sequences from cannot be null");
            }

            ISnpReader snpReader = GetSnpReader(reader);

            snpReader.MoveNext();

            List <ISequence> sequenceList = new List <ISequence>();

            while (snpReader.Current != null)
            {
                sequenceList.Add(ParseOne(snpReader, isReadOnly));
            }
            return(sequenceList);
        }
Esempio n. 6
0
        /// <summary>
        /// The common ParseOne method called for parsing SNPs
        /// NOTE: The snpReader.MoveNext must have already been called and
        /// the ISnpReader.Current have the first SnpItem to parse into the sequence
        /// </summary>
        /// <param name="snpReader">The ISnpReader to read a Snp chromosome sequence from</param>
        /// <returns>Returns a SparseSequence containing Snp items from the first contiguous
        /// chromosome number read from the snp reader.</returns>
        protected ISequence ParseOne(ISnpReader snpReader)
        {
            // Check input arguments
            if (snpReader == null)
            {
                throw new ArgumentNullException("snpReader", Properties.Resource.snpTextReaderNull);
            }

            if (snpReader.Current == null)
            {
                return new SparseSequence(Alphabet)
                       {
                           ID = "Empty"
                       }
            }
            ;

            int            sequenceChromosome = snpReader.Current.Chromosome;
            SparseSequence sequence           = new SparseSequence(Alphabet);

            sequence.ID = ("Chr" + sequenceChromosome);

            do
            {
                SnpItem snp = snpReader.Current;

                // increase the size of the sparse sequence
                if (sequence.Count <= snp.Position)
                {
                    sequence.Count = snp.Position + 1;
                }
                sequence[snp.Position] = ParseAlleleOne
                             ? (byte)snp.AlleleOne
                             : (byte)snp.AlleleTwo;
            } while (snpReader.MoveNext() && snpReader.Current.Chromosome == sequenceChromosome);

            return(sequence);
        }

        #endregion Protected Methods of SnpParser
    }
Esempio n. 7
0
        /// <summary>
        /// The common ParseOne method called for parsing SNPs
        /// NOTE: The snpReader.MoveNext must have already been called and 
        /// the ISnpReader.Current have the first SnpItem to parse into the sequence
        /// </summary>
        /// <param name="snpReader">The ISnpReader to read a Snp chromosome sequence from</param>
        /// <returns>Returns a SparseSequence containing Snp items from the first contiguous 
        /// chromosome number read from the snp reader.</returns>
        protected ISequence ParseOne(ISnpReader snpReader)
        {
            // Check input arguments
            if (snpReader == null) 
            {
                throw new ArgumentNullException("snpReader",Properties.Resource.snpTextReaderNull);
            }

            if (snpReader.Current == null)
                return new SparseSequence(Alphabet)
                {
                    ID = "Empty"
                };

            int sequenceChromosome = snpReader.Current.Chromosome;
            SparseSequence sequence = new SparseSequence(Alphabet) { ID = "Chr" + sequenceChromosome };

            do
            {
                SnpItem snp = snpReader.Current;
                // increase the size of the sparse sequence
                if (sequence.Count <= snp.Position)
                    sequence.Count = snp.Position + 1;
                sequence[snp.Position] = ParseAlleleOne
                             ? (byte)snp.AlleleOne
                             : (byte)snp.AlleleTwo;
            } while (snpReader.MoveNext() && snpReader.Current.Chromosome == sequenceChromosome);

            return sequence;
        }