public List <MappedItemGroup> ReadFromFile(string fileName) { var result = new List <MappedItemGroup>(); 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 MappedItemGroup(); result.Add(group); foreach (XElement mirnaEle in groupEle.Elements("subject")) { var mirna = new MappedItem(); group.Add(mirna); mirna.Name = mirnaEle.Attribute("name").Value; foreach (XElement regionEle in mirnaEle.Elements("region")) { var region = new SequenceRegionMapped(); mirna.MappedRegions.Add(region); region.Region.Name = mirna.Name; region.Region.ParseLocation(regionEle); if (regionEle.Attribute("sequence") != null) { region.Region.Sequence = regionEle.Attribute("sequence").Value; } if (regionEle.Attribute("query_count_before_filter") != null) { region.QueryCountBeforeFilter = int.Parse(regionEle.Attribute("query_count_before_filter").Value); } if (regionEle.Attribute("pvalue") != null) { region.PValue = double.Parse(regionEle.Attribute("pvalue").Value); } foreach (XElement queryEle in regionEle.Elements("query")) { string qname = queryEle.Attribute("qname").Value; string loc = queryEle.Attribute("loc").Value; string key = SAMAlignedLocation.GetKey(qname, loc); SAMAlignedLocation query = qmmap[key]; region.AlignedLocations.Add(query); query.Features.Add(region.Region); } } } } qmmap.Clear(); return(result); }
public List <SequenceRegionMapped> ReadFromFile(string fileName) { List <SequenceRegionMapped> result = new List <SequenceRegionMapped>(); XElement root = XElement.Load(fileName); var qmmap = root.ToSAMAlignedItems().ToSAMAlignedLocationMap(); foreach (var regionEle in root.Element("regions").Elements("region")) { var position = new SequenceRegionMapped(); result.Add(position); position.Region = new SequenceRegion(); position.Region.Name = regionEle.Attribute("name").Value; position.Region.ParseLocation(regionEle); foreach (var queryEle in regionEle.Elements("query")) { var qname = queryEle.Attribute("qname").Value; var loc = queryEle.Attribute("loc").Value; var key = SAMAlignedLocation.GetKey(qname, loc); var query = qmmap[key]; position.AlignedLocations.Add(query); query.Features.Add(position.Region); } } qmmap.Clear(); return(result); }
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); }