Пример #1
0
        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);
        }
Пример #2
0
    public static void FilterMappedRegion(MappedItem item)
    {
      //deal with the item with multiple regions but one of them contains others
      if (item.MappedRegions.Count > 1)
      {
        var removed = new List<SequenceRegionMapped>();
        for (int i = 0; i < item.MappedRegions.Count; i++)
        {
          var regi = item.MappedRegions[i];
          for (int j = i + 1; j < item.MappedRegions.Count; j++)
          {
            var regj = item.MappedRegions[j];
            if (removed.Contains(regj))
            {
              continue;
            }

            var con = regi.Region.Contains(regj.Region);
            if (con == 1)
            {
              //if i contains j and all mapped reads mapped to j, remove i
              if (regi.AlignedLocations.All(m => regj.AlignedLocations.Contains(m)))
              {
                removed.Add(regi);
                break;
              }

              //if i contains j and all mapped reads from j were contained in i, remove j 
              if (regj.AlignedLocations.All(m => regi.AlignedLocations.Contains(m)))
              {
                removed.Add(regj);
                continue;
              }
            }
            else if (con == -1)
            {
              //if j contains i and all mapped reads mapped to i, remove j
              if (regj.AlignedLocations.All(m => regi.AlignedLocations.Contains(m)))
              {
                removed.Add(regj);
                continue;
              }

              //if j contains i and all mapped reads from i were contained in j, remove i 
              if (regi.AlignedLocations.All(m => regj.AlignedLocations.Contains(m)))
              {
                removed.Add(regi);
                break;
              }
            }
          }
        }

        removed.ForEach(m => m.AlignedLocations.ForEach(l => l.Features.Remove(m.Region)));

        item.MappedRegions.RemoveAll(m => removed.Contains(m));
      }
    }
        public static void FilterMappedRegion(MappedItem item)
        {
            //deal with the item with multiple regions but one of them contains others
            if (item.MappedRegions.Count > 1)
            {
                var removed = new List <SequenceRegionMapped>();
                for (int i = 0; i < item.MappedRegions.Count; i++)
                {
                    var regi = item.MappedRegions[i];
                    for (int j = i + 1; j < item.MappedRegions.Count; j++)
                    {
                        var regj = item.MappedRegions[j];
                        if (removed.Contains(regj))
                        {
                            continue;
                        }

                        var con = regi.Region.Contains(regj.Region);
                        if (con == 1)
                        {
                            //if i contains j and all mapped reads mapped to j, remove i
                            if (regi.AlignedLocations.All(m => regj.AlignedLocations.Contains(m)))
                            {
                                removed.Add(regi);
                                break;
                            }

                            //if i contains j and all mapped reads from j were contained in i, remove j
                            if (regj.AlignedLocations.All(m => regi.AlignedLocations.Contains(m)))
                            {
                                removed.Add(regj);
                                continue;
                            }
                        }
                        else if (con == -1)
                        {
                            //if j contains i and all mapped reads mapped to i, remove j
                            if (regj.AlignedLocations.All(m => regi.AlignedLocations.Contains(m)))
                            {
                                removed.Add(regj);
                                continue;
                            }

                            //if j contains i and all mapped reads from i were contained in j, remove i
                            if (regi.AlignedLocations.All(m => regj.AlignedLocations.Contains(m)))
                            {
                                removed.Add(regi);
                                break;
                            }
                        }
                    }
                }

                removed.ForEach(m => m.AlignedLocations.ForEach(l => l.Features.Remove(m.Region)));

                item.MappedRegions.RemoveAll(m => removed.Contains(m));
            }
        }
Пример #4
0
    public static List<MappedItem> GroupByName(IEnumerable<SequenceRegionMapped> regions)
    {
      var result = new List<MappedItem>();

      foreach (var curregions in regions.GroupBy(m => m.Region.Name).ToList())
      {
        var mi = new MappedItem();
        mi.Name = curregions.Key;
        mi.MappedRegions.AddRange(curregions);
        result.Add(mi);
      }

      return result;
    }
        public static List <MappedItem> GroupByName(IEnumerable <SequenceRegionMapped> regions)
        {
            var result = new List <MappedItem>();

            foreach (var curregions in regions.GroupBy(m => m.Region.Name).ToList())
            {
                var mi = new MappedItem();
                mi.Name = curregions.Key;
                mi.MappedRegions.AddRange(curregions);
                result.Add(mi);
            }

            return(result);
        }