public virtual List <FeatureItemGroup> ReadFromFile(string fileName) { var result = new List <FeatureItemGroup>(); using (XmlReader source = XmlReader.Create(fileName)) { Progress.SetMessage("reading queries ..."); List <SAMAlignedItem> queries = SAMAlignedItemUtils.ReadFrom(source); Progress.SetMessage("{0} queries read.", queries.Count); var qmmap = queries.ToSAMAlignedLocationMap(); queries.Clear(); Progress.SetMessage("reading subjects ..."); string value; source.ReadToFollowing("subjectResult"); if (source.ReadToDescendant("subjectGroup")) { do { var featureGroup = new FeatureItemGroup(); result.Add(featureGroup); if (source.ReadToDescendant("subject")) { do { var item = new FeatureItem(); featureGroup.Add(item); item.Name = source.GetAttribute("name"); if (source.ReadToDescendant("region")) { do { var fl = new FeatureLocation(); item.Locations.Add(fl); fl.Name = item.Name; fl.Seqname = source.GetAttribute("seqname"); fl.Start = long.Parse(source.GetAttribute("start")); fl.End = long.Parse(source.GetAttribute("end")); fl.Strand = source.GetAttribute("strand")[0]; fl.Sequence = source.GetAttribute("sequence"); value = source.GetAttribute("query_count_before_filter"); if (value != null) { fl.QueryCountBeforeFilter = int.Parse(value); } value = source.GetAttribute("pvalue"); if (value != null) { fl.PValue = double.Parse(value); } if (source.ReadToDescendant("query")) { do { string qname = source.GetAttribute("qname"); string loc = source.GetAttribute("loc"); string key = SAMAlignedLocation.GetKey(qname, loc); SAMAlignedLocation query = qmmap[key]; FeatureSamLocation fsl = new FeatureSamLocation(fl); fsl.SamLocation = query; fsl.Offset = int.Parse(source.GetAttribute("offset")); var attr = source.GetAttribute("overlap"); if (attr == null) { fsl.OverlapPercentage = query.OverlapPercentage(fl); } else { fsl.OverlapPercentage = double.Parse(attr); } var nmi = source.GetAttribute("nmi"); if (nmi != null) { fsl.NumberOfMismatch = int.Parse(nmi); } var nnpm = source.GetAttribute("nnpm"); if (nnpm != null) { fsl.NumberOfNoPenaltyMutation = int.Parse(nnpm); } } while (source.ReadToNextSibling("query")); } } while (source.ReadToNextSibling("region")); } } while (source.ReadToNextSibling("subject")); } } while (source.ReadToNextSibling("subjectGroup")); } qmmap.Clear(); } Progress.SetMessage("{0} subjects read.", result.Count); return(result); }
public List <FeatureItemGroup> ReadFromFile(string fileName) { Console.WriteLine("read file {0} ...", fileName); var result = new List <FeatureItemGroup>(); XElement root = XElement.Load(fileName); //Console.WriteLine("read locations ..."); Dictionary <string, SAMAlignedLocation> qmmap = root.ToSAMAlignedItems().ToSAMAlignedLocationMap(); //Console.WriteLine("read mapped items ..."); foreach (XElement groupEle in root.Element("subjectResult").Elements("subjectGroup")) { var group = new FeatureItemGroup(); result.Add(group); foreach (XElement featureEle in groupEle.Elements("subject")) { var item = new FeatureItem(); group.Add(item); item.Name = featureEle.Attribute("name").Value; foreach (XElement locEle in featureEle.Elements("region")) { var fl = new FeatureLocation(); item.Locations.Add(fl); fl.Name = item.Name; fl.ParseLocation(locEle); if (locEle.Attribute("sequence") != null) { fl.Sequence = locEle.Attribute("sequence").Value; } if (locEle.Attribute("query_count_before_filter") != null) { fl.QueryCountBeforeFilter = int.Parse(locEle.Attribute("query_count_before_filter").Value); } if (locEle.Attribute("pvalue") != null) { fl.PValue = double.Parse(locEle.Attribute("pvalue").Value); } foreach (XElement queryEle in locEle.Elements("query")) { string qname = queryEle.Attribute("qname").Value; string loc = queryEle.Attribute("loc").Value; string key = SAMAlignedLocation.GetKey(qname, loc); SAMAlignedLocation query = qmmap[key]; FeatureSamLocation fsl = new FeatureSamLocation(fl); fsl.SamLocation = query; var attr = queryEle.FindAttribute("overlap"); if (attr == null) { fsl.OverlapPercentage = query.OverlapPercentage(fl); } else { fsl.OverlapPercentage = double.Parse(attr.Value); } var nnpm = queryEle.FindAttribute("nnpm"); if (nnpm == null) { nnpm = queryEle.FindAttribute("nnmp"); } if (nnpm != null) { fsl.NumberOfNoPenaltyMutation = int.Parse(nnpm.Value); } var nmi = queryEle.FindAttribute("nmi"); if (nmi != null) { fsl.NumberOfMismatch = int.Parse(nmi.Value); } } } } } qmmap.Clear(); return(result); }