/// <summary> /// Go to the next line in the text reader, unless it is the first line in which case, /// it has already been called in the constructor and we do not move /// the TextReader. /// </summary> /// <returns>True if we have a valid SnpItem in the next line moved to</returns> public bool MoveNext() { if (!isFirstLine) { GoToNextLine(); } else { // skip...we've already read the first line isFirstLine = false; } // parse the next SNP...if next line not present, set currentSnpitem to null and return false if (!HasLines) { currentSnpItem = null; return(false); } try { // we have a current Snp currentSnpItem = MakeSnpForCurrentLine(); } catch (Exception ex) { throw new FormatException(Properties.Resource.Parser_InvalidFileFormat, ex); } return(true); }
/// <summary> /// Go to the next line in the text reader, unless it is the first line in which case, /// it has already been called by MBFTextReader in the constructor and we do not move /// the TextReader. /// </summary> /// <returns>True if we have a valid SnpItem in the next line moved to</returns> public bool MoveNext() { if (!isFirstLine) { GoToNextLine(); } else { // skip...we've already read the first line isFirstLine = false; } // parse the next SNP...if next line not present, set currentSnpitem to null and return false if (!HasLines) { currentSnpItem = null; return(false); } try { // we have a current Snp currentSnpItem = MakeSnpForCurrentLine(); } catch (Exception ex) { throw new Exception("Error parsing line: " + Line, ex); } return(true); }
public void SnpItemBvtValidateGetHashCode() { SnpItem snpItem1 = new SnpItem(); snpItem1.AlleleOne = 'A'; snpItem1.AlleleTwo = 'G'; Assert.AreEqual(0, snpItem1.GetHashCode()); ApplicationLog.WriteLine("Snp Bvt : Successfully validated GetHashCode()."); }
public void SnpItemValidateEqualsObject() { SnpItem snpItem1 = new SnpItem(); snpItem1.AlleleOne = 'A'; snpItem1.AlleleTwo = 'G'; SnpItem snpItem2 = new SnpItem(); snpItem2.AlleleOne = 'A'; snpItem2.AlleleTwo = 'G'; Assert.IsTrue(snpItem2.Equals((object)snpItem1)); }
/// <summary> /// Makes a SNP item for the current line in the XSV reader. /// Since the XSV reader reads ahead, this is actually the next /// SNP item for the enumerator. /// </summary> /// <returns>Creates a SnpItem for the current line in the XsvReader</returns> private SnpItem MakeSnpForCurrentLine() { SnpItem snpItem = new SnpItem(); snpItem.Chromosome = (byte)ushort.Parse(GetFieldValue(FieldNames.Chromosome)); snpItem.Position = int.Parse(GetFieldValue(FieldNames.Position)); string allele = GetFieldValue(FieldNames.AlleleOne); snpItem.AlleleOne = (!string.IsNullOrEmpty(allele)) ? allele[0] : char.MinValue; allele = GetFieldValue(FieldNames.AlleleTwo); snpItem.AlleleTwo = (!string.IsNullOrEmpty(allele)) ? allele[0] : char.MinValue; return(snpItem); }
public void SnpItemBvtValidateEqualsObject() { SnpItem snpItem1 = new SnpItem(); snpItem1.AlleleOne = 'A'; snpItem1.AlleleTwo = 'G'; SnpItem snpItem2 = new SnpItem(); snpItem2.AlleleOne = 'A'; snpItem2.AlleleTwo = 'G'; Assert.IsTrue(snpItem2.Equals((object)snpItem1)); ApplicationLog.WriteLine("Snp Bvt : Successfully validated Equals(object)."); }
/// <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 }
/// <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 }