Exemplo n.º 1
0
 static PhasedGenomeFile SimplePhase(string filename, GenomeFile gfile, SnpCollection refSnps) {
     Console.Write("Creating simple phased genome...");
     PhasedGenome phased = new PhasedGenome(gfile.Genome);
     Console.WriteLine("completed");
     PhasedGenomeFile pfile = new PhasedGenomeFile(GetPhasedFilename(filename));
     pfile.SetStandardComments();
     pfile.AddComment("## history");
     pfile.AddComment("## " + DateTime.Now.ToString() + " SimplePhase of " + phased.Count.ToString("#,##0") 
         + " homozygous SNPs (of " + gfile.Genome.Count.ToString("#,##0") + " total).");
     pfile.PhasedGenome = phased;
     return pfile;
 }
Exemplo n.º 2
0
 public static void AddHistory(PhasedGenomeFile pfile, GenomeFile gfile, int count, IList<Tuple<SegmentMatch, SegmentMatch>> segs) {
     DateTime now = DateTime.Now;
     pfile.AddComment("## " + DateTime.Now.ToString() + " MatchPhase added " + count.ToString("#,##0") + " phased heterozygous SNPs using " + gfile.Name + ".");
     if ((segs != null) && (segs.Count > 0)) {
         string filename = Path.Combine(Path.GetDirectoryName(pfile.Filename), pfile.Name + "HISTORY.csv");
         List<string> lines = new List<string>();
         if (!File.Exists(filename)) {
             lines.Add("date,time,source,chromosome,origStart,origEnd,origLen(cM),sides,usedStart,usedEnd,usedLen(cM),newlyPhasedCount");
         }
         foreach (var tup in segs) {
             var match = tup.Item1;
             var phased = tup.Item2;
             string line = "\"" + now.ToShortDateString() + "\",\"" + now.ToShortTimeString() + "\",\"" + gfile.Name + "\","
                 + Snp.ChromosomeToString(match.StartSnp.Chromosome) + "," + match.StartSnp.Position.ToString() + ","
                 + match.EndSnp.Position.ToString() + "," + match.CmLength.ToString("#0.00") + "," 
                 + match.MatchKind.ToString() + "," + phased.StartSnp.Position.ToString() + "," 
                 + phased.EndSnp.Position.ToString() + "," + phased.CmLength.ToString("#0.00") + "," 
                 + phased.PhasedSnpCount.ToString();
             lines.Add(line);
         }
         File.AppendAllLines(filename, lines);
     }
 }
Exemplo n.º 3
0
 public static void WriteGenone(GenomeFile genomeFile) {
     genomeFile.Extension = "txt";
     Console.Write("Writing genome " + genomeFile.Name + "...");
     genomeFile.Write(true, Configuration.UnphasedChar, new System.Threading.CancellationToken(), null);
     Console.WriteLine("completed");
 }
Exemplo n.º 4
0
 public static GenomeFile ReadGenome(SnpCollection refSnps, string filename) {
     GenomeFile result = new GenomeFile(filename);
     result.Genome = new Genome(1, 23);
     Console.Write("Reading genome " + result.Name + "...");
     result.Read(refSnps, new System.Threading.CancellationToken(), null);
     Console.WriteLine("completed");
     return result;
 }
Exemplo n.º 5
0
        public static void SplitClone(string[] args) {
            if (args.Length != 2) {
                Console.WriteLine("invalid arguments");
                ShowHelpSplitClone();
                return;
            }
            SnpCollection refSnps = ReadRefSnps();
            string path = Configuration.GenomePath;
            string file1 = Path.Combine(path, args[1]);
            var full = ReadGenome(refSnps, file1);
            var phased1 = ReadPhasedGenome(refSnps, file1);
            if (phased1 == null) {
                phased1 = SimplePhase(file1, full, refSnps);
                WritePhasedGenome(phased1);
            }

            Console.Write("Splitting and cloning phased genome...");
            var result = phased1.PhasedGenome.Split(true);
            Console.WriteLine("completed");

            var split = new GenomeFile(phased1.Filename.Replace("phased-", "phasedAA-"));
            split.Genome = result.Item1;
            split.AddComment("# this file is the phased A side split and cloned from " + phased1.Name);
            WriteGenone(split);
            split = new GenomeFile(phased1.Filename.Replace("phased-", "phasedBB-"));
            split.Genome = result.Item2;
            split.AddComment("# this file is the phased B side split and cloned from " + phased1.Name);
            WriteGenone(split);            
        }
Exemplo n.º 6
0
        static void Match(string[] args) {
            if (args.Length < 4) {
                Console.WriteLine("invalid arguments");
                ShowHelpMatch();
                return;
            }
            SnpCollection refSnps = ReadRefSnps();
            string path = Configuration.GenomePath;
            string lastFilename = Path.Combine(path, args[args.Length - 1]);
            var testGenomeFile = new GenomeFile(lastFilename);
            if (File.Exists(testGenomeFile.Filename)) {
                try {
                    testGenomeFile.Read(refSnps, new System.Threading.CancellationToken(), null);
                    if (testGenomeFile.Genome.Count > 0) {
                        int i = 1;
                        while (File.Exists(Path.Combine(path, "MatchResults(" + i + ").csv"))) i++;
                        string filename = Path.Combine(path, "MatchResults(" + i + ").csv");
                        Console.WriteLine("** no filename was specified for the results");
                        Console.WriteLine("** results will be written to " + filename);
                        string[] args2 = new string[args.Length + 1];
                        for (int k = 0; k < args.Length; k++) args2[k] = args[k];
                        args = args2;
                        args[args.Length - 1] = filename;
                    }
                }
                catch { }
            }
            string[] filenames = new string[args.Length - 2];
            for (int i = 0; i < filenames.Length; i++) {
                filenames[i] = args[i + 1];
            }
            List<Tuple<string, string, SegmentMatch>> results = new List<Tuple<string, string, SegmentMatch>>();
            for (int i = 0; i < filenames.Length -1; i++) {
                string file1 = Path.Combine(path, filenames[i]);
                var phased1 = ReadPhasedGenome(refSnps, file1);
                if (phased1 == null) {
                    var full = ReadGenome(refSnps, file1);
                    phased1 = SimplePhase(file1, full, refSnps);
                    WritePhasedGenome(phased1);
                }
                for (int j = i + 1; j < filenames.Length; j++) {
                    string file2 = Path.Combine(path, filenames[j]);
                    var phased2 = ReadPhasedGenome(refSnps, file2);
                    if (phased2 == null) {
                        var full = ReadGenome(refSnps, file2);
                        phased2 = SimplePhase(file2, full, refSnps);
                        WritePhasedGenome(phased2);
                    }

                    Console.Write("Finding matching segments...");
                    var result = phased1.PhasedGenome.MatchingSegments(phased2.PhasedGenome, Configuration.MaxErrorsToStitch, 
                        Configuration.SegmentMinPhasedSnpCount, Configuration.SegmentMinCmLength, 
                        Configuration.StitchMinPhasedSnpCount, Configuration.StitchMinCmLength);
                    if (result.Count > 0) {
                        foreach (var seg in result) results.Add(new Tuple<string, string, SegmentMatch>(phased1.Name, phased2.Name, seg));
                    } else {
                        results.Add(new Tuple<string, string, SegmentMatch>(phased1.Name, phased2.Name, default(SegmentMatch)));
                    }
                    Console.WriteLine("completed");
                }
            }
            Console.Write("Writing match results to " + args[3] + "...");
            WriteSegmentMatches(results, Path.Combine(path, args[args.Length - 1]));
            Console.WriteLine("completed");
        }