Example #1
0
        /// <summary>
        /// Converts a gene model file (GTF?) to a BED12 file with all 12 columns sometimes required of a BED file.
        ///
        /// see https://gist.github.com/gireeshkbogu/f478ad8495dca56545746cd391615b93
        ///
        /// </summary>
        /// <param name="spritzDirectory"></param>
        /// <param name="filteredGeneModelGtfGffPath"></param>
        /// <returns></returns>
        public static string Gtf2Bed12(string spritzDirectory, string analysisDirectory, string filteredGeneModelGtfGffPath, string genomeFastaPath)
        {
            string geneModelGtf = filteredGeneModelGtfGffPath;

            if (Path.GetExtension(filteredGeneModelGtfGffPath).StartsWith(".gff"))
            {
                CufflinksWrapper.GffToGtf(spritzDirectory, analysisDirectory, filteredGeneModelGtfGffPath, out geneModelGtf);
            }
            string genePredPath    = Path.Combine(Path.GetDirectoryName(geneModelGtf), Path.GetFileNameWithoutExtension(geneModelGtf) + ".genePred");
            string bed12Path       = Path.Combine(Path.GetDirectoryName(geneModelGtf), Path.GetFileNameWithoutExtension(geneModelGtf) + ".bed12");
            string sortedBed12Path = Path.Combine(Path.GetDirectoryName(geneModelGtf), Path.GetFileNameWithoutExtension(geneModelGtf) + ".sorted.bed12");

            WrapperUtility.GenerateAndRunScript(WrapperUtility.GetAnalysisScriptPath(analysisDirectory, "Bed12FaidxSortConversion.bash"), new List <string>
            {
                "gtfToGenePred " + WrapperUtility.ConvertWindowsPath(geneModelGtf) + " " + WrapperUtility.ConvertWindowsPath(genePredPath),
                "genePredToBed " + WrapperUtility.ConvertWindowsPath(genePredPath) + " " + WrapperUtility.ConvertWindowsPath(bed12Path),
                "bedtools sort -faidx " + WrapperUtility.ConvertWindowsPath(genomeFastaPath + ".fai") + " -i " + WrapperUtility.ConvertWindowsPath(bed12Path) + " > " + WrapperUtility.ConvertWindowsPath(sortedBed12Path),
            }).WaitForExit();
            return(sortedBed12Path);
        }
Example #2
0
        /// <summary>
        /// Converts a gene model file (GTF?) to a BED12 file with all 12 columns sometimes required of a BED file.
        ///
        /// see https://gist.github.com/gireeshkbogu/f478ad8495dca56545746cd391615b93
        ///
        /// </summary>
        /// <param name="spritzDirectory"></param>
        /// <param name="geneModelGtfOrGff"></param>
        /// <returns></returns>
        public static string GffOrGtf2Bed12(string spritzDirectory, string analysisDirectory, string geneModelGtfOrGff)
        {
            string geneModelGtf = geneModelGtfOrGff;

            if (Path.GetExtension(geneModelGtfOrGff).StartsWith(".gff"))
            {
                CufflinksWrapper.GffToGtf(spritzDirectory, analysisDirectory, geneModelGtfOrGff, out geneModelGtf);
            }
            string genePredPath    = Path.Combine(Path.GetDirectoryName(geneModelGtf), Path.GetFileNameWithoutExtension(geneModelGtf) + ".genePred");
            string bed12Path       = Path.Combine(Path.GetDirectoryName(geneModelGtf), Path.GetFileNameWithoutExtension(geneModelGtf) + ".bed12");
            string sortedBed12Path = Path.Combine(Path.GetDirectoryName(geneModelGtf), Path.GetFileNameWithoutExtension(geneModelGtf) + ".sorted.bed12");

            WrapperUtility.GenerateAndRunScript(WrapperUtility.GetAnalysisScriptPath(analysisDirectory, "Bed12conversion.bash"), new List <string>
            {
                // Note, there is a gff3ToGenePred program. Could test and replace that here for gff3 files.
                "gtfToGenePred " + WrapperUtility.ConvertWindowsPath(geneModelGtf) + " " + WrapperUtility.ConvertWindowsPath(genePredPath),
                "genePredToBed " + WrapperUtility.ConvertWindowsPath(genePredPath) + " " + WrapperUtility.ConvertWindowsPath(bed12Path),
                "sort -k1,1 -k2,2n " + WrapperUtility.ConvertWindowsPath(bed12Path) + " > " + WrapperUtility.ConvertWindowsPath(sortedBed12Path),
            }).WaitForExit();
            return(sortedBed12Path);
        }