Exemplo n.º 1
0
 public void PrintFinalOutput(SequenceDesigner designer, NadirContext context)
     {
     FixDomainNames(this.resultToOutput);
     if (designer != null)
         OutputResult(designer.Context, this.resultToOutput, designer.Context.Scoring.BestScores);
     else
         OutputResult(new SequenceDesignContext(context), this.resultToOutput, new SortedList<DesignScoreResult, SequencesSaveState>());
     }
Exemplo n.º 2
0
 //-----------------------------------------------------------------------------------
 // Construction
 //-----------------------------------------------------------------------------------
 
 public SymbolTable(NadirContext context)
     {
     this.Context = context;
     InitTypeSystem();
     }
Exemplo n.º 3
0
    // The factor by which we reduce raw scale scoring when showing them to the user.
    // What's appropriate here is related to the accumulation function used both in computing
    // the pair score of two strands and across strand pairs. If that's 'sum' then the score
    // tends to vary with the square of the number of nucleotides; if it's 'max' then it's 
    // different. We presently use 'sum' as that allows local improvents even in the face
    // of global problems.

    //-----------------------------------------------------------------------------------
    // Construction
    //-----------------------------------------------------------------------------------

    public SequenceDesignContext(NadirContext context)
        {
        Trace.Assert(context.SequenceDesignContext == null);

        this.NadirContext = context;
        this.NadirContext.SequenceDesignContext = this;

        this.Scoring = new Scoring(this);
        }
Exemplo n.º 4
0
    //-----------------------------------------------------------------------------------
    // Construction
    //-----------------------------------------------------------------------------------

    public DistillationContext(NadirContext context, Distiller distiller)
        {
        this.NadirContext = context;
        this.Distiller    = distiller;
        this.mpIdListToIdInfo = new Dictionary<List<int>,IdInfo>(ListIntEqualitor);
        }
Exemplo n.º 5
0
    //-----------------------------------------------------      

    void DumpTrees(TreePrinter printer, NadirContext context)
        {
        MiscUtil.TraceLine("-------------------------", this.FTracingToDebug);
        foreach (ParseResult parseResult in context.ParseResults)
            {
            printer.DumpTree(parseResult.Tree, this.FTracingToDebug);
            }
        }
Exemplo n.º 6
0
    //-----------------------------------------------------     

    public SequenceDesigner Design(NadirContext context, object distillationResult, IScorePrinter printOutput, bool actuallyDesign)
        {
        string designerName = this.globalToDesign;
        if ("" == designerName)
            {
            // If there's a defined designer, then use that one!
            //
            foreach (NadirAST global in ((NadirAST)parseResult).NadirChildren)
                {
                if (global.Type == NadirParser.SeqDesignerDef)
                    {
                    designerName = global.Symbol.Name;
                    break;
                    }
                }
            }   

        Distiller distiller = new Distiller(context);
        SequenceDesigner sequenceDesigner = distiller.SequenceDesign(context, distillationResult, designerName, printOutput, actuallyDesign);
        return sequenceDesigner;
        }
Exemplo n.º 7
0
    //-----------------------------------------------------            

    object Distill(NadirContext context, string nameOfGlobal)
        {
        Distiller distiller = new Distiller(context, true);
        object result = distiller.Distill(nameOfGlobal);
        return result;
        }
Exemplo n.º 8
0
 ANTLRReaderStream OpenFileForAntlr(NadirContext context, string fileName)
     {
     System.IO.StreamReader reader = OpenFileAsReader(context, fileName);
     ANTLRReaderStream result = new ANTLRReaderStream(reader);
     result.SourceName = fileName;
     return result;
     }
Exemplo n.º 9
0
 void DefineTypes(NadirContext context)
     {
     context.PhaseExecuting = PARSEPHASE.DefineTypes;
     foreach (ParseResult parseResult in context.ParseResults)
         {
         NadirASTDefineTypes analyzer = new NadirASTDefineTypes(context,parseResult);
         do  {
             analyzer.TypedefTypeWasResolved = false;
             analyzer.DownUp(parseResult.Tree);    
             } while (!context.ExceptionOccurred && analyzer.TypedefTypeWasResolved);
         }
     context.PhaseCompleted = PARSEPHASE.DefineTypes;
     }
Exemplo n.º 10
0
 void AutoDefineVariables(NadirContext context)
     {
     context.PhaseExecuting = PARSEPHASE.AutoDefineVariables;
     foreach (ParseResult parseResult in context.ParseResults)
         {
         NadirASTAutoVariableDefinitions variableDefiner = new NadirASTAutoVariableDefinitions(context, parseResult);
         variableDefiner.DownUp(parseResult.Tree);
         }
     context.PhaseCompleted = PARSEPHASE.AutoDefineVariables;
     }         
Exemplo n.º 11
0
 void DefineSymbols(NadirContext context)
     {
     context.PhaseExecuting = PARSEPHASE.DefineSymbols;
     foreach (ParseResult parseResult in context.ParseResults)
         {
         NadirASTDefineSymbols symbolDefiner = new NadirASTDefineSymbols(context, parseResult);
         symbolDefiner.DownUp(parseResult.Tree);
         }
     context.PhaseCompleted = PARSEPHASE.DefineSymbols;
     }         
Exemplo n.º 12
0
 void OptimizeAST(NadirContext context)
     {
     context.PhaseExecuting = PARSEPHASE.Optimize;
     foreach (ParseResult parseResult in context.ParseResults)
         {
         NadirASTOptimizer optimizer = new NadirASTOptimizer(context, parseResult);
         parseResult.Tree = (NadirAST)(optimizer.DownUp(parseResult.Tree, true));
         }
     context.PhaseCompleted = PARSEPHASE.Optimize;
     }   
Exemplo n.º 13
0
 void ValidateAST(NadirContext context)
     {
     context.PhaseExecuting = PARSEPHASE.Validate;
     foreach (ParseResult parseResult in context.ParseResults)
         {
         NadirASTValidator validator = new NadirASTValidator(context, parseResult);
         validator.root();
         }
     context.PhaseCompleted = PARSEPHASE.Validate;
     }
Exemplo n.º 14
0
 NadirContext ParseInputs()
     {
     NadirContext context = new NadirContext(this);
     context.PhaseExecuting = PARSEPHASE.Parse;
     //
     foreach (NadirFileDesc desc in nadirFiles)
         {
         // Capture the file contents for posterity. Compute a hash as we do so
         // so we can generate better output file names.
         //
         using (System.IO.StreamReader reader = OpenFileAsReader(context, desc.Filename))
             {
             if (context.ExceptionOccurred) break;
             //
             string fileContents = reader.ReadToEnd();
             //
             using (HashAlgorithm hasher = new SHA1Managed())
                 { 
                 hasher.Initialize();
                 byte[] bytes = new byte[fileContents.Length*2];
                 for (int ich = 0; ich < fileContents.Length; ich++)
                     {
                     int  ch  = (int)fileContents[ich];
                     byte low = (byte)(ch & 0xff);
                     byte hi  = (byte)((ch >> 8) & 0xff);
                     bytes[2*ich] = low;
                     bytes[2*ich + 1] = hi;
                     }
                 hasher.ComputeHash(bytes);
                 byte[] hash = hasher.Hash;
                 desc.Hash = (((int)hash[0])<<0) | (((int)hash[1])<<8) | (((int)hash[2])<<16) | (((int)hash[3])<<24);    // just use the first four bytes as our signature of the file contents
                 }
             //
             this.nadirFileContents.Append(Environment.NewLine);
             this.nadirFileContents.Append(new string('=', 120));
             this.nadirFileContents.Append(Environment.NewLine);
             this.nadirFileContents.Append(fileContents);
             this.nadirFileContents.Append(Environment.NewLine);
             }
         //
         // Ok, now open and actually parse the file
         //
         ANTLRReaderStream inputStream = OpenFileForAntlr(context, desc.Filename);
         NadirLexer        lexer  = new NadirLexer(inputStream, context, true);
         CommonTokenStream tokens = new NadirTokenStream(lexer);
         NadirParser       parser = new NadirParser(context, tokens);
         //
         ParseResult parseResult = new ParseResult(parser.root().Tree);
         if (context.ParseResults.IsEmpty<ParseResult>())
             {
             // First guy in
             context.ParseResults.Add(parseResult);
             }
         else
             {
             // Since these later files were parsed with the contextual
             // symbols of the previous files (the symbol table is shared)
             // splice them all together into one conceptual compilation unit
             //
             context.ParseResults[0].Splice(parseResult);
             }
         //
         if (context.ExceptionOccurred) break;
         }
     //
     context.PhaseCompleted = PARSEPHASE.Parse;
     return context;
     }
Exemplo n.º 15
0
 void ResolveTypes(NadirContext context)
     {
     context.PhaseExecuting = PARSEPHASE.ResolveTypes;
     foreach (ParseResult parseResult in context.ParseResults)
         {
         NadirASTResolveTypes analyzer = new NadirASTResolveTypes(context, parseResult);
         analyzer.DownUp(parseResult.Tree);
         }
     context.PhaseCompleted = PARSEPHASE.ResolveTypes;
     }
Exemplo n.º 16
0
 protected void InitContext(NadirContext context)
     {
     this.context = context;
     }
Exemplo n.º 17
0
 //-----------------------------------------------------            
 // Processing stages
 //
 public static System.IO.StreamReader OpenFileAsReader(NadirContext context, string fileName)
     {
     System.IO.StreamReader reader = null;
     try { 
         reader = System.IO.File.OpenText(fileName);  // to do: catch and process exceptions better
         }
     catch (Exception e)
         {
         context.DisplayException(e);
         }
     return reader;
     }