Example #1
0
        private void CheckParameter(string optionName, ProgramConfig program, ParameterConfig paramset, string paramname, Func <AnnotationProcessorOptions, string> getFunc, Action <AnnotationProcessorOptions, string> setFunc)
        {
            var value = getFunc(this);

            value = paramset.GetParameter(paramname, value);
            if (string.IsNullOrEmpty(value))
            {
                ParsingErrors.Add(string.Format("{0} {1}. Or you can define the default value at {2}::{3}::{4} in configuration file {5}.",
                                                optionName,
                                                BaseSentenceBuilder.CreateBuiltIn().RequiredOptionMissingText,
                                                program.Name,
                                                paramset.Name,
                                                paramname,
                                                this.Config.ConfigFilename));
            }
            else
            {
                setFunc(this, value);
            }
        }
Example #2
0
        public override bool PrepareOptions()
        {
            if (this.Annovar)
            {
                if (string.IsNullOrEmpty(this.AnnovarBuildVersion))
                {
                    ParsingErrors.Add("--annovar_buildver " + BaseSentenceBuilder.CreateBuiltIn().RequiredOptionMissingText + ".");
                }

                var annovar = this.Config.FindOrCreate("annovar", "table_annovar.pl");

                this.AnnovarCommand = annovar.Command;

                if (!annovar.HasParameterSet(this.AnnovarBuildVersion))
                {
                    var paramset = new ParameterConfig(this.AnnovarBuildVersion);
                    paramset.Parameters["databasedir"]  = string.IsNullOrEmpty(this.AnnovarDatabaseDirectory) ? string.Empty : this.AnnovarDatabaseDirectory;
                    paramset.Parameters["protocol"]     = string.IsNullOrEmpty(this.AnnovarProtocol) ? string.Empty : this.AnnovarProtocol;
                    paramset.Parameters["operation"]    = string.IsNullOrEmpty(this.AnnovarOperation) ? string.Empty : this.AnnovarOperation;
                    annovar.ParameterSet[paramset.Name] = paramset;
                    this.Config.Save();
                    Console.WriteLine(string.Format("annovar buildver {0} is not defined at configuration file {1}, you can modify the configuration file for default parameters!", paramset.Name, this.Config.ConfigFilename));
                }

                var set = annovar.ParameterSet[this.AnnovarBuildVersion];
                CheckParameter("annovar_databasedir", annovar, set, "databasedir", m => m.AnnovarDatabaseDirectory, (m, n) => m.AnnovarDatabaseDirectory = n);
                CheckParameter("annovar_protocol", annovar, set, "protocol", m => m.AnnovarProtocol, (m, n) => m.AnnovarProtocol     = n);
                CheckParameter("annovar_operation", annovar, set, "operation", m => m.AnnovarOperation, (m, n) => m.AnnovarOperation = n);
                if (!Directory.Exists(this.AnnovarDatabaseDirectory))
                {
                    ParsingErrors.Add(string.Format("--annovar_databasedir : directory not exists : {0}", this.AnnovarDatabaseDirectory));
                }
                else
                {
                    var files = Directory.GetFiles(this.AnnovarDatabaseDirectory, this.AnnovarBuildVersion + "*");
                    if (files.Length == 0)
                    {
                        ParsingErrors.Add(string.Format("--annovar_databasedir : there is no annovar database {0} in directory {1}", this.AnnovarBuildVersion, this.AnnovarDatabaseDirectory));
                    }

                    if (this.AnnovarSetDefault)
                    {
                        set.Parameters["databasedir"] = this.AnnovarDatabaseDirectory;
                        set.Parameters["protocol"]    = this.AnnovarProtocol;
                        set.Parameters["operation"]   = this.AnnovarOperation;
                        annovar.DefaultParameterSet   = this.AnnovarBuildVersion;
                        this.Config.Save();
                    }
                }
            }

            if (this.Rnaediting)
            {
                if (!File.Exists(this.RnaeditingDatabase))
                {
                    ParsingErrors.Add(string.Format("--rnaediting_db : file not exists : {0}", this.RnaeditingDatabase));
                }
            }

            if (this.Distance)
            {
                int count = 0;
                if (!string.IsNullOrEmpty(this.DistanceInsertionBed))
                {
                    if (!File.Exists(this.DistanceInsertionBed))
                    {
                        ParsingErrors.Add(string.Format("--distance_insertion_bed : file not exists : {0}", this.DistanceInsertionBed));
                    }
                    else
                    {
                        count++;
                    }
                }

                if (!string.IsNullOrEmpty(this.DistanceDeletionBed))
                {
                    if (!File.Exists(this.DistanceInsertionBed))
                    {
                        ParsingErrors.Add(string.Format("--distance_deletion_bed : file not exists : {0}", this.DistanceDeletionBed));
                    }
                    else
                    {
                        count++;
                    }
                }

                if (!string.IsNullOrEmpty(this.DistanceJunctionBed))
                {
                    if (!File.Exists(this.DistanceInsertionBed))
                    {
                        ParsingErrors.Add(string.Format("--distance_junction_bed : file not exists : {0}", this.DistanceJunctionBed));
                    }
                    else
                    {
                        count++;
                    }
                }

                if (!string.IsNullOrEmpty(this.GtfFile))
                {
                    if (!File.Exists(this.GtfFile))
                    {
                        ParsingErrors.Add(string.Format("--distance_exon_gtf : file not exists : {0}", this.GtfFile));
                    }
                    else
                    {
                        count++;
                    }
                }

                if (count == 0)
                {
                    ParsingErrors.Add(string.Format("--distance : no bed file defined"));
                }
            }

            if (!this.IsPileup)
            {
                if (!File.Exists(this.InputFile))
                {
                    ParsingErrors.Add(string.Format("-i : input file not exists : {0}", this.InputFile));
                }

                if (this.Annovar && !Directory.Exists(this.AnnotationDirectory))
                {
                    try
                    {
                        Directory.CreateDirectory(this.AnnotationDirectory);
                    }
                    catch (Exception ex)
                    {
                        ParsingErrors.Add(string.Format("create directory {0} failed : {1}.", this.AnnotationDirectory, ex.Message));
                    }
                }
            }

            if (string.IsNullOrEmpty(this.OutputFile))
            {
                this.OutputFile = Path.ChangeExtension(this.InputFile, ".annotation.tsv");
            }

            return(ParsingErrors.Count == 0);
        }