/// <summary>
 /// TODO: Should verify that this only happens once, perhaps also that the samples don't contain things that wouldn't match this,
 /// </summary>
 /// <param name="filterToApply">Filter to apply.</param>
 public void ApplyFilterToAllSNPs(PolymorphismFilter filterToApply)
 {
     foreach (var root in treeRoot.GetAllChildren())
     {
         root.Mutations.FilterSites(filterToApply);
     }
     filtersApplied.Add(filterToApply);
 }
示例#2
0
 public SimpleSample(string id, List <Polymorphism> polys, PolymorphismFilter filter)
 {
     this.Filter = filter;
     this.Id     = id;
     //TODO: See if the filter was already applied?
     this.Polymorphisms = filter.FilterPolys(polys).ToList();
     //now calculate weight
     this.TotalSampleWeight = Polymorphisms.Sum(x => x.getMutationRate());
 }
        public HaploTypeReport GetHaplotypeReport(Sequence toBuildReportFor, List <string> dataLines, string id = "Sample")
        {
            var delts = ReferenceGenome.GetDeltaAlignments(toBuildReportFor).SelectMany(x => x).ToList();

            if (delts.Count != 1)
            {
                return(null);

                throw new Exception("Final assembly had no or multiple delta alignments with the reference, whereas only 1 is expected");
            }
            var delt = delts [0];
            var aln  = delt.ConvertDeltaToSequences();

            dataLines.Add("REF_OFFSET =" + delt.FirstSequenceStart.ToString());
            dataLines.Add("ASSEMBLY_OFFSET =" + delt.SecondSequenceStart.ToString());
            //dataLines.Add("ALN_SCORE=" + aln.Score.ToString());
            var refseq = aln.FirstSequence as Sequence;

            dataLines.Add("REF_SEQUENCE  = " + refseq.ConvertToString());
            var qseq = aln.SecondSequence as Sequence;

            dataLines.Add("QUERY_SEQUENCE= " + qseq.ConvertToString());

            //now get all polymorphisms, and sort haplotypes
            //TODO: Don't call nucmer twice
            var AllPolys          = GenomeToHaploGrepConverter.FindPolymorphisms(toBuildReportFor);
            PolymorphismFilter pf = new PolymorphismFilter();
            var sample            = new SimpleSample(id, AllPolys, pf);
            var comparisons       = treeRoot.GetAllChildren().Select(x => new HaplotypeComparison(x, sample)).ToList();
            var report            = new HaploTypeReport(comparisons, sample);

            dataLines.AddRange(report.GetRowReportLines());
            var passedFilters = sample.Polymorphisms.ToDictionary(x => x.position);

            //noq get list of differences
            dataLines.Add("#Data report below, (Note in rCRS positions, accounting for 'N' at position 3107 and in 1 based index)");
            List <VariantAnnotation> reporters = new List <VariantAnnotation>()
            {
                new HaploTypeMatchAnnotation(report.BestHit, passedFilters),
                new FrequencyFileAnnotation(), new BigTableAnnotation()
            };
            var headerLine = String.Join(VariantAnnotation.FIELD_DELIM, reporters.Select(x => x.GetHeaderLine()).ToArray());

            dataLines.Add(headerLine);
            var infoLines = AllPolys.Select(x => String.Join(VariantAnnotation.FIELD_DELIM, reporters.Select(y => y.GetAnnotation(x)).ToArray()));

            dataLines.AddRange(infoLines);
            return(report);
        }