コード例 #1
0
        protected void SendBAMs(List <string> fNames)
        {
            AllBAMPairs.Clear();
            MainData.LoadedSeqs        = 0;
            ProgramState.LoadedSamples = false;
            ProgramState.BAMLoadLock   = false;

            foreach (string st in fNames)
            {
                MainData.UpdateLog("Reading " + MainData.MainWindow.MaxLenString(st, 20) + " to Sample ID -- \"" + ID + "\" -- ", true);
                if (AppSettings.Loading.LOAD_SEQ_NAMES.Item)
                {
                    LoadBAMNameFile(st);
                }
                else
                {
                    LoadBAMFile(st);
                }
            }
            if (AllBAMPairs.Count > 0)
            {
                HasBAM = true;
            }

            MainData.UpdateLog("Assigning -- \"" + ID + "\" -- sample reads to all annotated regions..", true);
            MainData.Genome.SendReads(AllBAMPairs);
            MainData.UpdateLog("Assignment of: " + MainData.LoadedSeqs.ToString() + " seqs complete", true);
            ProgramState.LoadedSamples = true;
            ProgramState.BAMLoadLock   = true;
            AllBAMPairs.Clear();
        }
コード例 #2
0
        protected void OnSave(object sender, EventArgs e)
        {
            bool   success = true;
            double x, y;

            model.Axes [0].Title = xAxisEntry.Text;
            model.Axes [1].Title = yAxisEntry.Text;
            model.Title          = titleEntry.Text;

            if (!double.TryParse(xScaleEntry.Text, out x))
            {
                success = false;
            }
            if (!double.TryParse(yScaleEntry.Text, out y))
            {
                success = false;
            }
            if (fileEntry.Text.Length < 2)
            {
                success = false;
            }

            if (!success)
            {
                MainData.ShowMessageWindow("Unable to verify field entries, x & y are numbers, and you need a file location!", false);
            }
            else
            {
                SaveToPdf(fileEntry.Text, x, y);
                MainData.UpdateLog("Success!\nSaved Pdf to: " + fileEntry.Text, false);
                this.Destroy();
            }
        }
コード例 #3
0
        protected void LoadBAMNameFile(string fileName)
        {
            int count = 0;

            using (StreamReader st = new StreamReader(fileName)) {
                string line = "";
                while ((int)'@' == st.Peek())
                {
                    st.ReadLine();
                }
                while ((line = st.ReadLine()) != null)
                {
                    string[] spstrs = line.Split('\t');
                    if (spstrs [2].Length > 2 && spstrs.Length >= 10)
                    {
                        int      start = int.Parse(spstrs [3]);
                        NameRead sq    = new NameRead(this, start, spstrs [9].Length + start, spstrs[0]);
                        AllBAMPairs.Add(new SeqScaffPair(spstrs [2], sq));

                        count++;
                        if (count % 1000000 == 0)
                        {
                            int tot = count / 1000000;
                            MainData.UpdateLog("Read " + tot + "M seqs from " + MainData.MainWindow.MaxLenString(fileName, 20), true);
                        }
                    }
                }
            }
            //Parallel.ForEach(lines, x =>
            //	{
            //		ProcessLines(x);
            //	});
        }
コード例 #4
0
ファイル: Genome.cs プロジェクト: OliverCardiff/Renoo
        public void LoadGenomeLongSeq(string _fileName)
        {
            bool lite = AppSettings.Loading.GEN_LITE_LOAD.Item;

            FileName = _fileName;
            Scaffolds.Clear();

            long   count    = 0;
            string line     = "";
            string sequence = "";
            string id       = "";
            //long modulo = MainData.ScanFileForModulo (_fileName, 10);
            long nextMark      = 50000000;
            long markIncrement = 50000000;
            int  markCnt       = 0;

            count = 0;

            MainData.UpdateLog("Reading...", true);

            using (StreamReader sr = new StreamReader(_fileName)) {
                while (!sr.EndOfStream)
                {
                    line = sr.ReadLine();
                    if (line.Length < 3)
                    {
                        continue;
                    }
                    else if (line.StartsWith(">"))
                    {
                        id = line.TrimStart('>');
                        GENApplyOptionsToID(ref id);
                    }
                    else
                    {
                        sequence = line;

                        Scaffolds.Add(id, (new Scaffold(id, ref sequence, lite)));
                        count += sequence.Length;
                    }
                    if (count > nextMark)
                    {
                        markCnt++;
                        nextMark += markIncrement;
                        MainData.UpdateLog("Read " + (markCnt * 50).ToString() + " mega-bases from genome..", true);
                    }
                }
            }
            long finalCnt = count / 1000000;

            MainData.UpdateLog("Read " + finalCnt.ToString() + " mega-bases in total.", true);
        }
コード例 #5
0
        public static long ScanFileForModulo(string fileName, int division)
        {
            int count = 0;

            MainData.UpdateLog("Scanning " + ShortFileName(fileName) + "...", true);
            using (StreamReader sr = new StreamReader(fileName)) {
                while ((sr.ReadLine()) != null)
                {
                    count++;
                }
            }
            return(count / division);
        }
コード例 #6
0
        private static void RunAndWait <T>(List <Thread> lt, List <T> Content)
        {
            int tmax = AppSettings.Processing.MAX_THREADS.Item;

            MainData.UpdateLog("Running func with " + tmax + " threads...", true);
            int it = 0;

            foreach (Thread t in lt)
            {
                t.Start((object)Content[it]);
                it++;
            }
            foreach (var thread in lt)
            {
                thread.Join();
            }
            lt.Clear();
            Content.Clear();
        }
コード例 #7
0
        protected static void LoadAllVars()
        {
            AllVarPairs.Clear();
            MainData.LoadedVars          = 0;
            ProgramState.LoadedVariants  = false;
            ProgramState.VariantLoadLock = false;

            foreach (KeyValuePair <string, BioSample[]> kvp in LatestVarColIndexed)
            {
                LoadVarFile(kvp.Key, kvp.Value, IsGenotypedNames [kvp.Key]);
            }

            MainData.UpdateLog("Assigning Variants to annotation elements..", true);
            MainData.Genome.SendVars(AllVarPairs);
            MainData.UpdateLog("Assignment of: " + MainData.LoadedVars.ToString() + " variants complete", true);

            ProgramState.LoadedVariants  = true;
            ProgramState.VariantLoadLock = true;
            hasVarSomethingToLoad        = false;
            AllVarPairs.Clear();
        }
コード例 #8
0
        protected static void LoadAllFKPMS()
        {
            AllFKPMS.Clear();
            MainData.LoadedFKPM       = 0;
            ProgramState.LoadedFPKM   = false;
            ProgramState.FKPMLoadLock = false;

            foreach (KeyValuePair <string, BioSample[]> kvp in LatestFKPMColIndexed)
            {
                LoadFKPMFile(kvp.Key, kvp.Value);
            }

            MainData.UpdateLog("Assigning FKPM scores to genes..", true);
            MainData.Genome.SendFKPMS(AllFKPMS);
            MainData.UpdateLog("Assignment of: " + MainData.LoadedFKPM.ToString() + " fkpm scores complete", true);

            ProgramState.LoadedFPKM   = true;
            ProgramState.FKPMLoadLock = true;
            hasFKPMSomethingToLoad    = false;
            AllFKPMS.Clear();
        }
コード例 #9
0
        protected static void LoadVarFile(string fName, BioSample [] samps, bool genotyped)
        {
            char[] seps  = { '/', '|' };
            int    count = 0;

            using (StreamReader sr = new StreamReader(fName)) {
                while ((int)'#' == sr.Peek())
                {
                    sr.ReadLine();
                }

                string[] spstrs;
                string   line;

                while ((line = sr.ReadLine()) != null)
                {
                    spstrs = line.Split('\t');

                    if (spstrs [6] == "PASS")
                    {
                        Variant v;

                        string[] sps = spstrs [4].Split(',');
                        if (sps.Length == 1)
                        {
                            v = new Variant(int.Parse(spstrs [1]), spstrs [3], spstrs [4]);
                        }
                        else if (sps.Length == 2)
                        {
                            v = new Variant(int.Parse(spstrs [1]), spstrs [3], sps [0], sps [1]);
                        }
                        else
                        {
                            v = new Variant(int.Parse(spstrs [1]), spstrs [3], sps [0], sps [1], sps [2]);
                        }

                        if (genotyped)
                        {
                            int genLen = spstrs.Length;
                            int stInd  = 9;

                            for (int i = stInd; i < genLen; i++)
                            {
                                bool parsed = true;

                                string[] sps2 = spstrs [i].Split(':');
                                string[] sps3 = sps2 [0].Split(seps);
                                int      ma   = 0;
                                int      al   = 0;
                                if (!int.TryParse(sps3 [0], out ma))
                                {
                                    parsed = false;
                                }
                                if (sps3.Length > 1)
                                {
                                    if (!int.TryParse(sps3 [1], out al))
                                    {
                                        parsed = false;
                                    }
                                }
                                if (parsed)
                                {
                                    SampleVariant s = new SampleVariant(ma, al, samps [i - stInd]);
                                    v.AddSampleVars(s);
                                }
                            }
                        }

                        AllVarPairs.Add(new VarScaffPair(spstrs [0], v));

                        count++;
                        if (count % 100000 == 0)
                        {
                            int tot = count / 100000;
                            MainData.UpdateLog("Read " + tot + "00K variants from " + MainData.MainWindow.MaxLenString(fName, 20), true);
                        }
                    }
                }
            }
        }
コード例 #10
0
        public static void WriteDataFile(string fileName, NumericalText nt)
        {
            if (((nt.Data != null) && (nt.Data.Count > 0)) || ((nt.Tags != null) && (nt.Tags.Count > 0)))
            {
                int                 useLen         = Math.Min(nt.Titles.Count, (nt.Data.Count + nt.Tags.Count));
                int                 dataLen        = nt.Data [0].Count;
                List <int>          counts         = new List <int> ();
                List <int>          currentIndexes = new List <int> ();
                List <PrintOutNext> printTypes     = new List <PrintOutNext> ();

                if (nt.Tags != null)
                {
                    int tagInd = 0;
                    foreach (List <string> sl in nt.Tags)
                    {
                        counts.Add(sl.Count - 1);
                        printTypes.Add(PrintOutNext.Tag);
                        dataLen = Math.Max(dataLen, sl.Count);
                        currentIndexes.Add(tagInd);
                        tagInd++;
                    }
                }
                if (nt.Data != null)
                {
                    int datInd = 0;
                    foreach (List <Double> ld in nt.Data)
                    {
                        counts.Add(ld.Count - 1);
                        printTypes.Add(PrintOutNext.Data);
                        dataLen = Math.Max(dataLen, ld.Count);
                        currentIndexes.Add(datInd);
                        datInd++;
                    }
                }

                using (StreamWriter sw = new StreamWriter(fileName)) {
                    for (int i = 0; i < useLen; i++)
                    {
                        if (i > 0)
                        {
                            sw.Write("\t");
                        }
                        sw.Write(nt.Titles [i]);
                    }
                    sw.Write("\n");

                    for (int j = 0; j < dataLen; j++)
                    {
                        for (int i = 0; i < useLen; i++)
                        {
                            if (i > 0)
                            {
                                sw.Write("\t");
                            }
                            if (counts [i] >= j)
                            {
                                if (printTypes [i] == PrintOutNext.Data)
                                {
                                    sw.Write(nt.Data [currentIndexes[i]] [j]);
                                }
                                else
                                {
                                    sw.Write(nt.Tags [currentIndexes [i]] [j]);
                                }
                            }
                            else
                            {
                                sw.Write("x");
                            }
                        }
                        sw.Write("\n");
                    }
                }
                MainData.UpdateLog("Saved " + MainData.MainWindow.MaxLenString(fileName, 20), false);
            }
            else
            {
                MainData.ShowMessageWindow("There isn't any data there to save!", false);
            }
        }
コード例 #11
0
ファイル: Genome.cs プロジェクト: OliverCardiff/Renoo
        public void LoadGFF3(string fileName)
        {
            string idTag   = AppSettings.Loading.GFF3_ID_TAG.Item;
            int    tagSize = idTag.Length;

            string line      = "";
            string parentTag = "arent=";
            int    pTagSize  = parentTag.Length;
            int    count     = 0;
            long   modulo    = MainData.ScanFileForModulo(fileName, 5);
            long   lineCount = modulo * 5;

            MainData.UpdateLog("Reading... ", true);

            char[] spChar = { '\t' }; char[] spChar2 = { ';' };

            using (StreamReader sr = new StreamReader(fileName)) {
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.Length > 10)
                    {
                        string[] spstr  = line.Split(spChar, 10);
                        string[] spstr2 = spstr [8].Split(spChar2, 20);
                        string   ID     = "";
                        string   pID    = "";
                        foreach (string st in spstr2)
                        {
                            if (st.Contains(idTag))
                            {
                                ID = st;
                                break;
                            }
                        }
                        foreach (string st in spstr2)
                        {
                            if (st.Contains(parentTag))
                            {
                                pID = st;
                                break;
                            }
                        }
                        ID = ID.Substring(tagSize);
                        GFF3ApplyOptionsToID(ref ID);
                        if (pID != "")
                        {
                            GFF3ApplyOptionsToID(ref pID);
                        }

                        Sense sn = Sense.Sense;
                        if (spstr [6].Equals("-"))
                        {
                            sn = Sense.AntiSense;
                        }
                        else if (spstr [6].Equals("."))
                        {
                            sn = Sense.None;
                        }

                        string nameOfType = ID + "#" + spstr [2] + "#" + pID;;
                        int    sta, end;
                        bool   A = int.TryParse(spstr [3], out sta);
                        bool   B = int.TryParse(spstr [4], out end);
                        if (A && B)
                        {
                            if (Scaffolds.ContainsKey(spstr [0]))
                            {
                                Scaffolds [spstr [0]].SendComponent(nameOfType, sta, end, sn);
                            }
                            else
                            {
                                throw new Exception("Gff3 references scaffold not found in genome!");
                            }
                        }
                    }
                    count++;
                    if (count % modulo == 0)
                    {
                        long perc = (long)(((float)count / (float)lineCount) * 100);
                        MainData.UpdateLog("Read " + perc + "% of gff3..", true);
                    }
                }
            }
            if (AppSettings.Genes.GENERATE_ANY_PROMO.Item || AppSettings.Genes.GENERATE_FLANK3.Item)
            {
                MainData.UpdateLog("Generating GFF3 additional elements as described in Settings -> Genes", true);
                foreach (KeyValuePair <string, Scaffold> kvp in Scaffolds)
                {
                    kvp.Value.RunGenePostLoad();
                }
            }
        }