当前位置: 首页>>代码示例>>C#>>正文


C# StreamReader.GetCharpos方法代码示例

本文整理汇总了C#中System.IO.StreamReader.GetCharpos方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.GetCharpos方法的具体用法?C# StreamReader.GetCharpos怎么用?C# StreamReader.GetCharpos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StreamReader的用法示例。


在下文中一共展示了StreamReader.GetCharpos方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FillDbsnpIdByPosition

    /// <summary>
    /// Fill dbsnp information. The name of SNPItem will be replaced by dbSNP name and the mapping between dbSNP name and old SNPItem name will be returned.
    /// </summary>
    /// <param name="snpItems"></param>
    /// <param name="dbSnpVcfFile"></param>
    /// <param name="progress"></param>
    /// <returns></returns>
    public static Dictionary<string, string> FillDbsnpIdByPosition(this IEnumerable<SNPItem> snpItems, string dbSnpVcfFile, IProgressCallback progress = null)
    {
      var sourceDbsnpMap = snpItems.ToDictionary(m => m.Name, m => m.Name);

      if (progress == null)
      {
        progress = new  EmptyProgressCallback();
      }

      var dic = snpItems.ToDoubleDictionary(m => m.Chrom, m => m.Position);

      progress.SetMessage("Filling dbSNP id from {0} ...", dbSnpVcfFile);
      using (var sr = new StreamReader(dbSnpVcfFile))
      {
        progress.SetRange(0, sr.BaseStream.Length);

        string line;
        while ((line = sr.ReadLine()) != null)
        {
          if (!line.StartsWith("##"))
          {
            break;
          }
        }

        int linecount = 0;
        Dictionary<int, SNPItem> chrMap = null;
        int lastChr = -1;
        while (line != null)
        {
          linecount++;

          if (linecount % 10000 == 0)
          {
            progress.SetPosition(sr.GetCharpos());
          }

          try
          {
            //make sure it is SNV
            if (!line.Contains("VC=SNV"))
            {
              continue;
            }

            //Even it marked as SNV, it still could be insertion/deletion
            //2       179658175       rs11537855      C       CC,CT   .       .       RS=11537855;RSPOS=179658175;dbSNPBuildID=120;SSR=0;SAO=0;VP=0x050100001205000002000110;GENEINFO=TTN:7273;WGT=1;VC=SNV;SLO;NSF;REF;ASP;OTHERKG;NOC
            var parts = line.Split('\t');
            if (parts[3].Split(',').Any(l => l.Length != 1))
            {
              continue;
            }

            if (parts[4].Split(',').Any(l => l.Length != 1))
            {
              continue;
            }

            var chr = HumanChromosomeToInt(parts[0]);
            var position = int.Parse(parts[1]);

            if (lastChr != chr)
            {
              if (!dic.TryGetValue(chr, out chrMap))
              {
                continue;
              }
              lastChr = chr;
            }

            SNPItem source;
            if (!chrMap.TryGetValue(position, out source))
            {
              continue;
            }

            if (!source.Name.Equals(parts[2]))
            {
              sourceDbsnpMap.Remove(source.Name);
              sourceDbsnpMap[source.Name] = parts[2];
            }

            source.DbsnpRefAllele = parts[3][0];
            source.DbsnpAltAllele = parts[4][0];
            source.DbsnpIsReversed = parts[7].Contains(";RV;");
          }
          finally
          {
            line = sr.ReadLine();
          }
        }
      }

//.........这里部分代码省略.........
开发者ID:shengqh,项目名称:CQS.Core,代码行数:101,代码来源:SNPItemUtils.cs

示例2: DoFillAllele2FrequencyFrom1000Gome

    private static void DoFillAllele2FrequencyFrom1000Gome(this IEnumerable<SNPItem> snpItems, string g1000VcfFile, Func<SNPItem, string> keyFunc, IProgressCallback progress = null)
    {
      if (progress == null)
      {
        progress = new ConsoleProgressCallback();
      }

      var dic = snpItems.ToDictionary(m => keyFunc(m));

      progress.SetMessage("Filling MAF from {0} ...", g1000VcfFile);
      using (var sr = new StreamReader(g1000VcfFile))
      {
        progress.SetRange(0, sr.BaseStream.Length);

        string line;
        while ((line = sr.ReadLine()) != null)
        {
          if (!line.StartsWith("##"))
          {
            break;
          }
        }

        int linecount = 0;
        while ((line = sr.ReadLine()) != null)
        {
          linecount++;

          if (linecount % 10000 == 0)
          {
            progress.SetPosition(sr.GetCharpos());
          }

          var parts = line.Split('\t');
          var snp = new SNPItem()
          {
            Chrom = HumanChromosomeToInt(parts[0]),
            Position = int.Parse(parts[1]),
            Name = parts[2]
          };

          SNPItem loc;
          if (!dic.TryGetValue(keyFunc(snp), out loc))
          {
            continue;
          }

          loc.G1000Allele1 = parts[3][0];
          var allele2 = parts[4].Split(',');
          var frequencies = parts[7].StringAfter("AF=").StringBefore(";").Split(',');
          bool bFound = false;
          for (int i = 0; i < allele2.Length; i++)
          {
            if (allele2[i].Length != 1)
            {
              continue;
            }

            loc.G1000Allele2 = allele2[i][0];
            if (loc.IsSourceAllelesMatchedWithG1000())
            {
              loc.G1000Allele2Frequency = double.Parse(frequencies[i]);
              bFound = true;
              break;
            }
          }

          if (!bFound)
          {
            loc.G1000Allele1 = ' ';
            loc.G1000Allele2 = ' ';
            loc.G1000Allele2Frequency = 0.0;
          }
        }
      }
      progress.SetMessage("Filling MAF finished.");
    }
开发者ID:shengqh,项目名称:CQS.Core,代码行数:77,代码来源:SNPItemUtils.cs


注:本文中的System.IO.StreamReader.GetCharpos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。