public static void GenerateCleavageSiteFiles_Yang()
        {
            List <CleavageSite> sites = new List <CleavageSite>();

            string[] lines = FileExtension.ReadList(Config.WorkingFolder + "cleavage_sites.csv");
            Console.WriteLine($"Total Cleavage Sites:{lines.Length}");
            foreach (string line in lines)
            {
                var          arr  = line.Split('_');
                CleavageSite site = CleavageSite.Parse(line);
                sites.Add(site);
            }
            Console.WriteLine($"After filtered by clevage efficiency and reactivity:{sites.Count}");

            //Generate 4 files filtered by 4 degradome datasets.
            foreach (DegradomeType dType in EnumUtil.GetValues <DegradomeType>())
            {
                StringBuilder site_content_1 = new StringBuilder();
                StringBuilder site_content_3 = new StringBuilder();
                StringBuilder site_content_4 = new StringBuilder();

                foreach (CleavageSite site in sites)
                {
                    //if (site.Extendability < 50)
                    //{
                    //    break;
                    //}

                    float efficiency = Efficiency.GetEfficiency(site, dType);
                    if (efficiency > 0)
                    {
                        site_content_1.AppendLine(site.ToStringWithMiRNANames());
                    }
                    else if (Efficiency.HasEfficiency_21(site, dType))
                    {
                        site_content_3.AppendLine(site.ToStringWithMiRNANames());
                    }
                    else if (Efficiency.HasEfficiency_Gene(site, dType))
                    {
                        site_content_4.AppendLine(site.ToStringWithMiRNANames());
                    }
                }

                FileExtension.Save(site_content_1.ToString(), Config.WorkingFolder + "\\cleavage_sites_" + dType + "_1.csv");
                FileExtension.Save(site_content_3.ToString(), Config.WorkingFolder + "\\cleavage_sites_" + dType + "_3.csv");
                FileExtension.Save(site_content_4.ToString(), Config.WorkingFolder + "\\cleavage_sites_" + dType + "_4.csv");
            }
        }
Example #2
0
        public static void GenerateStructureFiles()
        {
            if (!Directory.Exists(Config.CsStrucFolder))
            {
                Directory.CreateDirectory(Config.CsStrucFolder);
            }

            foreach (DegradomeType dType in EnumUtil.GetValues <DegradomeType>())
            {
                string degDir = Config.CsStrucFolder + dType.ToString();
                if (!Directory.Exists(degDir))
                {
                    Directory.CreateDirectory(degDir);
                }

                string[] cleavageSiteSList = FileExtension.ReadList($"{Config.WorkingFolder}\\cleavage_site_{dType}.csv");
                foreach (int extend in new int[] { 25, 50 })
                {
                    int length = extend * 2 + 21;
                    //$"{dir}\\{length}
                    string lengthDir = $"{degDir}\\{length}";
                    if (!Directory.Exists(lengthDir))
                    {
                        Directory.CreateDirectory(lengthDir);
                    }
                    List <string> dotBrackets = new List <string>();
                    for (int i = 0; i < cleavageSiteSList.Length; i++)
                    {
                        if (string.IsNullOrWhiteSpace(cleavageSiteSList[i]))
                        {
                            continue;
                        }

                        CleavageSite site = CleavageSite.Parse(cleavageSiteSList[i]);


                        //Generate .seq file
                        int startAt = site.StartAt - 1 - extend;

                        //Check if the extended cleavage site is available
                        //(the start and ending points are legal)
                        if (startAt < 0)
                        {
                            Console.WriteLine(startAt);
                            continue;
                        }

                        int    endAt        = site.StartAt - 1 + extend + 21;
                        string fullSequence = Gene.GetSequence(site.Gene);
                        //check if the ending point is reasonable
                        if (endAt > fullSequence.Length)
                        {
                            Console.WriteLine(endAt);
                            continue;
                        }

                        string cleavageSiteSequence = fullSequence.Substring(startAt, endAt - startAt);
                        string seqFileContent       = $">{site.Gene}[{startAt},{endAt}]\r\n{cleavageSiteSequence.Replace("U", "T")}";
                        FileExtension.Save(seqFileContent, $"{degDir}\\{length}\\{i}.seq");

                        //generate the .shape file
                        GenerateShapeFile(site, startAt, endAt, $"{degDir}\\{length}\\{i}.shape");
                        //generate .db file
                        //Use ViennaRNA/RNAFold to do that.
                        //RNAFold--shape = ap2.shape < ap2.seq
                        string dotBracket = RnaFoldWrapper.Fold($"{degDir}\\{length}\\{i}.shape", $"{degDir}\\{length}\\{i}.seq");
                        dotBrackets.Add(dotBracket);
                        //availableCleavageSites.Add(cleavage_site_sList[i]);
                    }
                    FileExtension.SaveList($"{Config.CsStrucFolder}\\cs_structure_{length}_{dType}.txt", dotBrackets);
                }
            }
            GenerateRnaStructPlots();
        }
Example #3
0
        public static void GenerateCleavageSiteFiles()
        {
            List <CleavageSite> sites = new List <CleavageSite>();

            string[] lines = FileExtension.ReadList(Config.WorkingFolder + "cleavage_sites.csv");
            Console.WriteLine($"Total Cleavage Sites:{lines.Length}");
            foreach (string line in lines)
            {
                var          arr  = line.Split('_');
                CleavageSite site = CleavageSite.Parse(line);
                sites.Add(site);
            }
            Console.WriteLine($"After filtered by cleavage efficiency and reactivity:{sites.Count}");

            //Generate 4 files filtered by 4 degradome datasets.
            foreach (DegradomeType dType in EnumUtil.GetValues <DegradomeType>())
            {
                string site_content           = string.Empty;
                string efficiency_content     = string.Empty;
                string efficiency_log_content = string.Empty;
                string reactivity_content     = string.Empty;
                string reactivity_25_content  = string.Empty;
                string reactivity_50_content  = string.Empty;
                //string reactivity_75_content = string.Empty;
                //string reactivity_100_content = string.Empty;

                foreach (CleavageSite site in sites)
                {
                    if (site.Extendability < 50)
                    {
                        break;
                    }

                    //if the cleavage efficiency is zero,
                    //we can say that this is not a cleavage site.
                    //filter it out.
                    float efficiency = Efficiency.GetEfficiency(site, dType);
                    if (efficiency == 0)
                    {
                        continue;
                    }

                    site_content           += site.ToString() + "\n";
                    efficiency_content     += efficiency.ToString() + "\n";
                    efficiency_log_content += Math.Log(efficiency).ToString() + "\n";
                    for (int j = 0; j < 21; j++)
                    {
                        reactivity_content += Reactivity.GetReactivity(site.Gene, site.StartAt - 1 + j) + ",";
                    }

                    for (int j = 0 - 25; j < 21 + 25; j++)
                    {
                        reactivity_25_content += Reactivity.GetReactivity(site.Gene, site.StartAt - 1 + j) + ",";
                    }

                    for (int j = 0 - 50; j < 21 + 50; j++)
                    {
                        reactivity_50_content += Reactivity.GetReactivity(site.Gene, site.StartAt - 1 + j) + ",";
                    }

                    reactivity_content    = reactivity_content.TrimEnd(',') + "\n";
                    reactivity_25_content = reactivity_25_content.TrimEnd(',') + "\n";
                    reactivity_50_content = reactivity_50_content.TrimEnd(',') + "\n";
                }
                FileExtension.Save(site_content, Config.WorkingFolder + "\\cleavage_site_" + dType + ".csv");
                FileExtension.Save(efficiency_content, Config.WorkingFolder + "\\cs_efficiencies_" + dType + ".csv");
                FileExtension.Save(efficiency_log_content, Config.WorkingFolder + "\\cs_efficiencies_log_" + dType + ".csv");
                FileExtension.Save(reactivity_content, Config.WorkingFolder + "\\cs_reactivity_" + dType + ".csv");
                FileExtension.Save(reactivity_25_content, Config.WorkingFolder + "\\cs_reactivity_" + dType + "_25.csv");
                FileExtension.Save(reactivity_50_content, Config.WorkingFolder + "\\cs_reactivity_" + dType + "_50.csv");
                //FileExtension.Save(reactivity_75_content, Config.WorkingFoler + "\\cs_reactivity_" + dType + "_75.csv");
                //FileExtension.Save(reactivity_100_content, Config.WorkingFoler + "\\cs_reactivity_" + dType + "_100.csv");
            }
        }