示例#1
0
    public static bool TryParse(string name, out ITCGATechnology value)
    {
      var lname = name.ToLower();
      foreach (var tec in Technoligies)
      {
        if (tec.ToString().ToLower().Equals(lname))
        {
          value = tec;
          return true;
        }
      }

      value = null;
      return false;
    }
        public static bool TryParse(string name, out ITCGATechnology value)
        {
            var lname = name.ToLower();

            foreach (var tec in Technoligies)
            {
                if (tec.ToString().ToLower().Equals(lname))
                {
                    value = tec;
                    return(true);
                }
            }

            value = null;
            return(false);
        }
        private Dictionary <string, Dictionary <string, double> > GetData(Dictionary <string, BarInfo> barMap,
                                                                          out Func <double, double> getValue)
        {
            Func <string, string>        getFilename;
            IFileReader <ExpressionData> reader = null;

            ITCGATechnology tec = _options.GetTechnology();

            if (_options.IsCount && null != tec.GetCountReader())
            {
                reader      = tec.GetCountReader();
                getFilename = tec.GetCountFilename;
                getValue    = Math.Round;
            }
            else
            {
                reader      = tec.GetReader();
                getFilename = m => m;
                getValue    = m => m;
            }

            //tumor=>barcode=>gene=>value
            var result = new Dictionary <string, Dictionary <string, double> >();

            Progress.SetRange(0, barMap.Count);
            long count = 0;

            foreach (var bm in barMap)
            {
                var data   = reader.ReadFromFile(getFilename(bm.Value.FileName));
                var values = data.Values.ToDictionary(m => m.Name, m => m.Value);
                result[bm.Key] = values;
                count++;
                Progress.SetPosition(count);
            }

            return(result);
        }
示例#4
0
        public static Dictionary <string, BarInfo> GetBarcodeFileMap(string tcgaRootDir, ITCGATechnology tec, string tumor, IList <string> platforms, TCGASampleCode[] sampleTypes = null, Func <List <BarInfo>, BarInfo> barSelect = null, TCGAVialConflict vc = TCGAVialConflict.KeepLast)
        {
            Func <string, bool> acceptBarcode = null;
            HashSet <int>       sampleCodes   = null;

            if (sampleTypes != null)
            {
                sampleCodes   = new HashSet <int>(sampleTypes.ToList().ConvertAll(m => m.Code));
                acceptBarcode = m => sampleCodes.Contains(new BarInfo(m, null).Sample);
            }

            tumor = tumor.ToLower();
            var dir = tcgaRootDir + "/" + tumor;

            if (!Directory.Exists(dir))
            {
                return(new Dictionary <string, BarInfo>());
            }

            if (!Directory.Exists(tec.GetTechnologyDirectory(dir)))
            {
                return(new Dictionary <string, BarInfo>());
            }

            var dataset = tec.GetDataset(dir, platforms, null);

            if (acceptBarcode != null)
            {
                var barcodes = dataset.GetBarCodes();
                foreach (var barcode in barcodes)
                {
                    if (!acceptBarcode(barcode))
                    {
                        dataset.BarInfoListMap.Remove(barcode);
                    }
                }
            }

            if (barSelect == null)
            {
                barSelect = m =>
                {
                    if (m.Count > 1 && m.Any(l => l.Platform.Equals(tec.DefaultPreferPlatform)))
                    {
                        return(m.First(l => l.Platform.Equals(tec.DefaultPreferPlatform)));
                    }

                    return(m.First());
                };
            }

            //For data from different platforms, barSelect solves the conflict
            var result = dataset.BarInfoListMap.Values.ToList().ConvertAll(m => barSelect(m));

            if (vc == TCGAVialConflict.KeepAll)
            {
                return(result.ToDictionary(m => m.BarCode));
            }

            var lst = result.GroupBy(m => m.BarCode.Substring(0, 15)).ToList();

            //For data from same sample but with different vials, keep the last one
            if (vc == TCGAVialConflict.KeepLast)
            {
                return(lst.ConvertAll(n =>
                {
                    if (n.Count() == 1)
                    {
                        return n.First();
                    }

                    return (from l in n select new { Item = l, Vial = l.BarCode.Last() }).OrderByDescending(l => l.Vial).First().Item;
                }).ToDictionary(n => n.BarCode));
            }
            else
            {
                return(lst.ConvertAll(n =>
                {
                    if (n.Count() == 1)
                    {
                        return n.First();
                    }

                    return (from l in n select new { Item = l, Vial = l.BarCode.Last() }).OrderByDescending(l => l.Vial).Last().Item;
                }).ToDictionary(n => n.BarCode));
            }
        }