Esempio n. 1
0
        public static SNPInfo Read(BinaryReader reader)
        {
            var result = new SNPInfo();

            result.id = reader.ReadString();
            result.descriptionWikiText = reader.ReadString();
            result.gene        = reader.ReadString();
            result.chromosome  = reader.ReadString();
            result.position    = reader.ReadInt32();
            result.orientation = (Orientation)reader.ReadByte();
            result.updateTime  = DateTime.FromBinary(reader.ReadInt64());
            result.genotypes   = new SNPGenotypeInfo[reader.ReadInt32()];
            for (int genotypeIndex = 0; genotypeIndex < result.genotypes.Length; genotypeIndex++)
            {
                var genotypeInfo = new SNPGenotypeInfo();
                genotypeInfo.genotype = DiploidGenotype.Read(reader);
                genotypeInfo.trait    = reader.ReadString();
                genotypeInfo.populationFrequencies = new Dictionary <string, float>();
                int numPopulations = reader.ReadInt32();
                for (int populationIndex = 0; populationIndex < numPopulations; populationIndex++)
                {
                    var populationTag       = reader.ReadString();
                    var populationFrequency = reader.ReadSingle();
                    genotypeInfo.populationFrequencies.Add(populationTag, populationFrequency);
                }
                result.genotypes[genotypeIndex] = genotypeInfo;
            }
            return(result);
        }
Esempio n. 2
0
        public static DiploidGenotype Read(BinaryReader reader)
        {
            var result = new DiploidGenotype();

            result.a = (Genotype)reader.ReadByte();
            result.b = (Genotype)reader.ReadByte();
            return(result);
        }
Esempio n. 3
0
        public static SNPGenotype Read(BinaryReader reader)
        {
            var result = new SNPGenotype();

            result.orientation = (Orientation)reader.ReadByte();
            result.genotype    = DiploidGenotype.Read(reader);
            return(result);
        }
Esempio n. 4
0
        public static SNPGenotype ReadLegacy(BinaryReader reader)
        {
            var result            = new SNPGenotype();
            var legacyGenotype    = DiploidGenotype.Read(reader);
            var legacyOrientation = reader.ReadByte();

            result.orientation = Orientation.Plus;
            result.genotype    = DiploidGenotype.Read(reader);
            return(result);
        }
            /** Determines the orientation of the genotypes of a SNP. */
            public Orientation GetOrientation(SNPInfo snpInfo)
            {
                // Check whether any of the SNP's genotypes and their complements don't match the valid alleles for this orientation.
                var matches = new bool[2] {
                    true, true
                };

                foreach (var genotypeInfo in snpInfo.genotypes)
                {
                    // Determine whether this genotype or its complement matches the valid alleles for this orientation.
                    var orientedGenotypes = new DiploidGenotype[]
                    {
                        genotypeInfo.genotype,
                        genotypeInfo.genotype.GetComplement()
                    };
                    for (int tryIndex = 0; tryIndex < orientedGenotypes.Length; tryIndex++)
                    {
                        if (!DoesGenotypeMatch(orientedGenotypes[tryIndex].a) ||
                            !DoesGenotypeMatch(orientedGenotypes[tryIndex].b))
                        {
                            matches[tryIndex] = false;
                        }
                    }
                }

                if (matches[0] && !matches[1])
                {
                    // If the SNP's genotypes all match this orientation's valid alleles, they have the same orientation.
                    return(orientation);
                }
                else if (matches[1] && !matches[0])
                {
                    // If the SNP's genotypes' complements all match this orientation's valid alleles, the SNP's genotypes have the opposite orientation.
                    return(GetOppositeOrientation());
                }
                else
                {
                    // If none of the SNP's genotypes or their complements mismatch this orientation's alleles, we can't determine the orientation of the SNP's genotypes.
                    return(Orientation.Unknown);
                }
            }
Esempio n. 6
0
        public SimpleDiploidTraitPage(
            SNPInfo snpInfo,
            DiploidGenotype personalGenotype
            )
        {
            InitializeComponent();

            // Setup the SNP information controls.
            nameLabel.Content       = snpInfo.id;
            descriptionLabel.Text   = Utilities.ConvertWikiTextToPlainText(snpInfo.descriptionWikiText);
            snpediaLink.NavigateUri = new Uri(string.Format("http://www.snpedia.com/index.php?title={0}", snpInfo.id));

            // Setup the list of genotypes for this SNP.
            bHasMatchingGenotype = false;
            foreach (var genotypeInfo in snpInfo.genotypes)
            {
                bool bGenotypeMatchesPersonalGenome = personalGenotype.Equals(genotypeInfo.genotype);
                if (bGenotypeMatchesPersonalGenome)
                {
                    bHasMatchingGenotype = true;
                }
                genotypeList.Items.Add(new SNPGenotypeUIAdapter(
                                           genotypeInfo,
                                           bGenotypeMatchesPersonalGenome
                                           ));
            }

            // If the genome doesn't match any of the genotypes, create a placeholder genotype for it.
            if (!bHasMatchingGenotype)
            {
                var genotypeInfo = new SNPGenotypeInfo();
                genotypeInfo.genotype = personalGenotype;
                genotypeInfo.trait    = "";
                genotypeInfo.populationFrequencies = new Dictionary <string, float>();
                genotypeList.Items.Add(new SNPGenotypeUIAdapter(
                                           genotypeInfo,
                                           true
                                           ));
            }
        }
Esempio n. 7
0
        public static DiploidGenotype StringToDiploidGenotype(string genotypeString)
        {
            var result = new DiploidGenotype();

            result.a = Genotype.Unknown;
            result.b = Genotype.Unknown;

            var regexMatch = diploidGenotypeRegex.Match(genotypeString);

            if (regexMatch.Success)
            {
                if (regexMatch.Groups.Count >= 2 && regexMatch.Groups[1].Value.Length > 0)
                {
                    result.a = CharacterToGenotype(regexMatch.Groups[1].Value[0]);
                }
                if (regexMatch.Groups.Count >= 3 && regexMatch.Groups[2].Value.Length > 0)
                {
                    result.b = CharacterToGenotype(regexMatch.Groups[2].Value[0]);
                }
            }

            return(result);
        }
Esempio n. 8
0
 public bool Equals(DiploidGenotype otherPair)
 {
     return((a == otherPair.a && b == otherPair.b) ||
            (a == otherPair.b && b == otherPair.a));
 }