public override IEnumerable <string> Process() { using (var file = new PlinkBedRandomFile(_options.InputFile) { Progress = this.Progress }) { var locusList = file.Data.Locus; var individualList = file.Data.Individual; Progress.SetRange(0, locusList.Count); for (int i = 0; i < locusList.Count; i++) { Progress.SetPosition(i); var locus = locusList[i]; var data = file.Read(locus.MarkerId); int count1 = 0; int count2 = 0; int validSample = 0; for (int j = 0; j < individualList.Count; j++) { if (PlinkData.IsMissing(data[0, j], data[1, j])) { continue; } validSample++; if (data[0, j]) { count2++; } else { count1++; } if (data[1, j]) { count2++; } else { count1++; } } locus.Allele1Frequency = ((double)(count1)) / (count1 + count2); locus.TotalSample = individualList.Count; locus.ValidSample = validSample; } PlinkLocus.WriteToFile(_options.OutputFile, locusList, false, true, true); } return(new string[] { _options.OutputFile }); }
public override IEnumerable <string> Process() { Progress.SetMessage("Reading data from " + _options.InputFile + "..."); var data = _options.GetFileReader().ReadFromFile(_options.InputFile); var locusList = data.Locus; var individualList = data.Individual; for (int i = 0; i < locusList.Count; i++) { var locus = locusList[i]; int count1 = 0; int count2 = 0; int validSample = 0; for (int j = 0; j < individualList.Count; j++) { if (data.IsMissing(i, j)) { continue; } validSample++; if (data.IsHaplotype1Allele2[i, j]) { count2++; } else { count1++; } if (data.IsHaplotype2Allele2[i, j]) { count2++; } else { count1++; } } locus.Allele1Frequency = ((double)(count2)) / (count1 + count2); locus.TotalSample = individualList.Count; locus.ValidSample = validSample; } PlinkLocus.WriteToFile(_options.OutputFile, locusList, false, true); return(new string[] { _options.OutputFile }); }
public override IEnumerable <string> Process() { var locusList = new List <PlinkLocus>(); using (var sr = new StreamReader(_options.InputFile)) { string line; while ((line = sr.ReadLine()) != null) { var parts = line.Split(' '); var locus = new PlinkLocus() { Chromosome = int.Parse(parts[0]), MarkerId = parts[1], PhysicalPosition = int.Parse(parts[2]), Allele1 = parts[3], Allele2 = parts[4] }; locusList.Add(locus); var count1 = 0; var count2 = 0; for (int i = 5; i < parts.Length; i += 3) { if (parts[i].Equals("1")) { count1 += 2; } else if (parts[i + 1].Equals("1")) { count1++; count2++; } else if (parts[i + 2].Equals("1")) { count2 += 2; } else {//unknown, ignore Console.Error.WriteLine(string.Format("Unknown, name={0}, i={1}, genotype={2} {3} {4}", locus.MarkerId, i, parts[i], parts[i + 1], parts[i + 2])); } } locus.Allele1Frequency = ((double)(count2)) / (count1 + count2); } } PlinkLocus.WriteToFile(_options.OutputFile, locusList, false, true); return(new string[] { _options.OutputFile }); }