private static bool IsRefMinor(IRefMinorProvider refMinorProvider, IChromosome chrom, int position)
 {
     if (refMinorProvider == null)
     {
         return(false);
     }
     return(!string.IsNullOrEmpty(refMinorProvider.GetGlobalMajorAllele(chrom, position)));
 }
Beispiel #2
0
        public static IPosition ToPosition(ISimplePosition simplePosition, IRefMinorProvider refMinorProvider, ISequenceProvider sequenceProvider, IMitoHeteroplasmyProvider mitoHeteroplasmyProvider, VariantFactory variantFactory, bool enableDq = false)
        {
            if (simplePosition == null)
            {
                return(null);
            }

            sequenceProvider.LoadChromosome(simplePosition.Chromosome);

            string[] vcfFields   = simplePosition.VcfFields;
            string[] altAlleles  = vcfFields[VcfCommon.AltIndex].OptimizedSplit(',');
            bool     isReference = altAlleles.Length == 1 && VcfCommon.ReferenceAltAllele.Contains(altAlleles[0]);

            string globalMajorAllele = isReference
                ? refMinorProvider?.GetGlobalMajorAllele(simplePosition.Chromosome, simplePosition.Start)
                : null;

            bool isRefMinor = isReference && globalMajorAllele != null;

            if (isReference && !isRefMinor)
            {
                return(GetReferencePosition(simplePosition));
            }

            var    infoData = VcfInfoParser.Parse(vcfFields[VcfCommon.InfoIndex]);
            int    end      = ExtractEnd(infoData, simplePosition.Start, simplePosition.RefAllele.Length);
            double?quality  = vcfFields[VcfCommon.QualIndex].GetNullableValue <double>(double.TryParse);

            string[]  filters = vcfFields[VcfCommon.FilterIndex].OptimizedSplit(';');
            ISample[] samples = vcfFields.ToSamples(variantFactory.FormatIndices, simplePosition, mitoHeteroplasmyProvider, enableDq);

            IVariant[] variants = variantFactory.CreateVariants(simplePosition.Chromosome, simplePosition.Start, end,
                                                                simplePosition.RefAllele, altAlleles, infoData, simplePosition.IsDecomposed,
                                                                simplePosition.IsRecomposed, simplePosition.LinkedVids, globalMajorAllele);

            return(new Position(simplePosition.Chromosome, simplePosition.Start, end, simplePosition.RefAllele,
                                altAlleles, quality, filters, variants, samples, infoData, vcfFields, simplePosition.IsDecomposed,
                                simplePosition.IsRecomposed));
        }