Exemplo n.º 1
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.º 2
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");
        }