-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Concatenate and filter DIAMOND's results (#45)
* feat: Add subwf to concatenate alignments * fix: Fix import on annotation * fix: Change variable name in ann * fix: Change process selectors in config * fix: Change collect in concat * fix: Change module selector * refactor: Change temp txt files to .temp * test: Change trace task size * refactor: Add genome_id column name * test: Refactor trace size * refactor: Add header in add_column module * feat: Add module to filter matches * refactor: Remove add_column module * fix: Remove import statement
- Loading branch information
Showing
7 changed files
with
175 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import sys | ||
import errno | ||
import argparse | ||
from pandas import read_csv | ||
|
||
|
||
def parse_args(args=None): | ||
Description = "Filter alignment results." | ||
Epilog = "Example usage: python filter_alignment.py <FILE_IN> <GENOME> <HEADER> <FILE_OUT>" | ||
|
||
parser = argparse.ArgumentParser(description=Description, epilog=Epilog) | ||
parser.add_argument("FILE_IN", help="Input alignment file.") | ||
parser.add_argument("GENOME", help="Genome identifier.") | ||
parser.add_argument("HEADER", help="Header for the output file.") | ||
parser.add_argument("FILE_OUT", help="Output file.") | ||
return parser.parse_args(args) | ||
|
||
|
||
def filter_alignment(file_in, genome_id, header, file_out): | ||
df = read_csv(file_in, sep="\t", names=header.split(" ")) | ||
|
||
df["genome_id"] = genome_id | ||
df["qcover"] = df["length"] / df["slen"] | ||
filtered_df = ( | ||
df.sort_values("pident", ascending=False) | ||
.drop_duplicates(["qseqid", "full_qseq"]) | ||
.sort_values(["qseqid", "pident", "mismatch"], ascending=[True, False, False]) | ||
) | ||
|
||
filtered_df.to_csv(file_out, sep="\t", index=False) | ||
|
||
|
||
def main(args=None): | ||
args = parse_args(args) | ||
filter_alignment(args.FILE_IN, args.GENOME, args.HEADER, args.FILE_OUT) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
process CONCAT_ALIGNMENT { | ||
label "process_low" | ||
|
||
conda (params.enable_conda ? "conda-forge::python=3.8.3" : null) | ||
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { | ||
container "https://depot.galaxyproject.org/singularity/python:3.8.3" | ||
} else { | ||
container "quay.io/biocontainers/python:3.8.3" | ||
} | ||
|
||
input: | ||
path(aln) | ||
val dbname | ||
|
||
output: | ||
path("*.txt"), emit: txt | ||
|
||
script: | ||
def args = task.ext.args ?: '' | ||
def prefix = task.ext.prefix ?: "${dbname}" | ||
|
||
""" | ||
cat ${aln} > ${prefix}.txt | ||
""" | ||
|
||
stub: | ||
""" | ||
touch ${prefix}.txt | ||
""" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
process FILTER_MATCHES { | ||
tag "$meta.id" | ||
label "process_low" | ||
|
||
conda (params.enable_conda ? "conda-forge::pandas=1.4.3" : null) | ||
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { | ||
container "https://depot.galaxyproject.org/singularity/pandas:1.4.3" | ||
} else { | ||
container "quay.io/biocontainers/pandas:1.4.3" | ||
} | ||
|
||
input: | ||
tuple val(meta), path(aln) | ||
val dbname | ||
val header | ||
|
||
output: | ||
tuple val(meta), path("*.txt"), emit: txt | ||
|
||
script: | ||
def args = task.ext.args ?: '' | ||
def prefix = task.ext.prefix ?: "${meta.id}_${dbname}_filtered" | ||
|
||
""" | ||
filter_alignment.py ${aln} '${meta.id}' '${header}' ${prefix}.txt | ||
""" | ||
|
||
stub: | ||
""" | ||
touch ${prefix}.txt | ||
""" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
include { CONCAT_ALIGNMENT } from '../../modules/local/concat_alignments' | ||
include { FILTER_MATCHES } from '../../modules/local/filter_matches' | ||
|
||
|
||
workflow FILTER_ALIGNMENT { | ||
|
||
take: | ||
diamond_results | ||
db_name | ||
blast_columns | ||
|
||
main: | ||
diamond_results | ||
.filter{ id, path -> path.size() > 0 } | ||
.set { results } | ||
|
||
FILTER_MATCHES(results, db_name, blast_columns) | ||
FILTER_MATCHES.out.txt.set { diamond_filtered } | ||
|
||
diamond_filtered | ||
.collect{ id, paths -> paths } | ||
.set { paths } | ||
|
||
CONCAT_ALIGNMENT(paths, db_name) | ||
CONCAT_ALIGNMENT.out.txt.set { concatenated } | ||
|
||
emit: | ||
concatenated = concatenated | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters