/// <summary>
 /// Extracts sequence from genbank file.
 /// </summary>
 /// <param name="id">
 /// Accession id of the sequence in ncbi (remote id).
 /// </param>
 /// <returns>
 /// The <see cref="Stream"/>.
 /// </returns>
 private static ISequence GetGenBankSequence(string id)
 {
     Stream fileStream = GetResponseStream(GetEfetchParamsString("gbwithparts") + id);
     ISequenceParser parser = new GenBankParser();
     return parser.ParseOne(fileStream);
 }
        /// <summary>
        ///     Validate GenBank Features clonning.
        /// </summary>
        /// <param name="nodeName">xml node name.</param>
        /// <param name="featureName">Name of the GenBank feature</param>
        private void ValidateGenBankFeaturesClonning(string nodeName, FeatureGroup featureName)
        {
            // Get Values from XML node.
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode);
            string expectedExonFeatureCount = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExonCount);
            string expectedExonGeneSymbol = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExonGeneSymbol);
            string expectedExonNumber = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExonNumber);
            string expectedMiscDiffCount = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MiscQualifiersCount);
            string expectedGeneSymbol = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.GeneSymbol);
            string expectedIntronGeneSymbol = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.IntronGeneSymbol);
            string expectedIntronNumber = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.IntronNumber);
            string expectedVariationReplace = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.VariationReplace);

            // Parse a GenBank file.
            ISequenceParser parserObj = new GenBankParser();
            {
                ISequence seq = parserObj.ParseOne(filePath);
                Assert.IsNotNull(seq);

                var metadata = seq.Metadata[Constants.GenBank] as GenBankMetadata;
                Assert.IsNotNull(metadata);

                // Validate cloned GenBank feature.
                switch (featureName)
                {
                    case FeatureGroup.Exon:
                        List<Exon> exonFeatureList = metadata.Features.Exons;

                        // Validate Exon feature before clonning.
                        Assert.AreEqual(exonFeatureList.Count.ToString((IFormatProvider) null), expectedExonFeatureCount);
                        Assert.AreEqual(exonFeatureList[0].GeneSymbol, expectedExonGeneSymbol);
                        Assert.AreEqual(exonFeatureList[0].Number, expectedExonNumber);

                        // Clone Exon feature.
                        Exon clonedExons = exonFeatureList[0].Clone();

                        // Validate Exon feature after clonning.
                        Assert.AreEqual(clonedExons.GeneSymbol, expectedExonGeneSymbol);
                        Assert.AreEqual(clonedExons.Number, expectedExonNumber);
                        break;
                    case FeatureGroup.miscDifference:
                        // Validate Misc Difference feature before clonning.
                        List<MiscDifference> miscDifferenceFeatureList = metadata.Features.MiscDifferences;
                        Assert.AreEqual(miscDifferenceFeatureList.Count.ToString((IFormatProvider) null), expectedMiscDiffCount);
                        Assert.AreEqual(miscDifferenceFeatureList[0].GeneSymbol, expectedGeneSymbol);

                        // Clone Misc Difference feature 
                        MiscDifference clonedMiscDifferences = miscDifferenceFeatureList[0].Clone();

                        // Validate Misc Difference feature  after clonning.
                        Assert.AreEqual(clonedMiscDifferences.GeneSymbol, expectedGeneSymbol);
                        break;
                    case FeatureGroup.Intron:
                        // Validate Intron feature before clonning.
                        List<Intron> intronFeatureList = metadata.Features.Introns;
                        Assert.AreEqual(intronFeatureList[0].GeneSymbol, expectedIntronGeneSymbol);
                        Assert.AreEqual(intronFeatureList[0].Number, expectedIntronNumber);

                        // Clone Intron feature.
                        Intron clonedIntrons = intronFeatureList[0].Clone();

                        // Validate Intron feature after clonning.
                        Assert.AreEqual(clonedIntrons.GeneSymbol, expectedIntronGeneSymbol);
                        Assert.AreEqual(clonedIntrons.Number, expectedIntronNumber);
                        break;
                    case FeatureGroup.variation:
                        // Validate Variation feature before clonning.
                        List<Variation> variationFeatureList = metadata.Features.Variations;
                        Assert.AreEqual(variationFeatureList[0].Replace, expectedVariationReplace);

                        // Clone Variation feature.
                        Variation clonedVariations = variationFeatureList[0].Clone();

                        // Validate Intron feature after clonning.
                        Assert.AreEqual(clonedVariations.Replace, expectedVariationReplace);
                        break;
                    default:
                        break;
                }
            }
        }
        /// <summary>
        ///     Validate GenBank Citation referenced present in GenBank Metadata.
        /// </summary>
        /// <param name="nodeName">xml node name.</param>
        /// <param name="featureName">Feature Name</param>
        private void ValidateCitationReferenced(string nodeName,
                                                FeatureGroup featureName)
        {
            // Get Values from XML node.
            string filePath = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);
            string expectedCitationReferenced = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.citationReferencedCount);
            string expectedmRNACitationReferenced = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.citationReferencedCount);
            string expectedExonACitationReferenced = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.ExonCitationReferencedCount);
            string expectedIntronCitationReferenced = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.IntronCitationReferencedCount);
            string expectedpromoterCitationReferenced = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.PromotersCitationReferencedCount);

            // Parse a GenBank file.
            ISequenceParser parserObj = new GenBankParser();
            {
                ISequence seq = parserObj.ParseOne(filePath);

                var metadata =
                    seq.Metadata[Constants.GenBank] as GenBankMetadata;

                List<CitationReference> citationReferenceList;

                // Get a list citationReferenced present in GenBank file.
                switch (featureName)
                {
                    case FeatureGroup.CDS:
                        FeatureItem cds =
                            metadata.Features.CodingSequences[0];
                        citationReferenceList =
                            metadata.GetCitationsReferredInFeature(cds);

                        // Validate citation referenced present in CDS features.
                        Assert.AreEqual(citationReferenceList.Count.ToString((IFormatProvider) null),
                                        expectedCitationReferenced);
                        break;
                    case FeatureGroup.mRNA:
                        FeatureItem mRNA = metadata.Features.MessengerRNAs[0];
                        citationReferenceList = metadata.GetCitationsReferredInFeature(mRNA);

                        // Validate citation referenced present in mRNA features.
                        Assert.AreEqual(citationReferenceList.Count.ToString((IFormatProvider) null),
                                        expectedmRNACitationReferenced);
                        break;
                    case FeatureGroup.Exon:
                        FeatureItem exon = metadata.Features.Exons[0];
                        citationReferenceList =
                            metadata.GetCitationsReferredInFeature(exon);

                        // Validate citation referenced present in Exons features.
                        Assert.AreEqual(citationReferenceList.Count.ToString((IFormatProvider) null),
                                        expectedExonACitationReferenced);
                        break;
                    case FeatureGroup.Intron:
                        FeatureItem introns = metadata.Features.Introns[0];
                        citationReferenceList =
                            metadata.GetCitationsReferredInFeature(introns);

                        // Validate citation referenced present in Introns features.
                        Assert.AreEqual(citationReferenceList.Count.ToString((IFormatProvider) null),
                                        expectedIntronCitationReferenced);
                        break;
                    case FeatureGroup.Promoter:
                        FeatureItem promoter = metadata.Features.Promoters[0];
                        citationReferenceList =
                            metadata.GetCitationsReferredInFeature(promoter);

                        // Validate citation referenced present in Promoters features.
                        Assert.AreEqual(citationReferenceList.Count.ToString((IFormatProvider) null),
                                        expectedpromoterCitationReferenced);
                        break;
                    default:
                        break;
                }
            }
        }
        /// <summary>
        ///     Validate GenBank features with specified range.
        /// </summary>
        /// <param name="nodeName">xml node name.</param>
        private void ValidateGetFeatures(string nodeName)
        {
            // Get Values from XML node.
            string filePath = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);
            string expectedFirstRangeStartPoint = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.FirstRangeStartPoint);
            string expectedSecondRangeStartPoint = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.SecondRangeStartPoint);
            string expectedFirstRangeEndPoint = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.FirstRangeEndPoint);
            string expectedSecondRangeEndPoint = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.SecondRangeEndPoint);
            string expectedCountWithinSecondRange = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.SecondRangeCount);
            string expectedCountWithinFirstRange = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.FirstRangeCount);
            string expectedQualifierName = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.CDSKey);
            string expectedQualifiers = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.QualifiersCount);
            string firstFeaturesCount = string.Empty;
            string secodFeaturesCount = string.Empty;

            // Parse a GenBank file.
            ISequenceParser parserObj = new GenBankParser();
            {
                ISequence seq = parserObj.ParseOne(filePath);
                var metadata = seq.Metadata[Constants.GenBank] as GenBankMetadata;

                // Validate GetFeature within specified range.
                List<FeatureItem> features =
                    metadata.GetFeatures(Convert.ToInt32(
                        expectedFirstRangeStartPoint, null), Convert.ToInt32(
                            expectedFirstRangeEndPoint, null));

                firstFeaturesCount = metadata.GetFeatures(Convert.ToInt32(
                    expectedFirstRangeStartPoint, null), Convert.ToInt32(
                        expectedFirstRangeEndPoint, null)).Count.ToString((IFormatProvider) null);
                secodFeaturesCount = metadata.GetFeatures(Convert.ToInt32(
                    expectedSecondRangeStartPoint, null), Convert.ToInt32(
                        expectedSecondRangeEndPoint, null)).Count.ToString((IFormatProvider) null);

                // Validate GenBank features count within specified range.
                Assert.AreEqual(firstFeaturesCount, expectedCountWithinFirstRange);
                Assert.AreEqual(secodFeaturesCount, expectedCountWithinSecondRange);
                Assert.AreEqual(features.Count.ToString((IFormatProvider) null), firstFeaturesCount);
                Assert.AreEqual(features[1].Qualifiers.Count.ToString((IFormatProvider) null),
                                expectedQualifiers);
                Assert.AreEqual(features[1].Key.ToString(null), expectedQualifierName);
            }
        }
        public void ValidateGenBankLocationStartAndEndRange()
        {
            // Get Values from XML node.
            string filePath = utilityObj.xmlUtil.GetTextValue(
                Constants.GenBankRepeatRegionQualifiersNode,
                Constants.FilePathNode);
            bool startLocResult = false;
            bool endLocResult = false;
            bool rangeLocResult = false;

            // Parse a GenBank file.
            ISequenceParser parserObj = new GenBankParser();
            {
                ISequence sequence = parserObj.ParseOne(filePath);
                ILocationResolver locResolver = new LocationResolver();

                // Validate Start,End and Range of Gene feature location.
                var metadata =
                    (GenBankMetadata) sequence.Metadata[Constants.GenBank];
                startLocResult =
                    locResolver.IsInStart(metadata.Features.Genes[0].Location, 289);
                endLocResult =
                    locResolver.IsInEnd(metadata.Features.Genes[0].Location, 1647);
                rangeLocResult =
                    locResolver.IsInRange(metadata.Features.Genes[0].Location, 300);

                Assert.IsTrue(startLocResult);
                Assert.IsTrue(endLocResult);
                Assert.IsTrue(rangeLocResult);

                // Log VSTest GUI.
                ApplicationLog.WriteLine(
                    "GenBank Features P1: Successfully validated the location resolver Gene feature start End and IsInRange methods");
            }
        }
        public void ValidateGenBankSubSequence()
        {
            // Get Values from XML node.
            string filePath = utilityObj.xmlUtil.GetTextValue(
                Constants.GenBankRepeatRegionQualifiersNode,
                Constants.FilePathNode);
            string expectedSubSequence = utilityObj.xmlUtil.GetTextValue(
                Constants.GenBankRepeatRegionQualifiersNode,
                Constants.ExpectedFeatureSubSequence);

            // Parse a GenBank file.
            ISequenceParser parserObj = new GenBankParser();
            {
                ISequence sequence = parserObj.ParseOne(filePath);
                ILocationResolver locResolver = new LocationResolver();

                // Get repeatregion subsequence.
                var metadata =
                    (GenBankMetadata) sequence.Metadata[Constants.GenBank];
                ISequence subSeq = locResolver.GetSubSequence(
                    metadata.Features.RepeatRegions[0].Location, sequence);
                var sequenceString = new string(subSeq.Select(a => (char) a).ToArray());

                // Validate repeat region subsequence.
                Assert.AreEqual(sequenceString, expectedSubSequence);

                // Log VSTest GUI.
                ApplicationLog.WriteLine(
                    "GenBank Features P1: Successfully validated the GenBank subSequence");
            }
        }