//Command Handler
                public void ExecuteCommand(CommandConsole c, ReturnArgs retArgs, string[] swtchs, List<string> outputFeed)
                {
                    ArgClass existRef = null;
                    if (this._argName != "")
                    {
                    //    existRef = (from ArgClass r in c._argRefs
                    //                where (r is Reference) && r.FullName == this.FullName
                    //                select r).ToList<ArgClass>();
                        existRef = c.GetReference(this);

                    }
                    var existClass = (from ArgClass r in c._argRefs
                                      where !(r is Reference) && r.FullName == "" + this.Prefix
                                      select r).FirstOrDefault();
                    bool hasParenths = this._suffix != null && this._suffix[this._suffix.Length - 1] == ')', stdOut = false, stdEx = false;
                    bool hasFunction = false;
                    if (this.ArgName != null)
                        hasFunction = this.Parent._funcs.ContainsKey(this.ArgName);
                    List<ArgClass> refChain = new List<ArgClass> { this };
                    if (this._dotHierarchy.Length > 1)
                        refChain = existClass.GetReferenceChain(this._dotHierarchy, this._dotHierarchy[this._dotHierarchy.Length - 1]);
                    //ArgClass rf, fnc;
                    //this.GetObjectFunction(this, refChain, out rf, out fnc);

                    //if (hasFunction && (rf == null || fnc == null))
                    //    return;

                    Reference er = null;
                    if (existRef != null && existRef is Reference)
                        er = (Reference)existRef;
                    if (hasParenths)
                    {
                        ////////////////////
                        if (existRef == null && !hasFunction)
                        {
                            bool? cnstrct = this.AttemptConstruct(c, er, retArgs, swtchs, outputFeed);
                            if (cnstrct.HasValue && cnstrct.Value)
                            {
                                if (existRef == null)
                                {
                                    c.AddReference(this);
                                    outputFeed.Add("'" + this.FullName + "' was constructed.");
                                    return;
                                }
                            }
                            else
                            {
                                //if (!cnstrct.HasValue)
                                    outputFeed.Add("'" + this.FullName + "' was unable to be constructed.");
                                return;
                            }
                        }
                        //////////////////////////

                        bool? b = null;
                        if (!hasFunction)
                            b = this.ExecuteCall(c, er, retArgs, swtchs, outputFeed);
                        else
                            b = this._parRef._funcs[this._argName](c, this, retArgs, swtchs, outputFeed);
                        stdEx = b.HasValue && b.Value;

                        if (!stdEx)
                            return;
                    }

                    //Handle no class
                    if (existClass == null)
                        return;

                    if (!stdEx && this._argName == null)
                    {
                        outputFeed.Add("'" + this.FullName + "' is a type.");
                        return;
                    }

                    //Handleno reference
                    if (!stdEx && (existClass == null || existRef == null))
                    {
                        if (!hasFunction)
                            outputFeed.Add("'" + this.FullName + "' is null.");
                        else
                            outputFeed.Add("'" + this.FullName + "' must be called with ().");
                        return;
                    }
                    else if (!stdEx)
                        stdOut = true;

                    //Standard output from object
                    if (stdOut || stdEx)
                    {
                        if (stdOut)
                        {
                            var o = this.StandardOutput;
                            if (o != null && o != "")
                                outputFeed.Add(o);
                            else
                                outputFeed.Add("'" + this.FullName + "' is instantiated.");
                        }
                        if (stdEx)
                            outputFeed.Add("'" + this.FullName + "' was called.");

                        return;
                    }

                    return;
                }
 public virtual bool? AttemptConstruct(CommandConsole c, Reference existRef, ReturnArgs retArgs, string[] sws, List<string> outputFeed)
 {
     return false;
 }
 //Functions
 public override bool? ExecuteCall(CommandConsole c, Reference existRef, ReturnArgs retArgs, string[] swtchs, List<string> outputFeed)
 {
     return false;
 }
 //Functions
 public virtual bool? ExecuteCall(CommandConsole c, Reference existRef, ReturnArgs retArgs, string[] swtchs, List<string> outputFeed)
 {
     outputFeed.Add("'" + this.FullName + "' was called.");
     return false;
 }
            public Reference HandleCommand(CommandConsole c, ReturnArgs args, string req, List<string> outputFeed)
            {
                if (req == null || c == null || req.Length == 0)
                    return null;

                //Vars
                string[] dotArgs;
                string argName = null, suffix = null, dblprfx = null;
                int sindent = 0, pindent = 0;

                //Get Prefix
                //var prfxArg = (from LineArgumentHandler la in c._argTypes
                //               where la.Prefix == req[0]
                //               select la).FirstOrDefault();
                if (this._prefix.HasValue && this._prefix.Value != req[0])
                    return null;

                if (this._prefix.HasValue)
                    pindent++;

                //Get Double prefix
                if (req.Length > 2)
                {
                    dblprfx = ArgClass.GetDoublePrefix(req.Substring(pindent, 2));
                    if (dblprfx != null)
                        pindent += 2;
                }

                //Suffix
                if (req.Length >= pindent + 2)
                {
                    int ind1 = req.IndexOf(@"(");

                    if (ind1 != -1)
                    {
                        int ind2 = req.IndexOf(@")", ind1);

                        if (ind1 != -1 && ind2 != -1)
                            suffix = ArgClass.GetSuffix(req.Substring(ind1, (ind2 - ind1) + 1));
                    }
                }
                if (suffix != null)
                    sindent += suffix.Length;

                //Get next invalid char, if same as indented, then
                int invChar = ArgClass.GetInvalidCharIndex(pindent, req, ".", true);
                if (invChar == pindent && invChar < req.Length - sindent)
                    return null;

                //Get Dot Hiearchy and final argument
                string ss = req.Substring(pindent, req.Length - sindent - pindent), ss2 = null;
                if (this._prefix.HasValue)
                    ss2 = this._prefix.Value + "." + ss;
                dotArgs = ss2.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

                if (dotArgs.Length > 1)
                    argName = dotArgs[dotArgs.Length - 1];

                if (argName != null)
                {
                    int i = ArgClass.GetInvalidCharIndex(argName);
                    if (i != -1)
                    {
                        outputFeed.Add("'" + argName[i] + "' is an invalid character.");
                        return null;
                    }
                }

                ArgClass par = this;

                if (argName != null && argName != "")
                {
                    var ch1 = this.GetReferenceChain(dotArgs, dotArgs[dotArgs.Length - 2]);
                    if (ch1 == null)
                    {
                        outputFeed.Add("'" + ss + "' is null or invalid.");
                        return null;
                    }
                    var ch2 = ch1[ch1.Count - 1];
                    par = ch2;
                }

                //Get boolean states
                //bool refsObj =

                return this.CreateNewReference(par, dotArgs, argName, dblprfx, suffix);
            }
                public override bool? AttemptConstruct(CommandConsole c, Reference r, CommandConsole.ReturnArgs retArgs, string[] sws, List<string> outputFeed)
                {
                    var a = (string)null;
                    if (sws.Length > 0)
                        for (int i = 0; i < AlphabetTypes.Length; i++)
                            if (sws.Contains<string>(AlphabetTypes[i]))
                            {
                                a = Alphabets[i];
                                break;
                            }

                    bool hasFile = false;
                    bool? longOutput = false;
                    var hasFileType = -1;
                    var s = "";
                    if (sws.Contains<string>("show"))
                        longOutput = true;
                    else if (sws.Contains<string>("hide"))
                        longOutput = null;

                    if (this._conParams.Length > 0)
                        s = this._conParams[0];
                    var p = c.WorkingDirectory + "\\" + s;

                    if (this._conParams != null && this._conParams.Length > 0)
                    {
                        if (File.Exists(p))
                        {
                            hasFile = true;
                            for (int i = 0; i < ValidFileTypes.Length; i++)
                                if (ValidFileTypes[i] == s.Substring(s.Length - ValidFileTypes[i].Length, ValidFileTypes[i].Length))
                                {
                                    hasFileType = i;
                                    break;
                                }
                        }
                    }

                    if (hasFileType != -1)
                    {
                        var f = Management.GetTextFromFile(p);
                        List<string> fasta = new List<string>(), seqs = new List<string>(), o = new List<string>();
                        if (ValidFileTypes[hasFileType] == "fasta" || ValidFileTypes[hasFileType] == "txt")
                        {
                            bool startFound = false, endStartFound = false;
                            for (int i = 0; i < f.Length; i++)
                            {
                                //f[i] = f[i].Replace(@", ", "; ");
                                //f[i] = f[i].Replace(@",", "-");

                                if (f[i].Contains(">"))
                                {
                                    endStartFound = false;
                                    fasta.Add(f[i].Trim());
                                    seqs.Add("");
                                    o.Add(f[i].Trim());
                                    startFound = true;

                                    if (true || f[i].Contains("]") || sws.Contains<string>("literal"))
                                        endStartFound = true;

                                    continue;
                                }

                                if (startFound & !endStartFound)
                                {
                                    if (!f[i].Contains("]"))
                                    {
                                        fasta[fasta.Count - 1] += f[i].Trim();
                                        continue;
                                    }
                                    else
                                    {
                                        var ind = f[i].IndexOf("]");
                                        fasta[fasta.Count - 1] += f[i].Substring(0, ind).Trim();
                                        seqs[seqs.Count - 1] += f[i].Substring(ind, f[i].Length - ind).Trim();
                                        endStartFound = true;
                                        continue;
                                    }
                                }

                                if (endStartFound)
                                {
                                    if (!f[i].Contains(">"))
                                    {
                                        seqs[seqs.Count - 1] += f[i].Trim();
                                        continue;
                                    }
                                    else
                                    {
                                        i--;
                                        startFound = false;
                                        continue;
                                    }
                                }

                                /*
                                while (i < f.Length && !f[i].Contains(">"))
                                {
                                    var addStr = (string)null;
                                    if (a != null)
                                        addStr = StateSequence.RemoveInvalidAlphas(f[i], a);
                                    else
                                        addStr = f[i];
                                    seqs[seqs.Count - 1] += addStr;
                                    i++;
                                }
                                o.Add(seqs[seqs.Count - 1]);
                                i--;

                                */

                                /*
                                if ((i + 2) % 2 == 0)
                                    fasta.Add(f[i]);

                                else
                                    seqs.Add(f[i]);

                                //outputFeed.Add(f[i]);*/
                            }
                        }
                        else if (ValidFileTypes[hasFileType] == "txt2")
                        {
                            for (int i = 0; i < f.Length; i++)
                            {
                                fasta.Add("");
                                seqs.Add(f[i]);
                                //outputFeed.Add(f[i]);
                            }
                        }

                        this._allFasta = fasta;
                        this._allSeqs = seqs;

                        List<string> t = null;
                        if (a != null)
                        {
                            t = new List<string>();
                            for (int i = 0; i < a.Length; i++)
                                t.Add("" + a[i]);
                        }
                        this._myAlpha.AddMessageSamples(this._allSeqs, t);
                        this._myAlpha.UpdateInfo();

                        var rs = "";
                        if (fasta.Count > 0)
                            rs += fasta.Count + " fasta lines";
                        if (fasta.Count > 0 && seqs.Count > 0)
                            rs += " and ";
                        if (seqs.Count > 0)
                            rs += seqs.Count + " sequence lines";
                        if (rs.Length > 0)
                            rs += " were loaded into object '" + this.FullName + "'.";
                        else
                        {
                            outputFeed.Add("No sequence data was found in the requested file.");
                            return false;
                        }

                        if (longOutput != null && ((!longOutput.Value && o.Count < 350) || longOutput.Value))
                            outputFeed.AddRange(o);
                        outputFeed.AddRange(new string[] { "", rs });
                        return true;
                    }
                    else if (hasFile)
                    {
                        outputFeed.Add("'" + this._conParams[0] + "' is an invalid file type");
                        return false;
                    }

                    outputFeed.Add("Invalid parameters");
                    return false;
                }
                //Override Functions
                public override bool? ExecuteCall(CommandConsole c, Reference existRef, CommandConsole.ReturnArgs retArgs, string[] swtchs, List<string> outputFeed)
                {
                    if (this._argName == null)
                        return this.Parent.ExecuteCall(c, existRef, retArgs, swtchs, outputFeed);

                    return false;
                }
 public SeqRef(CommandConsole.ArgClass par, string[] dotHierarchy, string name, string dblprfx, string sfx)
     : base(par, dotHierarchy, name, dblprfx, sfx)
 {
 }
 public override bool? ExecuteCall(CommandConsole c, Reference existRef, CommandConsole.ReturnArgs retArgs, string[] swtchs, List<string> outputFeed)
 {
     return base.ExecuteCall(c, existRef, retArgs, swtchs, outputFeed);
 }
 public override Reference CreateNewReference(CommandConsole.ArgClass par, string[] dotHierarchy, string name, string dblprfx, string sfx)
 {
     return new SeqRef(par, dotHierarchy, name, dblprfx, sfx);
 }
            public static bool? ToCSV(CommandConsole c, Reference existRef, CommandConsole.ReturnArgs retArgs, string[] swtchs, List<string> outputFeed)
            {
                var sr = (SeqRef)existRef.Parent;
                var n = sr.ArgName;

                if (n == null || n == "")
                {
                    outputFeed.Add("parameter required: file name");
                    return false;
                }

                n += ".csv";

                var ss = new List<string[]>();
                for (int i = 0; i < sr.AllFasta.Count; i++)
                {
                    var s = new string[] { sr.AllFasta[i], sr.AllSeqs[i] };
                    ss.Add(s);
                }

                try
                {
                    Management.WriteTextToCSVFile(c.WorkingDirectory + @"\" + n, ss.ToArray<string[]>(), false);
                }
                catch (Exception e)
                {
                    outputFeed.Add("unable to write csv file.");
                    return false;
                }

                var o = Management.GetTextFromFile(c.WorkingDirectory + @"\" + n);

                return true;
            }
            public static bool? FuncStats(CommandConsole c, Reference existRef, CommandConsole.ReturnArgs retArgs, string[] swtchs, List<string> outputFeed)
            {
                SeqRef sr = null;
                if (existRef.Parent is SeqRef)
                {
                    sr = (SeqRef)existRef.Parent;
                    //outputFeed.AddRange(((SeqRef)existRef.Parent).OutputText);
                }

                var a = sr.MyAlphabet;

                var infos = a.MyInfo;

                var allStates = new List<string>();
                for (int i = 0; i < infos.Length; i++)
                {
                    var infoI = infos[i];
                    infoI.UpdateInfo();

                    for (int j = 0; j < infoI.States.Count; j++)
                        allStates.Add(infoI.States[j]);
                }

                var allProbs = new List<List<double>>();
                for (int i = 0; i < infos.Length; i++)
                {
                    allProbs.Add(new List<double>());
                    for (int j = 0; j < allStates.Count; j++)
                    {
                        var queryState = allStates[j];

                        if (queryState.Length == infos[i].StateLength)
                        {
                            var tind = infos[i].States.IndexOf(queryState);
                            if (tind != -1)
                                allProbs[i].Add(infos[i].StateProbabilities[tind]);
                        }

                    }
                }

                var r = new List<string>();
                var max = 0;
                for (int i = 0; i < allProbs.Count; i++)
                {
                    max = Math.Max(allProbs[i].Count, max);
                }

                for (int i = 0; i < allStates.Count; i++)
                {
                    for (int j = 0; j < infos.Length; j++)
                    {
                        if (r.Count <= i)
                            r.Add(allStates[i]);

                        var curState = allStates[i];
                        var curInfo = infos[j];

                        if (curInfo.StateLength == curState.Length)
                        {
                            var tind = infos[j].States.IndexOf(curState);
                            r[i] += ("\t\t" + curInfo.StateProbabilities[tind].ToString("E5").PadRight(16));
                        }
                        else
                            r[i] += ("\t\t-").PadRight(16);

                        continue;

                    }
                }

                var ts = 0;
                /*
                for (int i = 0; i < allProbs.Count; i++)
                {
                    for (int j = 0; j < max; j++)
                    {
                        if (r.Count <= j)
                            r.Add(allStates[j]);
                        var s = "";

                        if (j >= allProbs[i].Count)
                            s = " - ";
                        else
                        {
                            s = ("" + Math.Round(allProbs[i][j], 4));
                            if (s.Contains('.'))
                                s = s.Substring(1, s.Length - 2);
                        }
                        r[j] += ("\t\t" + s.PadRight(16));
                    }
                }*/

                r.Insert(0, "State");
                for (int i = 0; i < infos.Length; i++)
                    r[0] += "\t\tProbability(n=" + infos[i].StateLength + ")";
                outputFeed.AddRange(r);

                return true;
            }