コード例 #1
0
ファイル: Output.cs プロジェクト: rgatkinson/nadir
 public void OutputResult(SequenceDesignContext context, object distillationResult, SortedList<DesignScoreResult, SequencesSaveState> best)
     {
     if (this.outputAsText)
         {
         string txtFileName = this.OutputText(context, distillationResult, best);
         this.OutputScoringMatrices(txtFileName, context);
         }
                 
     if (this.outputAsGraph)
         {
         this.OutputGraph(context, distillationResult);
         }
     }
コード例 #2
0
    //
    //------------------------------------------------------------------------------

    public AllocationStatistics(SequenceDesignContext context, bool fTracingEnabled)
        {
        this.fTracingEnabled = fTracingEnabled;

        AddColumn(12, "iter",   "N0",          () => context.DesignIter);
        AddColumn(9, "best",    "",            () => context.ScaleScoreFormatted(this.scoring.designScoreBest.Score));
        AddColumn(9, "cur",     "",            () => context.ScaleScoreFormatted(this.scoring.designScoreCur.Score));
        AddColumn(13, "mut'ns",  "F2", "/iter", () => (double)this.cMutations / this.cScoringIter);
        AddColumn(10, "overall", "F1", "/s",   () => (this.cPrinted > cPrintedOmit) ? ((double)this.cTotalScoringIter / ((this.now-this.nowScoringTrialZero).TotalMilliseconds * 0.001)) : 0.0);
        AddColumn(10, "iters",   "F1", "/s",   () => (double)this.cScoringIter    / ((this.now - this.nowPrev).TotalMilliseconds * 0.001));
        AddColumn(10, "legal",  "F1", "/s",    () => (double)(this.cLegalUp+this.cDown) / ((this.now - this.nowPrev).TotalMilliseconds * 0.001));
        AddColumn(8, "temp",    "F1",          () => this.scoring.temperature);
        AddColumn(6, "n",       "D",           () => this.scoring.designScoreStatistics.N);
        //  AddColumn(9, "mean",    "F2",          () => context.ScaleScore(scoring.designScoreDistribution.Mean));
        //  AddColumn(9, "stddev",  "F2",          () => context.ScaleScore(scoring.designcoreDistribution.StdDev));
        AddColumn(8, "downs",   "F1", "%",     () => (double)this.cDown       / this.cScoringIter * 100); 
        AddColumn(9, "legalup",  "F1", "%",    () => (double)this.cLegalUp    / this.cScoringIter * 100);
        AddColumn(9, "illegal", "F1", "%",     () => (double)this.cIllegalUp  / this.cScoringIter * 100); 
        AddColumn(8, "ups",     "F1", "%",     () => (double)this.cUp         / this.cScoringIter * 100); 
        AddColumn(9, "abandon", "F1", "%",     () => (double)this.cAbandon    / this.cScoringIter * 100);
        AddColumn(9, "hillexp", "g3",          () => this.HillExpansion);
        AddColumn(8, "cMutd",   "F2",          () => (double)this.cChangedStrandsSinceScored / this.cScoringAttempts);
        AddColumn(5, "cTot",    "D",           () => this.cScoreable);
        AddColumn(10, "remain",  "",           () => 
            {
            System.TimeSpan elapsed = this.now - this.nowIterZero;
            if (context.DesignIter != 0 && elapsed.TotalMilliseconds > 0)
                {
                double itersPerSecond = context.DesignIter / (elapsed.TotalMilliseconds * 0.001);
                long itersRemaining = context.Program.DesignIterMax - context.DesignIter;
                return System.TimeSpan.FromSeconds(itersRemaining / itersPerSecond).ToString("dd':'hh':'mm");
                }
            else
                return "unk";
            });

        if (fTracingEnabled)
            { 
            this.fileWriter = context.Program.CreateWritableFile("-trace", out this.fileStream);
            }
        }
コード例 #3
0
ファイル: Output.cs プロジェクト: rgatkinson/nadir
    void OutputScoringMatrices(string txtFileName, SequenceDesignContext context)
    // Output the current scoring matrices in a form that is easily importable into Mathematica.
    // We choose a simple JSON format
        {
        string jsonFileName = Path.GetFileNameWithoutExtension(txtFileName) + ".scores.json";
        FileStream fs = new FileStream(jsonFileName, FileMode.Create, FileAccess.Write, FileShare.Read);
        if (context.Designer != null)
            {
            using (StreamWriter writer = new StreamWriter(fs))
                {
                writer.WriteLine("{");
                int strandCount = context.Designer.StrandVerifiers.Count;
                for (int i = 0; i < strandCount; i++)
                    {
                    writer.WriteLine($"\t\"s{i}\" : \"{context.Designer.StrandVerifiers[i].Strand.Sequence.Nucleotides}\",");
                    writer.WriteLine($"\t\"m{i}\" : \"{MutabiltiesString(context.Designer.StrandVerifiers[i].Strand.Sequence.Mutabilities)}\",");
                    }
            
                writer.WriteLine("\t\"scores\" : [");

                writer.Flush();
                fs.Flush();
                SafeFileHandle handle = fs.SafeFileHandle;
                context.Designer.PrintScoresMatrix(handle);

                fs.Position = fs.Length;
                writer.WriteLine("\t]");
                writer.WriteLine("}");
                }
            }
        }
コード例 #4
0
ファイル: Output.cs プロジェクト: rgatkinson/nadir
 void OutputGraph(SequenceDesignContext context, object result)
     {
     // Render the result
     //
     RenderingContext ctx = new RenderingContext(result);
     ctx.Compose();
     ctx.EmitSchematic();
     }
コード例 #5
0
ファイル: Output.cs プロジェクト: rgatkinson/nadir
 void OutputStrands(int resultNumber, SequenceDesignContext context, PrettyPrintContext pp, List<Strand> strands, long iteration)
     {
     List<string> prints = strands.ConvertAll<string>(s => pp.Cloned().PrettyPrint(BuiltIns.orient(s, Strand.Direction.FiveToThree)));
     //
     pp.NewLine();
     string strStrandsCaption   = context.Designer==null 
         ? $"#{resultNumber}: Strands:"
         : $"#{resultNumber}: Strands: score={context.ScaleScoreFormatted(context.Scoring.designScoreCur.Score)} iter={iteration:N0}";
     string strStrandsUnderline = new string('-', strStrandsCaption.Length);
     pp.AppendLine(strStrandsCaption);
     pp.AppendLine(strStrandsUnderline);
     pp.Indent();
     //
     AutoWidthTable formatter = new AutoWidthTable();
     List<string> formats = new List<string>();
     formatter.AddColumn(strands, s => s.DisplayName);                   formats.Add("{0}");
     formatter.AddColumn(strands, s => s.Length);                      formats.Add(" len={0}");
     if (context.Designer !=null)
         {
         formatter.AddColumn(strands, s => context.ScaleScoreFormatted(s.DesignScore)); formats.Add(" score={0}");
         formatter.AddColumn(strands, s => true 
             ? String.Format("{1}{0:F1}", (s.MeltInfo as IMeltInfo).TempCelsiusCur, (s.MeltInfo.hasGoal ? ":" : "="))
             : "=n/a"); 
         formats.Add(" Tm{0}");
         }
     formatter.AddColumn(prints, p => p);                                formats.Add(" {0}");
     // formatter.AddColumn(strands, s => s.ChunckedNucleotidesWithDecorations);   formats.Add(" {0}");
     formatter.FormatTo(pp, formats.ToArray());
     //
     if (context.Designer != null)
         {
         pp.NewLine();
         formatter = new AutoWidthTable();
         formats = new List<string>();
         formatter.AddColumn(strands, s => $"{s.DisplayName}.seed="); formats.Add("{0}");
         formatter.AddColumn(strands, s => $"\"{s.ChunckedNucleotidesWithDecorations}\";"); formats.Add("{0}");
         formatter.FormatTo(pp, formats.ToArray());
         }
     //
     pp.Outdent();
     }        
コード例 #6
0
ファイル: Output.cs プロジェクト: rgatkinson/nadir
 void OutputDomains(SequenceDesignContext context, PrettyPrintContext pp, Model m)
     {
     List<Domain> domains = new List<Domain>();
     domains.AddRange(m.AllDomains().Distinct<Domain>(new ChemicalEqualitor<Domain>()).Where<Domain>(d => (d.Length > 0)));
     domains.Sort((x,y) => x.FullDisplayName.CompareTo(y.FullDisplayName));
     //
     pp.NewLine();
     string strDomainsCaption   = context.Designer==null ? "Domains" : "Domains (nucleotides as in #1 below)";
     string strDoaminsUnderline = new string('-', strDomainsCaption.Length);
     pp.AppendLine(strDomainsCaption);
     pp.AppendLine(strDoaminsUnderline);
     pp.Indent();
     //
     AutoWidthTable formatter = new AutoWidthTable();
     List<string> formats = new List<string>();
     formatter.AddColumn(domains, d => d.FullDisplayName);       formats.Add("{0}");
     formatter.AddColumn(domains, d => d.Id);                    formats.Add(" id={0}");
     formatter.AddColumn(domains, d => d.Length);                formats.Add(" len={0}");
     if (context.Designer != null)
         {
         formatter.AddColumn(domains, d => 
             {
             double tm = ThermodynamicsData.ComputeThermodynamics(context.Designer.ExperimentalConfiguration, d.Nucleotides, 0).MeltTempCelsius;
             return tm > 0 ? $"{tm:F1}" : "n/a";
             });
         formats.Add(" Tm={0}");
         }
     formatter.AddColumn(domains, d => d.ChunkedNucleotides);    formats.Add(" {0}");
     formatter.FormatTo(pp, formats.ToArray());
     //
     pp.Outdent();
     }
コード例 #7
0
ファイル: Output.cs プロジェクト: rgatkinson/nadir
    string OutputText(SequenceDesignContext context, object result, SortedList<DesignScoreResult, SequencesSaveState> best)
        {
        string fileName = null;

        PrettyPrintContext pp = new PrettyPrintContext();
        //
        DateTime now = DateTime.Now;
        //
        if (this.nadirFiles.Count > 0)
            {
            StreamWriter writer = CreateWritableFile("");
            fileName = (writer.BaseStream as FileStream)?.Name;
            pp.LogToFile(writer);
            }
        //
        pp.NewLine();
        this.OutputBannerAndCopyright(pp);
        //
        pp.Append("Parameters: "); 
        pp.Append(this.args.Interleave(" "));
        pp.NewLine(); 
        //
        pp.AppendLine("Start:        {0}, {1}", this.StartTime.ToLongDateString(), this.StartTime.ToLongTimeString());
        pp.AppendLine("Now:          {0}, {1}", now.ToLongDateString(), now.ToLongTimeString());
        pp.AppendLine("Elapsed time: {0}", FormatElapsed(now - this.StartTime));
        pp.AppendLine("Iterations:   {0:N0}", context.DesignIter);
        pp.AppendLine("Random Seed:  {0}", MiscUtil.RandSeed);
        //
        List<Strand> strands = new List<Strand>();
        if (result is Model)
            {
            strands = new List<Strand>((result as Model).ChemicallyUniqueStrands());
            strands.Sort();

            pp.AppendLine("Nucleotides:  {0,6:N0} unique nucleotide bases", context.IndependentNucleotideCount);
            pp.AppendLine("              {0,6:N0} of those are mutable", context.MutableNucleotideCount);
            pp.AppendLine("Strands:      {0,6:N0} unique strands", strands.Count);
            pp.AppendLine("              {0,6:N0} bases total length", context.TotalNucleotideCount);
            if (context.Designer != null)
                { 
                pp.AppendLine("Tm Calculation Parameters:");
                pp.AppendLine("              {0,6:F2} mM monovalent salt concentration",  context.Designer.MonovalentConcentration * 1000);
                pp.AppendLine("              {0,6:F2} mM divalent salt concentration",    context.Designer.DivalentConcentration * 1000);
                pp.AppendLine("              {0,6:F2} uM oligo concentration",            context.Designer.OligoConcentration * 1000000);
                pp.AppendLine("Scoring Complexity: {0,6:F3}", context.Designer.ScoringComplexity());
                }
            }
        pp.NewLine();
        //
        string title = "Result of Distillation Computation";
        pp.AppendLine(title);
        pp.AppendLine(new string('-', title.Length)); 
        pp.NewLine();
        pp.Indent();
        //
        // Note: this Append here will cause all the domain ids to disambiguate.
        // We want to keep the same disambiguation through the rest of the output here.
        //
        pp.What = PrettyPrintContext.WHAT.DOMAINS;
        pp.AppendLine(result);
        //
        if (this.fOutputNucleotides)
            {
            pp.NewLine();
            pp.What = PrettyPrintContext.WHAT.NUCLEOTIDES;
            pp.AppendLine(result);
            }
        pp.Outdent();
        pp.What = PrettyPrintContext.WhatDefault;
        //
        if (result is Model)
            {
            Model m = result as Model;
            OutputDomains(context, pp, m);
            if (best==null || best.Count == 0)
                {
                OutputStrands(1, context, pp, strands, context.DesignIter);
                }
            else
                {
                int i=1;
                foreach (KeyValuePair<DesignScoreResult,SequencesSaveState> pair in best)
                    {
                    pair.Value.RestoreAndRescore();
                    // scores should be as they originally were, but scoring uses parallelization, which introduces some small numerical uncertainty
                    Trace.Assert(DesignScoreResult.ApproximatelyEquals(pair.Key, pair.Value.SavedDesignScore));
                    OutputStrands(i++, context, pp, strands, pair.Value.Iteration);
                    }
                }
            }
        //
        if (this.nadirFileContents.Length > 0)
            {
            pp.InhibitConsole();
            pp.Append(this.nadirFileContents.ToString());
            pp.DisinhibitConsole();
            }
        //
        MiscUtil.TraceLine(pp.PrettyPrintedOutputString());
        pp.CloseLogFile();
        
        return fileName;
        }
コード例 #8
0
    public void Print(SequenceDesignContext context, Scoring scoring)
        {
        if (!this.fTracingEnabled) return;

        this.context = context;
        this.scoring = scoring;
        this.now     = System.DateTime.Now;

        if (context.Program.Verbose || context.Program.DesignVerbose)
            {
            if (context.DesignIter % context.Program.DesignVerboseColumnHeadersCount == 0)
                {
                this.WriteLine(this.columnHeaders);
                }

            StringBuilder line = new StringBuilder();
            for (int i = 0; i < this.columnValues.Count; i++)
                {
                object value = this.columnValues[i]();
                string formatted = String.Format(this.columnFormats[i], value);
                line.Append(formatted);
                }

            this.WriteLine(line.ToString());
            }
        else
            {
            MiscUtil.Trace($"{scoring.designScoreBest:F1} ");
            }

        this.cPrinted++;

        if (this.cPrinted == cPrintedOmit)
            {
            this.cTotalScoringIter = 0;
            this.nowScoringTrialZero = System.DateTime.Now;
            }

        this.nowPrev = this.now;
        }