Beispiel #1
0
 public override string ErrorMessage() 
     { 
     PrettyPrintContext pp = new PrettyPrintContext();
     pp.Append(Format("annealing {1} produces {0} molecular configurations:", configs.Count, annealingFlavor));   // REVIEW: AppendFormat should work, but uses differnt pp context inside, which is wrong
     pp.NewLine();
     pp.Append(Format("input:"));
     pp.Indent(); pp.NewLine();
     pp.Append(Format("{0}", annealed));
     pp.Outdent(); pp.NewLine();
     pp.Append(Format("output:"));
     pp.Indent();
     int i = 0;
     foreach (MoleculeMultiSet config in configs)
         {
         pp.NewLine();
         pp.Append(Format("{0}:", i));
         pp.Indent();
         pp.Append(config);
         pp.Outdent();
         i++;
         }
     pp.Outdent();
     return pp.PrettyPrintedOutputString();
     }
Beispiel #2
0
 public void PrettyPrint(PrettyPrintContext context)
     {
     if (this.children==null || this.ChildCount == 0)
         {
         context.Append('(');
         context.Append(this.ToStringCore());
         context.Append(')');
         }
     else
         {
         if (!this.IsNil)
             {
             context.Append('(');
             context.Append(this.ToStringCore());
             }
         //
         if (this.ChildCount == 1)
             {
             if (!this.IsNil) context.Append(' ');
             this.GetNadirChild(0).PrettyPrint(context);
             }
         else
             {
             if (!this.IsNil) context.Indent();
             //
             foreach (NadirAST child in this.NadirChildren)
                 {
                 context.NewLine();
                 child.PrettyPrint(context);
                 }
             //
             if (!this.IsNil) context.Outdent();
             }
         //
         if (!this.IsNil)
             {
             context.Append(')');
             }
         }
     }   
Beispiel #3
0
 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();
     }        
Beispiel #4
0
 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();
     }
Beispiel #5
0
    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;
        }
Beispiel #6
0
    int                     test = 0;       // if non-zero, is internal test to run

    void Usage()
        {
        PrettyPrintContext pp = new PrettyPrintContext();
        this.OutputBannerAndCopyright(pp);
        pp.NewLine();
        pp.AppendLine($"usage: nadir [options] input.nadir"); 
        pp.Indent();
        pp.AppendLine($"[-f] inputFile          input file(s) to read from (multiple input files are allowed)");
        pp.AppendLine($"-distill globalItem     process definition globalItem into its parts; defaults to first in first file");
        pp.AppendLine($"-nodistill              force no distillation");
        pp.AppendLine($"-design [designerName]  design nucleotides using indicated designer; default to first designer, or trivial designer if none");
        pp.AppendLine($"-nodesign               do not design nucleotide sequences");
        pp.AppendLine($"-nice                   run a background scheduling priority"); 
        pp.Outdent();
        pp.AppendLine("");
        pp.AppendLine($"nucleotide sequence design options");
        pp.Indent();
        pp.AppendLine($"-keepBest nnnn          report this many of the best nucleic acid assignments we fine (default: {designKeepBestCountDefault:N0})");
        pp.AppendLine($"-seed nnnn              set the seed of the random number generator (default: random seed)");
        pp.AppendLine($"-designRate rate        mean mutation rate per iteration (default: {designMutationsPerIterationDefault})");
        pp.AppendLine($"-designSweep iter       sweep for SNP improvements every # of iterations (default: {designIterMutSweepDefault:N0})");
        pp.AppendLine($"-designMin  iter        run sequence designer at least this # of iterations (default: {designIterMinDefault})");
        pp.AppendLine($"-designMax  iter        run sequence designer at most this # of iterations (default: {designIterMaxDefault:N0})");
        pp.AppendLine($"-designGoal score       run sequence designer until this score level reached (default: {designGoalDefault})");
        pp.AppendLine($"-designTemp t           initial temperature for annealling (default: {designTempDefault})");
        pp.AppendLine($"-[no]designTrace iter   print tracing every # of iterations (default: {designIterTraceDefault})");
        pp.Outdent();
        if (this.showHiddenUsage)
            { 
            pp.AppendLine("felony options");
            pp.Indent();
            pp.AppendLine("-felony");
            pp.AppendLine("-fasta file");
            pp.AppendLine("-forward primer");
            pp.AppendLine("-reverse primer");
            pp.AppendLine("-amplicon index length");
            pp.Outdent();
            pp.AppendLine("output options");
            pp.Indent();
            pp.AppendLine("-out text               show output in human-readable text to stdout (default)");
            pp.Indent();
            pp.AppendLine("-[no]verbose         show verbose details in text output");
            pp.AppendLine("-debug               show debugging-related details in text output");
            pp.AppendLine("-nt                  show nucleotides instead of domains in text output");
            pp.AppendLine("-debugTrace          tracing to debug output");
            pp.AppendLine("-consoleTrace        tracing to console output");
            pp.AppendLine("-dumpParse           trace the parse trees");
            pp.AppendLine("-dumpTrees           trace the parse trees");
            pp.Outdent();
            pp.AppendLine("-out graph              show a graphical representation of the output");
            pp.Outdent();
            pp.AppendLine("rare options");
            pp.Indent();
            pp.AppendLine("-designBad              pessimize rather than optimize interactions while designing");
            pp.AppendLine("-domconn                show domain connections in output");
            pp.Outdent();
            }
        System.Console.Error.Write(pp.PrettyPrintedOutputString());
        Environment.Exit(-1);
        }