Esempio n. 1
0
        private void LoadSequenceMetadata()
        {
            //Associate available metadata with Sequence objects.
            var seqmetadata = from e in _manifestRoot.Descendants(SequenceMetadata.SequenceMetadataLabel)
                              join s in _alignment.Sequences
                              on e.Element(SequenceMetadata.AlignmentRowNameLabel).Value equals s.ID
                              select new { e, s };

            //Load the metadata
            foreach (var sm in seqmetadata)
            {
                sm.s.Metadata.Add(SequenceMetadata.SequenceMetadataLabel, new SequenceMetadata());
                SequenceMetadata metadata = (SequenceMetadata)sm.s.Metadata[SequenceMetadata.SequenceMetadataLabel];

                if (sm.e.Element(SequenceMetadata.ScientificNameLabel) != null)
                {
                    metadata.ScientificName = sm.e.Element(SequenceMetadata.ScientificNameLabel).Value;
                }

                if (sm.e.Element(SequenceMetadata.TaxIDLabel) != null)
                {
                    int taxID = 0;
                    Int32.TryParse(sm.e.Element(SequenceMetadata.TaxIDLabel).Value, out taxID);
                    metadata.TaxID = taxID;
                }

                if (sm.e.Element(SequenceMetadata.LineageLabel) != null)
                {
                    metadata.Lineage = sm.e.Element(SequenceMetadata.LineageLabel).Value;
                }

                if (sm.e.Element(SequenceMetadata.SequenceLengthLabel) != null)
                {
                    int seqLength = 0;
                    Int32.TryParse(sm.e.Element(SequenceMetadata.SequenceLengthLabel).Value, out seqLength);
                    metadata.SequenceLength = seqLength;
                }

                if (sm.e.Element(SequenceMetadata.LocationDescriptionLabel) != null)
                {
                    metadata.LocationDescription = sm.e.Element(SequenceMetadata.LocationDescriptionLabel).Value;
                }

                if (sm.e.Element(SequenceMetadata.AlignmentRowNameLabel) != null)
                {
                    metadata.AlignmentRowName = sm.e.Element(SequenceMetadata.AlignmentRowNameLabel).Value;
                }

                if (sm.e.Element(SequenceMetadata.AccessionsLabel) != null)
                {
                    var accessions = from accession in sm.e.Element(SequenceMetadata.AccessionsLabel).Descendants(SequenceMetadata.GenbankAccessionLabel)
                                     select new GenBankVersion
                    {
                        Accession = accession.Element(SequenceMetadata.GenbankAccessionIDLabel).Value,
                        Version   = accession.Element(SequenceMetadata.GenbankAccessionVersionLabel).Value
                    };
                    foreach (var accession in accessions)
                    {
                        metadata.Accessions.Add(accession);
                    }
                }

                if (sm.e.Element(SequenceMetadata.StructureModelLabel) != null)
                {
                    StructureModel strmodel = new StructureModel(metadata.SequenceLength);
                    var            pairs    = from pair in sm.e.Element(SequenceMetadata.StructureModelLabel).Descendants(SequenceMetadata.StructureModelPairLabel)
                                              select pair;
                    foreach (var pair in pairs)
                    {
                        int fivePrimeIndex, threePrimeIndex;
                        if (Int32.TryParse(pair.Element(SequenceMetadata.StructureModelPairFivePrimeIndexLabel).Value, out fivePrimeIndex) &&
                            Int32.TryParse(pair.Element(SequenceMetadata.StructureModelPairThreePrimeIndexLabel).Value, out threePrimeIndex))
                        {
                            strmodel.Pairs.Add(fivePrimeIndex, threePrimeIndex);
                        }
                    }
                    strmodel.DecomposeStructure();
                    metadata.StructureModel = strmodel;
                }
            }
        }