コード例 #1
0
        private static IGenomesReferencePath SafeGetReference(string fastaPath)
        {
            IGenomesReferencePath reference = null;

            try
            {
                reference = new IGenomesReferencePath(fastaPath);
            }
            catch { }
            return(reference);
        }
コード例 #2
0
        public static bool SameReference(string fastaA, string fastaB)
        {
            IGenomesReferencePath fastaAReference = null;
            IGenomesReferencePath fastaBReference = null;

            try
            {
                fastaAReference = new IGenomesReferencePath(fastaA);
            }
            catch (ArgumentException)
            { }
            try
            {
                fastaBReference = new IGenomesReferencePath(fastaB);
            }
            catch (ArgumentException)
            { }

            if (fastaAReference == null || fastaBReference == null)
            {
                return(fastaA == fastaB);
            }
            return(fastaAReference.Equals(fastaBReference));
        }
コード例 #3
0
        /// <summary>
        /// Populates the genome metadata from an XML file
        /// </summary>
        public void Deserialize(string inputFilename)
        {
            // open the XML file
            inputFilename = Path.GetFullPath(inputFilename);
            string directory = Path.GetDirectoryName(inputFilename);

            Length     = 0;
            KnownBases = 0; // initial
            int refIndex = 0;
            IGenomesReferencePath iGenomesReference = IGenomesReferencePath.GetReferenceFromFastaPath(directory);

            // use StreamReader to avoid URI parsing of filename that will cause problems with
            // certain characters in the path (#).
            using (var xmlReader = XmlReader.Create(new StreamReader(inputFilename)))
            {
                while (xmlReader.Read())
                {
                    XmlNodeType nType = xmlReader.NodeType;

                    // handle
                    if (nType == XmlNodeType.Element)
                    {
                        // retrieve the genome variables
                        if (xmlReader.Name == "sequenceSizes")
                        {
                            Name = xmlReader.GetAttribute("genomeName");
                            if (iGenomesReference != null && string.IsNullOrEmpty(Name))
                            {
                                Name = iGenomesReference.ToString();
                            }
                        }

                        // retrieve the chromosome variables
                        if (xmlReader.Name == "chromosome")
                        {
                            SequenceMetadata refSeq = new SequenceMetadata
                            {
                                FastaPath = Path.Combine(directory, xmlReader.GetAttribute("fileName")),
                                Name      = xmlReader.GetAttribute("contigName"),
                                Index     = refIndex++,
                                Length    = long.Parse(xmlReader.GetAttribute("totalBases")),
                                Type      = ParseSequenceType(xmlReader.GetAttribute("type"))
                            };
                            Length += refSeq.Length;

                            refSeq.Build   = xmlReader.GetAttribute("build");
                            refSeq.Species = xmlReader.GetAttribute("species");

                            // update species and build from fasta path if in iGenomes format
                            if (iGenomesReference != null)
                            {
                                if (string.IsNullOrEmpty(refSeq.Build))
                                {
                                    refSeq.Build = iGenomesReference.Build;
                                }
                                if (string.IsNullOrEmpty(refSeq.Species))
                                {
                                    refSeq.Species = iGenomesReference.Species;
                                }
                            }

                            string isCircular = xmlReader.GetAttribute("isCircular");
                            if (!string.IsNullOrEmpty(isCircular))
                            {
                                refSeq.IsCircular = (isCircular == "true");
                            }

                            string ploidy = xmlReader.GetAttribute("ploidy");
                            if (!string.IsNullOrEmpty(ploidy))
                            {
                                refSeq.Ploidy = int.Parse(ploidy);
                            }

                            string md5 = xmlReader.GetAttribute("md5");
                            if (!string.IsNullOrEmpty(md5))
                            {
                                refSeq.Checksum = md5;
                            }

                            string knownBases = xmlReader.GetAttribute("knownBases");
                            if (!string.IsNullOrEmpty(knownBases))
                            {
                                refSeq.KnownBases = long.Parse(knownBases);
                                KnownBases       += refSeq.KnownBases;
                            }

                            Sequences.Add(refSeq);
                        }
                    }
                }
            }
        }
コード例 #4
0
        // TODO - If anyone is going to use this, put it somewhere appropriate. Probably in BamReader.
        //public static IGenomesReferencePath GetReferenceFromBamHeader(string bamPath)
        //{
        //    using (BamReader reader = new BamReader(bamPath))
        //    {
        //        return SafeGetReference(reader.GetReferenceURI());
        //    }
        //}

        public bool Equals(IGenomesReferencePath p)
        {
            return(p.Species == Species && p.Provider == Provider && p.Build == Build);
        }