public async Task <FrequencyReport> Frequency(FastaReader reader, string evalue = "1e-6")
        {
            var report        = new FrequencyReport(reader.Length);
            var blastnResults = await Client.ExecuteBuffered(new BlastnOptions(reader.Path)
            {
                Task             = Task,
                Evalue           = evalue,
                FormatSpecifiers = new List <string> {
                    "qseqid"
                },
                MaxTargetSeqs = MaxTargetSeqs
            });

            foreach (var result in blastnResults)
            {
                if (result.QuerySeqId == null)
                {
                    continue;
                }
                var index = reader.IndexOf(result.QuerySeqId);
                report.Increment(index);
            }

            return(report);
        }
Ejemplo n.º 2
0
        /**
         * TODO: Avec frequency > 2 pour les autres Alternatives ? Inutile pour l'instant
         */
        public async Task <FrequencyReport> SnpFrequency(string referenceId, Snp snp, int windowSize = 20,
                                                         int validateSize = 5)
        {
            var genome = await Reader.ReadSequenceAsync(referenceId);

            if (genome[snp.Position0].ToString() != snp.Reference)
            {
                throw new Exception("Reference mismatch");
            }

            var beforeWindow = new Range(snp.Position0 - windowSize, snp.Position0);
            var afterWindow  = new Range(snp.Position0 + 1, snp.Position0 + 1 + windowSize);

            var seq1 = genome[beforeWindow] + genome[snp.Position0] + genome[afterWindow];
            var seq2 = genome[beforeWindow] + snp.Insertion + genome[afterWindow];

            var options = await BlastnOptions.FromInlineQuery($">id\n{seq2}");

            options.Evalue           = "1e-5";
            options.Task             = "blastn";
            options.MaxTargetSeqs    = 150;
            options.FormatSpecifiers = new List <string> {
                "sseq"
            };
            var results = await Client.ExecuteBuffered(options);

            var validateBefore = new Range(windowSize - validateSize + 1, windowSize + 1);
            var validateAfter  = new Range(windowSize, windowSize + validateSize);

            var frequencies = new FrequencyReport(2);

            foreach (var result in results)
            {
                if (String.IsNullOrEmpty(result.AlignedPartOfSubjectSequence))
                {
                    continue;
                }
                if (result.AlignedPartOfSubjectSequence.Contains(seq1[validateBefore]))
                {
                    frequencies.Increment(0);
                }
                if (result.AlignedPartOfSubjectSequence.Contains(seq1[validateAfter]))
                {
                    frequencies.Increment(0);
                }
                if (result.AlignedPartOfSubjectSequence.Contains(seq2[validateBefore]))
                {
                    frequencies.Increment(1);
                }
                if (result.AlignedPartOfSubjectSequence.Contains(seq2[validateAfter]))
                {
                    frequencies.Increment(1);
                }
            }

            return(frequencies);
        }