/// <summary> /// Create a new SegmentMatch struct with the specified values. /// </summary> /// <param name="startSnp">The Snp that is the start of the segment.</param> /// <param name="endSnp">The Snp that is the end of the segment (inclusive).</param> /// <param name="snpCount">The number of matching Snps within the segment.</param> /// <param name="halvesMatched">The number of halves matched; either 1 for a half /// matching segment, or 2 for a full matching segment.</param> public SegmentMatch(Snp startSnp, Snp endSnp, int snpCount, int phasedSnpCount, int score, PhasedGenome.Phasing.MatchKind matchKind, int halvesMatched) { this.startSnp = startSnp; this.endSnp = endSnp; this.snpCount = snpCount; this.phasedSnpCount = phasedSnpCount; this.score = score; this.matchKind = matchKind; this.halvesMatched = halvesMatched; }
static PhasedGenomeFile SimplePhase(string filename, GenomeFile gfile, SnpCollection refSnps) { Console.Write("Creating simple phased genome..."); PhasedGenome phased = new PhasedGenome(gfile.Genome); Console.WriteLine("completed"); PhasedGenomeFile pfile = new PhasedGenomeFile(GetPhasedFilename(filename)); pfile.SetStandardComments(); pfile.AddComment("## history"); pfile.AddComment("## " + DateTime.Now.ToString() + " SimplePhase of " + phased.Count.ToString("#,##0") + " homozygous SNPs (of " + gfile.Genome.Count.ToString("#,##0") + " total)."); pfile.PhasedGenome = phased; return pfile; }
public void Read(SnpCollection snps, CancellationToken cancel, Progress progress) { if (snps == null) throw new ArgumentNullException("The SnpCollection cannot be null."); if (this.filename == null) throw new ArgumentNullException("filename cannot be null."); if (String.IsNullOrWhiteSpace(filename)) throw new ArgumentOutOfRangeException("filename cannot be empty."); if (this.genome == null) { this.genome = new PhasedGenome(1, 23); } else { this.genome.Clear(); } this.comments.Clear(); using (StreamReader reader = new StreamReader(this.filename)) { long length = 0; if (progress != null) length = reader.BaseStream.Length; string line; string[] columns = new string[4]; while ((line = reader.ReadLine()) != null) { cancel.ThrowIfCancellationRequested(); if ((line.Length > 0) && (line[0] != '#')) { int colCount = line.FastSplit('\t', columns); if ((colCount != 2) && (colCount != 4)) throw new ApplicationException("Not phased genome format."); string rsId = columns[0]; Snp snp = snps[rsId]; if (snp != null) { var alleles = columns[colCount - 1]; var phased = new PhasedGenome.Phasing(alleles[0].ToAllele(), alleles[1].ToAllele()); this.genome.Add(snp, phased); } } else if ((line.Length > 0) && (genome.Count == 0) && (line != header)) { this.comments.Add(line); } if (progress != null) progress.Set(reader.BaseStream.Position, length); } } if (String.IsNullOrWhiteSpace(genome.Name)) this.genome.Name = Path.GetFileNameWithoutExtension(filename); }
public void Read(PhasedGenome genome, SnpCollection snps, CancellationToken cancel, Progress progress) { this.PhasedGenome = genome; Read(snps, cancel, progress); }