예제 #1
0
        /// <summary>
        /// executes the program
        /// </summary>
        protected override void ProgramExecution()
        {
            var bundle = GetDataBundle(ConfigurationSettings.InputReferencePath, ConfigurationSettings.InputPrefix);
            var header = bundle.Cache.Header.Custom as GlobalCustomHeader;

            if (header == null)
            {
                throw new InvalidCastException("Unable to cast the custom header as a GlobalCustomHeader");
            }

            IUpdater updater              = null;
            var      outputFiles          = new List <string>();
            var      transcriptDataSource = bundle.Cache.Header.TranscriptSource.ToString();

            if (_useTranscriptUpdater)
            {
                var transcripts = GetDesiredTranscripts(bundle, ConfigurationSettings.TranscriptIds);
                if (transcripts.Count == 0)
                {
                    throw new UserErrorException($"Unable to find the desired transcript: {ConfigurationSettings.TranscriptIds}");
                }

                var transcriptId = ConfigurationSettings.TranscriptIds.First();
                var transcript   = transcripts[0];

                updater = new TranscriptUpdater(transcriptId, transcript.ReferenceIndex, transcriptDataSource);
            }
            else if (_useMultiTranscriptUpdater)
            {
                var transcripts = GetDesiredTranscripts(bundle, ConfigurationSettings.TranscriptIds);
                if (transcripts.Count < 2)
                {
                    throw new UserErrorException($"Unable to find two or more transcripts: {ConfigurationSettings.TranscriptIds}");
                }

                var ids = new List <string>();
                ids.AddRange(ConfigurationSettings.TranscriptIds);

                updater = new MultiTranscriptUpdater(ids, transcriptDataSource);
            }
            else if (_usePositionUpdater)
            {
                var refIndex = bundle.Sequence.Renamer.GetReferenceIndex(ConfigurationSettings.ReferenceName);
                updater = new PositionUpdater(refIndex, ConfigurationSettings.ReferencePosition,
                                              ConfigurationSettings.ReferenceAllele, ConfigurationSettings.AlternateAllele, transcriptDataSource);
            }
            else if (_usePositionRangeUpdater)
            {
                var refIndex = bundle.Sequence.Renamer.GetReferenceIndex(ConfigurationSettings.ReferenceName);
                updater = new PositionRangeUpdater(refIndex, ConfigurationSettings.ReferencePosition,
                                                   ConfigurationSettings.ReferenceEndPosition, transcriptDataSource);
            }

            if (updater == null)
            {
                throw new NullReferenceException("The IUpdater is null.");
            }

            var status = updater.Update(bundle, ConfigurationSettings.OutputDirectory, header.VepVersion, outputFiles);

            UnitTestResourceCrawler.CleanupFiles(status, new List <string>(), outputFiles);

            if (status != UpdateStatus.Current)
            {
                throw new UserErrorException($"Unable to create the mini-cache file. Status: {status}");
            }

            Console.WriteLine();
            Console.WriteLine("- created the following files:");
            foreach (var path in outputFiles)
            {
                Console.WriteLine(Path.GetFileNameWithoutExtension(path));
            }
        }
예제 #2
0
        private static CacheFile TryMatchFilename(string ndbPath, Func <string, Match> matcher, MiniCacheType type,
                                                  ChromosomeRenamer renamer)
        {
            string filename = Path.GetFileName(ndbPath);

            if (filename == null)
            {
                return(null);
            }

            var match = matcher(filename);

            if (!match.Success)
            {
                return(null);
            }

            IUpdater updater;
            string   id, transcriptDataSource;
            int      position;
            ushort   refIndex;

            switch (type)
            {
            case MiniCacheType.Transcript:
                var tuple = FormatUtilities.SplitVersion(match.Groups[1].Value);
                id                   = tuple.Item1;
                refIndex             = renamer.GetReferenceIndex(match.Groups[2].Value);
                transcriptDataSource = match.Groups[3].Value;
                updater              = new TranscriptUpdater(id, refIndex, transcriptDataSource);
                break;

            case MiniCacheType.Regulatory:
                id                   = match.Groups[1].Value;
                refIndex             = renamer.GetReferenceIndex(match.Groups[2].Value);
                transcriptDataSource = match.Groups[3].Value;
                updater              = new RegulatoryUpdater(id, refIndex, transcriptDataSource);
                break;

            case MiniCacheType.Position:
                refIndex = renamer.GetReferenceIndex(match.Groups[1].Value);
                position = int.Parse(match.Groups[2].Value);
                string refAllele = match.Groups[3].Value;
                string altAllele = match.Groups[4].Value;
                transcriptDataSource = match.Groups[5].Value;
                updater = new PositionUpdater(refIndex, position, refAllele, altAllele, transcriptDataSource);
                break;

            case MiniCacheType.PositionRange:
                refIndex = renamer.GetReferenceIndex(match.Groups[1].Value);
                position = int.Parse(match.Groups[2].Value);
                int endPosition = int.Parse(match.Groups[3].Value);
                transcriptDataSource = match.Groups[4].Value;
                updater = new PositionRangeUpdater(refIndex, position, endPosition, transcriptDataSource);
                break;

            default:
                throw new GeneralException($"Unexpected mini-cache type encountered: {type}");
            }

            return(new CacheFile(ndbPath, updater.RefIndex, ConvertTranscriptDataSource(updater.TranscriptDataSource),
                                 type, updater));
        }