2024-09-08 02:48:54 +08:00
|
|
|
#!/usr/bin/env rdmd
|
|
|
|
|
|
|
|
import std.stdio;
|
|
|
|
import std.file;
|
|
|
|
import std.process;
|
|
|
|
import std.algorithm;
|
|
|
|
import std.conv;
|
|
|
|
import std.array;
|
|
|
|
import std.path;
|
2024-09-09 01:19:42 +08:00
|
|
|
import std.parallelism;
|
2024-09-09 09:33:50 +08:00
|
|
|
import std.regex;
|
2024-09-08 02:48:54 +08:00
|
|
|
|
|
|
|
void show_help(string pkgver) {
|
|
|
|
writeln("\t\t\t\t\t\033[0;47;31mR\033[0m\033[0;47;92mG\033[0m\033[0;47;94mB\033[0m\033[0;47m \033[0m\033[0;47;33mE\033[0m\033[0;47;94mP\033[0m\033[0;47;33mP\033[0m
|
|
|
|
\t\t\tReference Genome based Exon Phylogeny Pipeline
|
|
|
|
Version: ", pkgver, "
|
|
|
|
License: GPL-2.0-only
|
|
|
|
Author: Guoyi Zhang
|
2024-09-09 09:45:55 +08:00
|
|
|
-c\t--config\tconfig file for software path (optional)
|
2024-09-09 01:19:42 +08:00
|
|
|
-g\t--genes\t\tgene file path (optional, if -r is specified)
|
|
|
|
-f\t--functions\tfunctions type (optional): all clean map
|
|
|
|
\t \tpostmap varcall consen align
|
2024-09-08 02:48:54 +08:00
|
|
|
-h\t--help\t\tshow this information
|
|
|
|
-l\t--list\t\tlist file path
|
|
|
|
-m\t--memory\tmemory settings (optional, default 16 GB)
|
|
|
|
-r\t--reference\treference genome path
|
|
|
|
-t\t--threads\tthreads setting (optional, default 8 threads)
|
2024-09-09 09:45:55 +08:00
|
|
|
--fastp\t\tFastp path (optional)
|
|
|
|
--bowtie2\t\tBowtie2 path (optional)
|
|
|
|
--samtools\t\tSamtools path (optional)
|
|
|
|
--bcftools\t\tBcftools path (optional)
|
|
|
|
--macse\t\tMacse jarfile path (optional)
|
|
|
|
--trimal\t\tTrimal path (optional)
|
2024-09-09 10:25:32 +08:00
|
|
|
--spades\t\tSpades python path (optional)
|
2024-09-09 01:19:42 +08:00
|
|
|
for example: ./RGBEPP -f all -l list -t 8 -r reference.fasta \n");
|
2024-09-08 02:48:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void createDir(string path) {
|
|
|
|
if (!exists(path)) {
|
|
|
|
mkdir(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-09 01:19:42 +08:00
|
|
|
void executeCommand(string[] cmd) {
|
2024-09-08 02:48:54 +08:00
|
|
|
auto process = spawnProcess(cmd);
|
|
|
|
|
|
|
|
if (wait(process) != 0) {
|
|
|
|
writeln("Error executing command: ", cmd.join(" "));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void executeCommandPipe(string[][] cmds) {
|
|
|
|
|
|
|
|
Pid[] pids;
|
|
|
|
scope(exit) {
|
|
|
|
foreach (pid; pids) {
|
|
|
|
wait(pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// pipe init
|
|
|
|
auto temp_pipe = pipe();
|
|
|
|
// process first
|
|
|
|
pids ~= spawnProcess(cmds[0], stdin, temp_pipe.writeEnd);
|
|
|
|
|
|
|
|
// process cmd2 ~ cmdN-1
|
|
|
|
for (int i = 1; i < cmds.length - 1; i++) {
|
|
|
|
auto new_pipe = pipe(); // create next pipe
|
|
|
|
pids ~= spawnProcess(cmds[i], temp_pipe.readEnd, new_pipe.writeEnd);
|
|
|
|
temp_pipe = new_pipe; // update the pipe
|
|
|
|
}
|
|
|
|
|
|
|
|
// process final, output to stdout
|
|
|
|
pids ~= spawnProcess(cmds[$-1], temp_pipe.readEnd, stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
string[] readArrFromFile(string filename) {
|
|
|
|
string[] arr;
|
|
|
|
|
|
|
|
try {
|
|
|
|
arr = filename.readText().splitter.array;
|
|
|
|
} catch (FileException ex) {
|
|
|
|
writeln("Error reading file: ", ex.msg);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
writeln("Exception: ", ex.msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
string getBaseName(string ARG_R){
|
|
|
|
string ARG_R_extension = extension(ARG_R); // get extension
|
|
|
|
string baseNameRef = baseName(ARG_R, ARG_R_extension); //rm dir and extension
|
|
|
|
return baseNameRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
string[] getRef(string ARG_R, string DirMap){
|
|
|
|
string baseNameRef = getBaseName(ARG_R);
|
|
|
|
string ARG_R_index = DirMap ~ "/index/" ~ baseNameRef; // bt2_index_base
|
|
|
|
string ARG_R_refer = ARG_R_index ~ ".fasta"; //reference_in fasta file
|
|
|
|
string[] Refs = [ARG_R_index, ARG_R_refer];
|
|
|
|
return Refs;
|
|
|
|
}
|
|
|
|
|
2024-09-09 00:04:36 +08:00
|
|
|
string[] getARG_G(string ARG_R){
|
|
|
|
string[] ARG_G;
|
|
|
|
// if ARG_G is empty
|
|
|
|
if (ARG_G.length == 0) {
|
|
|
|
auto file = File(ARG_R, "r");
|
|
|
|
ARG_G = file.byLine
|
|
|
|
.filter!(line => line.startsWith(">")) // flitering
|
|
|
|
.map!(line => line[1..$].idup) // convert to word
|
|
|
|
.array;
|
|
|
|
}
|
|
|
|
return ARG_G;
|
|
|
|
}
|
|
|
|
|
2024-09-09 10:25:32 +08:00
|
|
|
string getValueFromConfig(string file, string key) {
|
|
|
|
string content = readText(file);
|
|
|
|
string value;
|
|
|
|
auto regex = regex(key ~ r"\s*=\s*(.+)");
|
|
|
|
|
|
|
|
foreach (line; content.splitter("\n")) {
|
|
|
|
if (auto match = matchFirst(line, regex)) {
|
|
|
|
value = match.captures[1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void processQcTrim(string[] ARG_L, int ARG_T, string DirRaw, string DirQcTrim, string PathFastp) {
|
2024-09-08 02:48:54 +08:00
|
|
|
// Prepare directory
|
|
|
|
createDir(DirQcTrim);
|
2024-09-09 09:33:50 +08:00
|
|
|
writeln("QcTrimming::Start");
|
2024-09-08 02:48:54 +08:00
|
|
|
foreach (string file; ARG_L) {
|
|
|
|
string baseName = getBaseName(file);
|
|
|
|
string inputFileR1 = DirRaw ~ "/" ~ baseName ~ "_R1.fastq.gz";
|
|
|
|
string inputFileR2 = DirRaw ~ "/" ~ baseName ~ "_R2.fastq.gz";
|
|
|
|
string outputFileR1 = DirQcTrim ~ "/" ~ baseName ~ "_R1.fastq.gz";
|
|
|
|
string outputFileR2 = DirQcTrim ~ "/" ~ baseName ~ "_R2.fastq.gz";
|
|
|
|
string jsonFile = DirQcTrim ~ "/" ~ baseName ~ ".json";
|
|
|
|
string htmlFile = DirQcTrim ~ "/" ~ baseName ~ ".html";
|
|
|
|
|
|
|
|
// Perform quality control and trimming using external program `fastp`
|
2024-09-09 09:33:50 +08:00
|
|
|
string[] cmdQcTrim = [PathFastp, "-i", inputFileR1, "-I", inputFileR2,
|
2024-09-08 02:48:54 +08:00
|
|
|
"-o", outputFileR1, "-O", outputFileR2,
|
|
|
|
"-j", jsonFile, "-h", htmlFile,
|
|
|
|
"-w", ARG_T.to!string];
|
2024-09-09 09:33:50 +08:00
|
|
|
executeCommand(cmdQcTrim);
|
2024-09-08 02:48:54 +08:00
|
|
|
}
|
2024-09-09 09:33:50 +08:00
|
|
|
writeln("QcTrimming::End");
|
2024-09-08 02:48:54 +08:00
|
|
|
}
|
|
|
|
|
2024-09-09 09:33:50 +08:00
|
|
|
void processMapping(string[] ARG_L, string ARG_R, int ARG_T, string DirQcTrim, string DirMap, string PathBowtie2, string PathSamtools) {
|
2024-09-08 02:48:54 +08:00
|
|
|
writeln("Mapping::Start");
|
|
|
|
|
|
|
|
// Prepare directory
|
|
|
|
createDir(DirMap);
|
|
|
|
|
|
|
|
createDir(DirMap ~ "/index");
|
2024-09-09 09:33:50 +08:00
|
|
|
string PathBowtie2_build = PathBowtie2 ~ "-build";
|
2024-09-08 02:48:54 +08:00
|
|
|
string[] Refs = getRef(ARG_R, DirMap);
|
|
|
|
string ARG_R_index = Refs[0]; // bt2_index_base
|
|
|
|
string ARG_R_refer = Refs[1]; //reference_in fasta file
|
|
|
|
|
|
|
|
copy(ARG_R, ARG_R_refer);
|
|
|
|
|
2024-09-09 09:33:50 +08:00
|
|
|
string[] cmdBuildDB = [PathBowtie2_build, "--threads", ARG_T.to!string, ARG_R_refer, ARG_R_index];
|
2024-09-08 02:48:54 +08:00
|
|
|
executeCommand(cmdBuildDB);
|
|
|
|
|
|
|
|
foreach (string file; ARG_L) {
|
|
|
|
string baseName = baseName(file, ".fastq.gz");
|
|
|
|
string outputBam = DirMap ~ "/" ~ baseName ~ ".bam";
|
|
|
|
string inputFileR1 = DirQcTrim ~ "/" ~ baseName ~ "_R1.fastq.gz";
|
|
|
|
string inputFileR2 = DirQcTrim ~ "/" ~ baseName ~ "_R2.fastq.gz";
|
|
|
|
|
|
|
|
// Perform mapping using Bowtie2 and converted to Bam using samtools
|
2024-09-09 09:33:50 +08:00
|
|
|
string[] cmdMap = [PathBowtie2, "-x", ARG_R_index, "-1", inputFileR1, "-2", inputFileR2,
|
2024-09-08 02:48:54 +08:00
|
|
|
"-p", ARG_T.to!string];
|
2024-09-09 09:33:50 +08:00
|
|
|
string[] cmdSam2Bam = [PathSamtools, "view", "-bS", "-@", ARG_T.to!string, "-o", outputBam];
|
2024-09-08 02:48:54 +08:00
|
|
|
|
|
|
|
executeCommandPipe([cmdMap, cmdSam2Bam]);
|
|
|
|
|
|
|
|
}
|
|
|
|
writeln("Mapping::End");
|
|
|
|
}
|
|
|
|
|
2024-09-09 09:33:50 +08:00
|
|
|
void processPostMap(string[] ARG_L, int ARG_T, string DirMap, string DirBam, string PathSamtools) {
|
2024-09-08 02:48:54 +08:00
|
|
|
|
|
|
|
createDir(DirBam);
|
|
|
|
writeln("PostMapping::Start");
|
|
|
|
|
|
|
|
foreach (string file; ARG_L) {
|
|
|
|
string baseName = getBaseName(file);
|
|
|
|
string inputBam = DirMap ~ "/" ~ baseName ~ ".bam";
|
|
|
|
string outputBam = DirBam ~ "/" ~ baseName ~ ".bam";
|
|
|
|
|
|
|
|
// Convert SAM to BAM, sort and remove duplicates using Samtools
|
2024-09-09 09:33:50 +08:00
|
|
|
string[] cmdFixmate = [PathSamtools, "fixmate", "-@", ARG_T.to!string, "-m", inputBam, "-"];
|
|
|
|
string[] cmdSort = [PathSamtools, "sort", "-@", ARG_T.to!string, "-"];
|
|
|
|
string[] cmdMarkdup = [PathSamtools, "markdup", "-@", ARG_T.to!string, "-", outputBam];
|
2024-09-08 23:17:57 +08:00
|
|
|
executeCommandPipe([cmdFixmate, cmdSort, cmdMarkdup]);
|
|
|
|
|
2024-09-09 09:33:50 +08:00
|
|
|
string [] cmdIndexBam = [PathSamtools, "index", "-@", ARG_T.to!string, outputBam];
|
2024-09-08 23:17:57 +08:00
|
|
|
executeCommand(cmdIndexBam);
|
2024-09-08 02:48:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
writeln("PostMapping::End");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-09 09:33:50 +08:00
|
|
|
void processVarCall(string[] ARG_L, string ARG_R, int ARG_T, string DirMap, string DirBam, string DirVcf, string PathBcftools) {
|
2024-09-08 02:48:54 +08:00
|
|
|
writeln("VarCalling::Start");
|
|
|
|
|
|
|
|
string[] Refs = getRef(ARG_R, DirMap);
|
|
|
|
string ARG_R_refer = Refs[1]; //reference_in fasta file
|
|
|
|
|
|
|
|
createDir(DirVcf);
|
|
|
|
|
2024-09-10 16:09:11 +08:00
|
|
|
foreach (string file; parallel(ARG_L, 1)) {
|
2024-09-08 02:48:54 +08:00
|
|
|
string baseName = getBaseName(file);
|
|
|
|
string inputBam = DirBam ~ "/" ~ baseName ~ ".bam";
|
|
|
|
string outputVcf = DirVcf ~ "/" ~ baseName ~ ".vcf.gz";
|
|
|
|
|
|
|
|
// Variant calling using bcftools
|
2024-09-09 09:33:50 +08:00
|
|
|
string[] cmdPileup = [PathBcftools, "mpileup", "-Oz", "--threads", ARG_T.to!string, "-f", ARG_R_refer, inputBam];
|
|
|
|
string[] cmdVarCall = [PathBcftools, "call", "-mv", "-Oz", "--threads", ARG_T.to!string];
|
|
|
|
string[] cmdNorm = [PathBcftools, "norm", "--threads", ARG_T.to!string, "-f", ARG_R_refer, "-Oz"];
|
|
|
|
string[] cmdFilter = [PathBcftools, "filter", "--threads", ARG_T.to!string, "--IndelGap", "5", "-Oz", "-o", outputVcf];
|
2024-09-08 02:48:54 +08:00
|
|
|
executeCommandPipe([cmdPileup, cmdVarCall, cmdNorm, cmdFilter]);
|
|
|
|
}
|
|
|
|
|
|
|
|
writeln("VarCalling::End");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-09-09 09:33:50 +08:00
|
|
|
void processCon(string[] ARG_G, string[] ARG_L, string ARG_R, int ARG_T, string DirMap, string DirVcf, string DirConsensus, string PathBcftools) {
|
2024-09-08 02:48:54 +08:00
|
|
|
createDir(DirConsensus);
|
|
|
|
|
2024-09-08 23:17:57 +08:00
|
|
|
string DirConTaxa = DirConsensus ~ "/" ~ "taxa";
|
|
|
|
|
|
|
|
createDir(DirConTaxa);
|
|
|
|
|
2024-09-08 02:48:54 +08:00
|
|
|
string[] Refs = getRef(ARG_R, DirMap);
|
|
|
|
string ARG_R_refer = Refs[1]; //reference_in fasta file
|
|
|
|
|
2024-09-08 23:17:57 +08:00
|
|
|
writeln("Consensus::Start");
|
|
|
|
// Extract fasta from vcf file
|
2024-09-08 02:48:54 +08:00
|
|
|
foreach (string file; ARG_L) {
|
|
|
|
string baseName = getBaseName(file);
|
|
|
|
string inputVcf = DirVcf ~ "/" ~ baseName ~ ".vcf.gz";
|
2024-09-08 23:17:57 +08:00
|
|
|
string outputFasta = DirConTaxa ~ "/" ~ baseName ~ ".fasta";
|
2024-09-08 02:48:54 +08:00
|
|
|
|
|
|
|
// index vcf.gz
|
2024-09-09 09:33:50 +08:00
|
|
|
string[] cmdIndexVcf = [PathBcftools, "index", inputVcf];
|
2024-09-08 02:48:54 +08:00
|
|
|
executeCommand(cmdIndexVcf);
|
|
|
|
|
|
|
|
// Generate consensus sequences using bcftools
|
2024-09-09 09:33:50 +08:00
|
|
|
string[] cmdCon = [PathBcftools, "consensus", "-f", ARG_R, inputVcf, "-o", outputFasta];
|
2024-09-08 02:48:54 +08:00
|
|
|
executeCommand(cmdCon);
|
|
|
|
}
|
2024-09-08 23:17:57 +08:00
|
|
|
// Recombine the sequences based on genes
|
|
|
|
writeln("Consensus::End");
|
2024-09-08 02:48:54 +08:00
|
|
|
}
|
|
|
|
|
2024-09-09 09:33:50 +08:00
|
|
|
void processCombFasta(string[] ARG_G, string[] ARG_L, string DirConsensus) {
|
2024-09-08 23:17:57 +08:00
|
|
|
|
|
|
|
string DirConTaxa = DirConsensus ~ "/" ~ "taxa";
|
|
|
|
string DirConGene = DirConsensus ~ "/" ~ "gene";
|
2024-09-09 00:04:36 +08:00
|
|
|
createDir(DirConGene);
|
|
|
|
|
2024-09-08 23:17:57 +08:00
|
|
|
// create a dictory
|
|
|
|
string[string] geneSequences;
|
|
|
|
|
2024-09-09 00:04:36 +08:00
|
|
|
writeln("ConvertFasta::Start");
|
2024-09-08 23:17:57 +08:00
|
|
|
// read first
|
|
|
|
foreach (file; ARG_L) {
|
2024-09-09 00:04:36 +08:00
|
|
|
string inputFile = DirConTaxa ~ "/" ~ file ~ ".fasta";
|
2024-09-08 23:17:57 +08:00
|
|
|
if (!exists(inputFile)) {
|
|
|
|
writeln("File not found: ", inputFile);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
string content = cast(string) readText(inputFile);
|
|
|
|
bool inSequence = false;
|
|
|
|
string currentGene;
|
|
|
|
|
|
|
|
foreach (line; content.splitter("\n")) {
|
|
|
|
if (line.empty) continue;
|
|
|
|
|
|
|
|
if (line[0] == '>') {
|
|
|
|
string header = line[1 .. $];
|
|
|
|
if (ARG_G.canFind(header)) {
|
|
|
|
currentGene = header;
|
|
|
|
geneSequences[currentGene] ~= ">" ~ file ~ "\n";
|
|
|
|
inSequence = true;
|
|
|
|
} else {
|
|
|
|
inSequence = false;
|
|
|
|
}
|
|
|
|
} else if (inSequence) {
|
|
|
|
geneSequences[currentGene] ~= line ~ "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// write different files
|
|
|
|
foreach (gene; ARG_G) {
|
|
|
|
string outputFile = DirConGene ~ "/" ~ gene ~ ".fasta";
|
2024-09-09 00:04:36 +08:00
|
|
|
File output = File(outputFile, "w");
|
2024-09-08 23:17:57 +08:00
|
|
|
if (gene in geneSequences) {
|
|
|
|
output.write(geneSequences[gene]);
|
|
|
|
}
|
|
|
|
}
|
2024-09-09 00:04:36 +08:00
|
|
|
writeln("ConvertFasta::End");
|
|
|
|
}
|
|
|
|
|
|
|
|
void processAlign(string[] ARG_G, string DirConsensus, string DirAlign, string PathMacse){
|
2024-09-08 23:17:57 +08:00
|
|
|
|
2024-09-09 01:19:42 +08:00
|
|
|
string DirConGene = DirConsensus ~ "/" ~ "gene";
|
|
|
|
string DirAlignAA = DirAlign ~ "/" ~ "AA";
|
|
|
|
string DirAlignNT = DirAlign ~ "/" ~ "NT";
|
|
|
|
|
|
|
|
writeln("Align::Start");
|
|
|
|
createDir(DirAlign);
|
|
|
|
createDir(DirAlignAA);
|
|
|
|
createDir(DirAlignNT);
|
|
|
|
foreach (gene; parallel(ARG_G, 1)) {
|
|
|
|
string inputFasta = DirConGene ~ "/" ~ gene ~ ".fasta";
|
|
|
|
string outAA = DirAlignAA ~ "/" ~ gene ~ ".fasta";
|
|
|
|
string outNT = DirAlignNT ~ "/" ~ gene ~ ".fasta";
|
2024-09-09 09:33:50 +08:00
|
|
|
string[] cmdAlign = ["java", "-jar", PathMacse, "-prog", "alignSequences", "-seq" , inputFasta, "-out_AA", outAA, "-out_NT", outNT ];
|
|
|
|
executeCommand(cmdAlign);
|
2024-09-09 01:19:42 +08:00
|
|
|
}
|
|
|
|
writeln("Align::End");
|
|
|
|
|
2024-09-08 23:17:57 +08:00
|
|
|
}
|
2024-09-08 02:48:54 +08:00
|
|
|
|
2024-09-10 00:37:06 +08:00
|
|
|
void processTrimming(string[] ARG_G, string DirAlign, string DirTrim, string PathDelstop, string PathTrimal){
|
2024-09-10 16:43:18 +08:00
|
|
|
writeln("Trimming::Start");
|
2024-09-10 00:37:06 +08:00
|
|
|
|
|
|
|
string DirAA = DirAlign ~ "/" ~ "AA";
|
|
|
|
string DirNT = DirAlign ~ "/" ~ "NT";
|
2024-09-10 13:09:05 +08:00
|
|
|
string DirAA_out = DirAlign ~ "/" ~ "AA_out";
|
|
|
|
string DirNT_out = DirAlign ~ "/" ~ "NT_out";
|
2024-09-10 00:37:06 +08:00
|
|
|
|
2024-09-10 13:09:05 +08:00
|
|
|
createDir(DirAA_out);
|
|
|
|
createDir(DirNT_out);
|
|
|
|
|
2024-09-10 00:37:06 +08:00
|
|
|
// copy file firstly
|
2024-09-11 09:41:09 +08:00
|
|
|
foreach (gene; parallel(ARG_G,1)){
|
2024-09-10 00:37:06 +08:00
|
|
|
string inputFastaAA = DirAA ~ "/" ~ gene ~ ".fasta";
|
2024-09-10 13:09:05 +08:00
|
|
|
string outputFastaAA = DirAA_out ~ "/" ~ gene ~ ".fasta";
|
2024-09-10 00:37:06 +08:00
|
|
|
string inputFastaNT = DirNT ~ "/" ~ gene ~ ".fasta";
|
2024-09-10 13:09:05 +08:00
|
|
|
string outputFastaNT = DirNT_out ~ "/" ~ gene ~ ".fasta";
|
2024-09-10 00:37:06 +08:00
|
|
|
|
|
|
|
copy(inputFastaNT, outputFastaNT);
|
|
|
|
copy(inputFastaAA, outputFastaAA);
|
|
|
|
// del stop codon
|
|
|
|
string[] cmdDelStop = [PathDelstop, outputFastaAA, outputFastaNT, "--delete"];
|
|
|
|
executeCommand(cmdDelStop);
|
|
|
|
}
|
|
|
|
|
2024-09-10 13:09:05 +08:00
|
|
|
string DirTrimNT = DirTrim ~ "/" ~ "NT";
|
2024-09-10 00:37:06 +08:00
|
|
|
createDir(DirTrim);
|
2024-09-10 13:09:05 +08:00
|
|
|
createDir(DirTrimNT);
|
2024-09-11 09:41:09 +08:00
|
|
|
foreach (gene; parallel(ARG_G,1)){
|
2024-09-10 13:09:05 +08:00
|
|
|
string inputFastaAA = DirAA_out ~ "/" ~ gene ~ ".fasta";
|
|
|
|
string inputBackTransNT = DirNT_out ~ "/" ~ gene ~ ".fasta";
|
|
|
|
string outputFastaNT = DirTrimNT ~ "/" ~ gene ~ ".fasta";
|
2024-09-10 00:37:06 +08:00
|
|
|
|
2024-09-10 13:09:05 +08:00
|
|
|
string[] cmdTrim = [PathTrimal, "-in", inputFastaAA, "-backtrans", inputBackTransNT, "-out", outputFastaNT, "-automated1"];
|
2024-09-10 00:37:06 +08:00
|
|
|
executeCommand(cmdTrim);
|
|
|
|
}
|
2024-09-10 13:09:05 +08:00
|
|
|
writeln("Trimming::End");
|
|
|
|
|
2024-09-10 00:37:06 +08:00
|
|
|
}
|
|
|
|
|
2024-09-09 10:25:32 +08:00
|
|
|
void processAssembly(string[] ARG_L, int ARG_M, int ARG_T, string DirQcTrim, string DirAssembly, string PathSpades){
|
2024-09-10 00:37:06 +08:00
|
|
|
writeln("Assembly::Start");
|
2024-09-09 10:25:32 +08:00
|
|
|
createDir(DirAssembly);
|
|
|
|
foreach (string file; ARG_L) {
|
|
|
|
string baseName = getBaseName(file);
|
|
|
|
string DirAss = DirAssembly ~ "/" ~ baseName;
|
|
|
|
createDir(DirAss);
|
|
|
|
string inputFileR1 = DirQcTrim ~ "/" ~ baseName ~ "_R1.fastq.gz";
|
|
|
|
string inputFileR2 = DirQcTrim ~ "/" ~ baseName ~ "_R2.fastq.gz";
|
|
|
|
string[] cmdAssembly = [PathSpades, "--pe1-1", inputFileR1, "--pe1-2", inputFileR2, "-t", ARG_T.to!string, "-m", ARG_M.to!string, "--careful", "--phred-offset", "33", "-o", DirAss];
|
|
|
|
executeCommand(cmdAssembly);
|
2024-09-09 09:33:50 +08:00
|
|
|
}
|
2024-09-10 00:37:06 +08:00
|
|
|
writeln("Assembly::End");
|
2024-09-09 09:33:50 +08:00
|
|
|
}
|
|
|
|
|
2024-09-08 02:48:54 +08:00
|
|
|
void main(string[] args) {
|
2024-09-08 23:17:57 +08:00
|
|
|
string pkgver = "0.0.3";
|
2024-09-08 02:48:54 +08:00
|
|
|
|
|
|
|
string DirHome = std.file.getcwd();
|
|
|
|
string DirRaw = DirHome ~ "/00_raw";
|
|
|
|
string DirQcTrim = DirHome ~ "/01_fastp";
|
|
|
|
string DirMap = DirHome ~ "/02_bowtie2";
|
2024-09-09 10:25:32 +08:00
|
|
|
string DirAssembly = DirHome ~ "/02_spades";
|
2024-09-08 02:48:54 +08:00
|
|
|
string DirBam = DirHome ~ "/03_bam";
|
|
|
|
string DirVcf = DirHome ~ "/04_vcf";
|
|
|
|
string DirConsensus = DirHome ~ "/05_consen";
|
2024-09-10 00:37:06 +08:00
|
|
|
string DirAlign = DirHome ~ "/06_macse";
|
|
|
|
string DirTrim = DirHome ~ "/07_trimal";
|
2024-09-08 02:48:54 +08:00
|
|
|
|
2024-09-09 09:33:50 +08:00
|
|
|
string PathFastp = "/usr/bin/fastp";
|
|
|
|
string PathBowtie2 = "/usr/bin/bowtie2";
|
|
|
|
string PathSamtools = "/usr/bin/samtools";
|
|
|
|
string PathBcftools = "/usr/bin/bcftools";
|
2024-09-08 02:48:54 +08:00
|
|
|
string PathMacse = "/usr/share/java/macse.jar";
|
2024-09-10 00:37:06 +08:00
|
|
|
string PathDelstop = "/usr/bin/delstop";
|
2024-09-09 09:33:50 +08:00
|
|
|
string PathTrimal = "/usr/bin/trimal";
|
2024-09-09 10:25:32 +08:00
|
|
|
string PathSpades = "/usr/bin/spades.py";
|
2024-09-08 02:48:54 +08:00
|
|
|
|
|
|
|
int ARG_T = 8;
|
2024-09-09 10:25:32 +08:00
|
|
|
int ARG_M = 16;
|
2024-09-08 23:17:57 +08:00
|
|
|
string[] ARG_G;
|
2024-09-08 02:48:54 +08:00
|
|
|
string[] ARG_L;
|
2024-09-09 09:33:50 +08:00
|
|
|
string ARG_C;
|
2024-09-08 02:48:54 +08:00
|
|
|
string ARG_F;
|
|
|
|
string ARG_R;
|
|
|
|
|
|
|
|
if (args.length > 1){
|
|
|
|
foreach (int i; 0 .. cast(int)args.length) {
|
|
|
|
switch (args[i]) {
|
2024-09-09 09:33:50 +08:00
|
|
|
case "-c", "--config":
|
|
|
|
i++;
|
|
|
|
ARG_C = args[i];
|
|
|
|
break;
|
2024-09-08 02:48:54 +08:00
|
|
|
case "-f", "--functions":
|
|
|
|
i++;
|
|
|
|
ARG_F = args[i];
|
|
|
|
break;
|
2024-09-08 23:17:57 +08:00
|
|
|
case "-g", "--gene":
|
|
|
|
i++;
|
|
|
|
ARG_G ~= readArrFromFile(args[i]);
|
|
|
|
break;
|
2024-09-08 02:48:54 +08:00
|
|
|
case "-h", "--help":
|
|
|
|
show_help(pkgver);
|
|
|
|
return;
|
|
|
|
case "-l", "--list":
|
|
|
|
i++;
|
2024-09-08 23:17:57 +08:00
|
|
|
ARG_L ~= readArrFromFile(args[i]);
|
2024-09-08 02:48:54 +08:00
|
|
|
break;
|
|
|
|
case "-r", "--reference":
|
|
|
|
i++;
|
|
|
|
ARG_R = args[i];
|
|
|
|
break;
|
|
|
|
case "-t", "--threads":
|
|
|
|
i++;
|
|
|
|
ARG_T = args[i].to!int;
|
|
|
|
break;
|
2024-09-09 09:45:55 +08:00
|
|
|
case "--fastp":
|
|
|
|
i++;
|
|
|
|
PathFastp = args[i];
|
|
|
|
break;
|
|
|
|
case "--bowtie2":
|
|
|
|
i++;
|
|
|
|
PathBowtie2 = args[i];
|
|
|
|
break;
|
|
|
|
case "--samtools":
|
|
|
|
i++;
|
|
|
|
PathSamtools = args[i];
|
|
|
|
break;
|
|
|
|
case "--bcftools":
|
|
|
|
i++;
|
|
|
|
PathBcftools = args[i];
|
|
|
|
break;
|
2024-09-08 02:48:54 +08:00
|
|
|
case "--macse":
|
|
|
|
i++;
|
|
|
|
PathMacse = args[i];
|
|
|
|
break;
|
2024-09-09 09:45:55 +08:00
|
|
|
case "--trimal":
|
|
|
|
i++;
|
|
|
|
PathTrimal = args[i];
|
|
|
|
break;
|
2024-09-10 13:09:05 +08:00
|
|
|
case "--delstop":
|
|
|
|
i++;
|
|
|
|
PathDelstop = args[i];
|
|
|
|
break;
|
2024-09-09 10:25:32 +08:00
|
|
|
case "--spades":
|
|
|
|
i++;
|
|
|
|
PathSpades = args[i];
|
|
|
|
break;
|
2024-09-08 02:48:54 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
show_help(pkgver);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-09-09 00:04:36 +08:00
|
|
|
// get gene from ARG_R reference fasta
|
|
|
|
if (ARG_R.length != 0 ){
|
|
|
|
ARG_G = getARG_G(ARG_R);
|
|
|
|
}
|
2024-09-09 09:33:50 +08:00
|
|
|
|
|
|
|
// get pathXXX form config file
|
|
|
|
if (ARG_C != ""){
|
2024-09-09 00:04:36 +08:00
|
|
|
|
2024-09-09 09:33:50 +08:00
|
|
|
PathFastp = getValueFromConfig(ARG_C, "fastp");
|
|
|
|
PathBowtie2 = getValueFromConfig(ARG_C, "bowtie2");
|
|
|
|
PathSamtools = getValueFromConfig(ARG_C, "samtools");
|
|
|
|
PathBcftools = getValueFromConfig(ARG_C, "bcftools");
|
|
|
|
PathMacse = getValueFromConfig(ARG_C, "macse");
|
|
|
|
PathTrimal = getValueFromConfig(ARG_C, "trimal");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-09-08 02:48:54 +08:00
|
|
|
writeln("RGBEPP::Start");
|
|
|
|
// Perform steps based on provided function argument
|
|
|
|
if (ARG_F == "all" || ARG_F == "clean") {
|
2024-09-09 10:25:32 +08:00
|
|
|
processQcTrim(ARG_L, ARG_T, DirRaw, DirQcTrim, PathFastp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ARG_F == "assembly") {
|
|
|
|
processAlign(ARG_G, DirConsensus, DirAlign, PathMacse);
|
2024-09-08 02:48:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ARG_F == "all" || ARG_F == "map") {
|
2024-09-09 09:33:50 +08:00
|
|
|
processMapping(ARG_L, ARG_R, ARG_T, DirQcTrim, DirMap, PathBowtie2, PathSamtools);
|
2024-09-08 02:48:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ARG_F == "all" || ARG_F == "postmap") {
|
2024-09-09 09:33:50 +08:00
|
|
|
processPostMap(ARG_L, ARG_T, DirMap, DirBam, PathSamtools);
|
2024-09-08 02:48:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ARG_F == "all" || ARG_F == "varcall") {
|
2024-09-09 09:33:50 +08:00
|
|
|
processVarCall(ARG_L, ARG_R, ARG_T, DirMap, DirBam, DirVcf, PathBcftools);
|
2024-09-08 02:48:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ARG_F == "all" || ARG_F == "consen") {
|
2024-09-09 09:33:50 +08:00
|
|
|
processCon(ARG_G, ARG_L, ARG_R, ARG_T, DirMap, DirVcf, DirConsensus, PathBcftools);
|
|
|
|
processCombFasta(ARG_G, ARG_L, DirConsensus);
|
2024-09-08 02:48:54 +08:00
|
|
|
}
|
|
|
|
|
2024-09-08 23:17:57 +08:00
|
|
|
if (ARG_F == "all" || ARG_F == "align") {
|
2024-09-09 00:04:36 +08:00
|
|
|
processAlign(ARG_G, DirConsensus, DirAlign, PathMacse);
|
2024-09-08 23:17:57 +08:00
|
|
|
}
|
2024-09-08 02:48:54 +08:00
|
|
|
|
2024-09-10 00:37:06 +08:00
|
|
|
if (ARG_F == "all" || ARG_F == "trim") {
|
|
|
|
processTrimming(ARG_G, DirAlign, DirTrim, PathDelstop, PathTrimal);
|
|
|
|
}
|
2024-09-09 10:25:32 +08:00
|
|
|
|
2024-09-08 02:48:54 +08:00
|
|
|
writeln("RGBEPP::End");
|
|
|
|
}
|
|
|
|
|