예제 #1
0
 public void Log(string message)
 {
     if (filter.Accept(message))
     {
         logger.Log(message);
     }
 }
 protected Action <ActionContext> WrapFilter(Action <ActionContext> handler, IFilter filter)
 {
     return((ActionContext ctx) =>
     {
         filter.Accept(handler, ctx);
     });
 }
예제 #3
0
 public static void AssignDecoy <T>(List <T> peptides, IFilter <IIdentifiedSpectrum> decoyFilter) where T : IIdentifiedSpectrum
 {
     foreach (T phit in peptides)
     {
         phit.FromDecoy = decoyFilter.Accept(phit);
     }
 }
예제 #4
0
        public override IEnumerable <string> Process(string fileName)
        {
            IFilter <FastqSequence> filter = options.GetFilter();

            using (GzipTextReader gz1 = new GzipTextReader(options.Gzip, options.FastqFiles[0]))
                using (GzipTextReader gz2 = new GzipTextReader(options.Gzip, options.FastqFiles[1]))
                    using (StreamWriter sw1 = new StreamWriter(options.OutputFiles[0]))
                        using (StreamWriter sw2 = new StreamWriter(options.OutputFiles[1]))
                        {
                            FastqReader reader = new FastqReader();
                            FastqWriter writer = new FastqWriter();
                            var         count  = 0;
                            while (true)
                            {
                                var q1 = reader.Parse(gz1.Reader);
                                var q2 = reader.Parse(gz2.Reader);
                                if (q1 == null || q2 == null)
                                {
                                    break;
                                }

                                count++;

                                if (count % 100000 == 0)
                                {
                                    Progress.SetMessage("{0} reads", count);
                                    if (Progress.IsCancellationPending())
                                    {
                                        throw new UserTerminatedException();
                                    }
                                }

                                if (filter.Accept(q1) && filter.Accept(q2))
                                {
                                    writer.Write(sw1, q1);
                                    writer.Write(sw2, q2);
                                }
                            }
                        }

            return(options.OutputFiles);
        }
예제 #5
0
        private void visitSelect(SelectBuilder item)
        {
            bool needsParentheses = level > 0;

            if (needsParentheses)
            {
                writer.Write("(");
            }
            writer.Write("SELECT ");
            if (item.Distinct != DistinctQualifier.Default)
            {
                DistinctQualifierConverter converter = new DistinctQualifierConverter();
                writer.Write(converter.ToString(item.Distinct));
                writer.Write(" ");
            }
            if (item.Top != null)
            {
                IVisitableBuilder top = item.Top;
                top.Accept(forSubCommand().forValueContext(ValueReferenceType.Reference));
                writer.Write(" ");
            }
            forValueContext(ValueReferenceType.Declaration).join(", ", item.Projection);
            if (item.From.Any())
            {
                writer.Write(" FROM ");
                forSourceContext(SourceReferenceType.Declaration).join(", ", item.From);
            }
            if (item.WhereFilterGroup.HasFilters)
            {
                writer.Write(" WHERE ");
                IFilter where = item.WhereFilterGroup;
                where.Accept(forSubCommand().forValueContext(ValueReferenceType.Reference));
            }
            if (item.GroupBy.Any())
            {
                writer.Write(" GROUP BY ");
                forValueContext(ValueReferenceType.Reference).join(", ", item.GroupBy);
            }
            if (item.HavingFilterGroup.HasFilters)
            {
                writer.Write(" HAVING ");
                IFilter having = item.HavingFilterGroup;
                having.Accept(forSubCommand().forValueContext(ValueReferenceType.Reference));
            }
            if (item.OrderBy.Any())
            {
                writer.Write(" ORDER BY ");
                forValueContext(ValueReferenceType.Alias).join(", ", item.OrderBy);
            }
            if (needsParentheses)
            {
                writer.Write(")");
            }
        }
예제 #6
0
        public PeakList <T> Filter(IFilter <T> filter)
        {
            PeakList <T> result = NewSubPeakList();

            foreach (T peak in this)
            {
                if (filter.Accept(peak))
                {
                    result.Add(peak);
                }
            }
            return(result);
        }
        protected override void VisitSelect(SelectBuilder item)
        {
            this.QueryExpression = CreateDefaultQueryExpression();
            CurrentRequest.Query = this.QueryExpression;

            if (!item.From.Any())
            {
                throw new InvalidOperationException("The query does not have a valid FROM clause");
            }
            Mode = VisitMode.From;
            if (item.From.Count() == 1)
            {
                IsSingleSource = true;
            }
            VisitEach(item.From);

            Mode = VisitMode.Projection;
            NavigateProjections(item.Projection);

            Mode = VisitMode.Filter;
            if (item.WhereFilterGroup != null)
            {
                IFilter where = item.WhereFilterGroup;
                where.Accept(this);
            }
            else
            {
                //TODO: Should only be one where clause?
                foreach (IVisitableBuilder where in item.Where)
                {
                    where.Accept(this);
                }
            }

            if (item.Top != null)
            {
                Mode = VisitMode.Top;
                IVisitableBuilder top = item.Top;
                top.Accept(this);
            }

            if (item.OrderBy != null)
            {
                Mode = VisitMode.OrderBy;
                foreach (IVisitableBuilder order in item.OrderBy)
                {
                    order.Accept(this);
                }
            }
        }
        public List <Pair <char, char> > getSiteListByFilter(
            IFilter <Pair <char, char> > filter)
        {
            List <Pair <char, char> > result = new List <Pair <char, char> >();

            for (int i = 0; i < sites.Count; i++)
            {
                if (filter.Accept(sites[i]))
                {
                    result.Add(new Pair <char, char>(sites[i]));
                }
            }
            return(result);
        }
        private void CreateHideVesselCommands(CommandSet commands)
        {
            var vessels = FlightGlobals.Vessels;

            for (int i = 0; i < vessels.Count; i++)
            {
                var vessel      = vessels[i];
                var needCommand = m_configuration.HideVesselIcons | m_configuration.HideVesselOrbits;
                if (needCommand && m_vesselFilter.Accept(vessel))
                {
                    var command = new HideOrbitCommand(vessel.orbitRenderer, m_configuration.HideVesselIcons, m_configuration.HideVesselOrbits);
                    commands.Add(command);
                }
            }
        }
        private void CreateHideBodiesCommands(CommandSet commands)
        {
            var bodies = FlightGlobals.Bodies;

            for (int i = 0; i < bodies.Count; i++)
            {
                var body        = bodies[i];
                var needCommand = m_configuration.HideCelestialBodyIcons | m_configuration.HideCelestialBodyOrbits;
                if (needCommand && m_celestialBodyFilter.Accept(body))
                {
                    var command = new HideOrbitCommand(body.GetOrbitDriver().Renderer, m_configuration.HideCelestialBodyIcons, m_configuration.HideCelestialBodyOrbits);
                    commands.Add(command);
                }
            }
        }
예제 #11
0
 private void visitDelete(DeleteBuilder item)
 {
     writer.Write("DELETE ");
     if (options.VerboseDeleteStatement)
     {
         writer.Write("FROM ");
     }
     forSourceContext(SourceReferenceType.Declaration).visitAliasedSource(item.Table);
     if (item.WhereFilterGroup.HasFilters)
     {
         writer.Write(" WHERE ");
         IFilter filterGroup = item.WhereFilterGroup;
         filterGroup.Accept(forSubCommand().forValueContext(ValueReferenceType.Reference));
     }
 }
        protected override void VisitSelect(SelectBuilder item)
        {
            this.QueryExpression = new QueryExpression();
            CurrentRequest.Query = this.QueryExpression;
            if (!item.From.Any())
            {
                throw new InvalidOperationException("The query does not have a valid FROM clause");
            }
            Mode = VisitMode.From;
            if (item.From.Count() == 1)
            {
                IsSingleSource = true;
            }
            VisitEach(item.From);

            Mode = VisitMode.Projection;
            NavigateProjections(item.Projection);

            Mode = VisitMode.Filter;
            if (item.WhereFilterGroup != null)
            {
                IFilter where = item.WhereFilterGroup;
                where.Accept(this);
            }
            else
            {
                //TODO: Should only be one where clause?
                foreach (IVisitableBuilder where in item.Where)
                {
                    where.Accept(this);
                }
            }

            if (item.Top != null)
            {
                Mode = VisitMode.Top;
                IVisitableBuilder top = item.Top;
                top.Accept(this);
            }
            else
            {
                // xrm wont let you use paging and top for some reason..
                if (QueryExpression.PageInfo == null)
                {
                    QueryExpression.PageInfo = new PagingInfo();
                }
                QueryExpression.PageInfo.PageNumber = 1;
                //todo take this from the connection string..
                QueryExpression.PageInfo.Count = 500;
                QueryExpression.PageInfo.ReturnTotalRecordCount = true;
            }

            if (item.OrderBy != null)
            {
                Mode = VisitMode.OrderBy;
                foreach (IVisitableBuilder order in item.OrderBy)
                {
                    order.Accept(this);
                }
            }
        }
예제 #13
0
        protected override List <IIdentifiedSpectrum> DoParse()
        {
            IAccessNumberParser parser = options.Parent.Database.GetAccessNumberParser();

            var peptideFormat = new SequestPeptideTextFormat()
            {
                Progress = this.Progress
            };

            Progress.SetRange(0, options.PathNames.Count + 1);

            var result = new List <IIdentifiedSpectrum>();

            IFilter <IIdentifiedSpectrum> spectrumFilter = options.GetFilter();

            SequestOutDirectoryParser outDirParser;
            SequestOutsParser         outsParser;
            SequestOutZipParser       outZipParser;
            string modStr = "";

            if (options.SkipSamePeptideButDifferentModificationSite)
            {
                modStr = MyConvert.Format(".M{0:0.00}", options.MaxModificationDeltaCn);

                outsParser = new SequestOutsParser(true, options.MaxModificationDeltaCn);

                outDirParser = new SequestOutDirectoryParser(true, options.MaxModificationDeltaCn);

                outZipParser = new SequestOutZipParser(true, options.MaxModificationDeltaCn);
            }
            else
            {
                outsParser = new SequestOutsParser(true);

                outDirParser = new SequestOutDirectoryParser(true);

                outZipParser = new SequestOutZipParser(true);
            }
            outsParser.Progress   = Progress;
            outDirParser.Progress = Progress;
            outZipParser.Progress = Progress;

            long     afterFirstMemory = 0;
            DateTime afterFirstTime   = DateTime.Now;

            int stepCount = 0;

            foreach (string pathName in options.PathNames)
            {
                stepCount++;

                if (Progress.IsCancellationPending())
                {
                    throw new UserTerminatedException();
                }

                AbstractSequestSpectraDistiller distiller;
                string engine;
                if (Directory.Exists(pathName))
                {
                    var dir = new DirectoryInfo(pathName);

                    if (dir.GetFiles("*.outs").Length > 0 || dir.GetFiles("*.outs.zip").Length > 0)
                    {
                        distiller = new SequestOutsDistiller(outsParser, peptideFormat);
                    }
                    else
                    {
                        distiller = new SequestOutDirectoryDistiller(outDirParser, peptideFormat);
                    }
                    engine = "SEQUEST";
                }
                else if (pathName.ToLower().EndsWith(".xml"))
                {
                    distiller = new CometSpectraDistiller(peptideFormat);
                    engine    = "COMET";
                }
                else if (pathName.ToLower().EndsWith(".msf"))
                {
                    distiller = new MsfSpectraDistiller(peptideFormat);
                    engine    = "PD";
                }
                else //zipfile
                {
                    ISpectrumParser zipParser;
                    if (ZipUtils.HasFile(pathName, m => m.ToLower().EndsWith(".out")))
                    {
                        zipParser = outZipParser;
                    }
                    else
                    {
                        zipParser = outsParser;
                    }
                    distiller = new SequestOutZipDistiller(zipParser, peptideFormat);
                    engine    = "SEQUEST";
                }

                distiller.Progress = this.Progress;

                List <IIdentifiedSpectrum> curPeptides = distiller.ParseSpectra(pathName, modStr, stepCount, options.PathNames.Count);
                int curPeptideCount = curPeptides.Count;

                if (null != spectrumFilter)
                {
                    curPeptides.RemoveAll(m => !spectrumFilter.Accept(m));
                }

                curPeptides.ForEach(m =>
                {
                    m.Tag    = options.Name;
                    m.Engine = engine;
                });

                result.AddRange(curPeptides);
                curPeptides = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();

                if (stepCount == 1)
                {
                    afterFirstMemory = Process.GetCurrentProcess().WorkingSet64 / (1024 * 1024);
                    afterFirstTime   = DateTime.Now;
                }
                else
                {
                    long   currMemory    = Process.GetCurrentProcess().WorkingSet64 / (1024 * 1024);
                    double averageCost   = (double)(currMemory - afterFirstMemory) / (stepCount - 1);
                    double estimatedCost = afterFirstMemory + averageCost * options.PathNames.Count;

                    DateTime currTime    = DateTime.Now;
                    var      averageTime = currTime.Subtract(afterFirstTime).TotalMinutes / (stepCount - 1);
                    var      finishTime  = afterFirstTime.AddMinutes(averageTime * (options.PathNames.Count - 1));
                    Console.WriteLine("{0}/{1}, cost {2}M, avg {3:0.0}M, need {4:0.0}M, will finish at {5:MM-dd HH:mm:ss}", stepCount, options.PathNames.Count, currMemory, averageCost, estimatedCost, finishTime.ToString());
                }
            }
            return(result);
        }
예제 #14
0
 public PropertyTree ApplyFilter(IFilter <PropertyTree> f)
 {
     return(new PropertyTree(
                Entity, Properties, Children.Where(child => f.Accept(child)).Select(child => child.ApplyFilter(f)).ToImmutableList()));
 }