예제 #1
0
 public static void UpdateCentimorgans(string[] args) {
     SnpCollection snps = new SnpCollection(1, 23);
     string filename = args[1];
     SnpFile.ReadRutgers(snps, filename, new System.Threading.CancellationToken(), null);
     for (int i = 1; i <= 23; i++) snps.Add(new Snp("fake" + i, (byte) i, 0, 0, null, null));
     SnpCollection refSnps = new SnpCollection(1, 23);
     SnpFile.Read(refSnps, "RefSnps.csv");
     Snp prevSnp = null;
     foreach(Snp snp in refSnps) {
         Snp rutgerSnp = null;
         if (snps.Contains(snp.RsId)) {
             rutgerSnp = snps[snp.RsId];
             //if ((rutgerSnp.Chromosome != snp.Chromosome) || (Math.Abs(rutgerSnp.Position-snp.Position) > 10)) {
             //    Console.WriteLine("mismatched pos for " + snp.RsId + " - " + snp.Chromosome + ":" + snp.Position + " vs. " + rutgerSnp.Chromosome + ":" + rutgerSnp.Position);
             //    snp.cM = snps.ExtrapolateCentiMorganPosition(snp.Chromosome, snp.Position);
             //} else {
             //    snp.cM = snps[snp.RsId].cM;
             //}
             snp.Chromosome = rutgerSnp.Chromosome;
             snp.Position = rutgerSnp.Position;
         } 
         if ((rutgerSnp != null) && (rutgerSnp.cM > 0)) {
             snp.cM = rutgerSnp.cM;
         } else {
             snp.cM = snps.ExtrapolateCentiMorganPosition(snp.Chromosome, snp.Position);
         }
         if ((prevSnp != null) && (prevSnp.Chromosome == snp.Chromosome)
             && (prevSnp.cM > snp.cM)) {
             Console.WriteLine("cM out of sequence " + prevSnp.RsId + "-" + snp.RsId);
         }
         prevSnp = snp;
     }
     SnpFile.Write(refSnps, "RefSnps2.csv");
 }
예제 #2
0
        public static void ReadMatchWeights(SnpMap<MatchWeight> matchWeights, SnpCollection snps, string filename, 
            CancellationToken cancel, Progress progress) {
            if (matchWeights == null) throw new ArgumentNullException("The MatchWeights cannot be null.");
            if (snps == null) throw new ArgumentNullException("The SnpCollection cannot be null.");
            if (filename == null) throw new ArgumentNullException("filename cannot be null.");
            if (String.IsNullOrWhiteSpace(filename)) throw new ArgumentOutOfRangeException("filename cannot be empty.");

            using (StreamReader reader = new StreamReader(filename)) {
                long length = 0;
                if (progress != null) length = reader.BaseStream.Length;
                string line;
                string[] columns = new string[5];
                while ((line = reader.ReadLine()) != null) {
                    cancel.ThrowIfCancellationRequested();
                    if (line.Length > 0) {
                        line.FastSplit('\t', columns);
                        string rsId = columns[0];
                        string majorAllele = columns[1];
                        double majorWeight, minorWeight;
                        double.TryParse(columns[2], out majorWeight);
                        double.TryParse(columns[4], out minorWeight);
                        if (snps.Contains(rsId)) {
                            Snp snp = snps[rsId];
                            MatchWeight matchWeight = new MatchWeight(Convert.ToInt32(10*majorWeight), Convert.ToInt32(10*minorWeight));
                            matchWeights.Add(snp, matchWeight);
                        }
                    }
                    if (progress != null) progress.Set(reader.BaseStream.Position, length);
                }
            }
        }