Skip to content

Commit

Permalink
fix linting after mergin branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-VM committed May 20, 2024
1 parent 7778a12 commit 820ca64
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 70 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ In specific cases where samples recorded in the input samplesheet belong to more

> NOTE: This scenario is supported when [Kmerfinder](https://bitbucket.org/genomicepidemiology/kmerfinder/src/master/) analysis is performed only.

In cases where input samplesheet has files where , the pipeline will group samples in batches according to their reference genomes and will provide a general QUAST containing all the input samples and a by reference genome QUAST report, that is, a quast report for each reference genome.

## Usage

> [!NOTE]
Expand Down
2 changes: 0 additions & 2 deletions assets/multiqc_config_long.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ module_order:
path_filters:
- "./bakta/*.txt"


report_section_order:
nanostat:
after: general_stats
Expand Down Expand Up @@ -134,7 +133,6 @@ custom_data:
format: "{:,.0f}"

export_plots: true

# # Customise the module search patterns to speed up execution time
# # - Skip module sub-tools that we are not interested in
# # - Replace file-content searching with filename pattern searching
Expand Down
1 change: 0 additions & 1 deletion assets/multiqc_config_short.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ module_order:
path_filters:
- "./bakta/*.txt"


report_section_order:
fastqc:
after: general_stats
Expand Down
29 changes: 15 additions & 14 deletions bin/csv_to_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,22 @@
import csv
import yaml


def parse_args(args=None):
Description = (
"Create a yaml file from csv input file grouping samples as keys and resting fields as their value pair."
)
Description = "Create a yaml file from csv input file grouping samples as keys and resting fields as their value pair."

Epilog = "Example usage: python csv_to_yaml.py -i myfile.csv -k 'sample_name' -o converted_file"
parser = argparse.ArgumentParser(description=Description, epilog=Epilog)
parser.add_argument(
"-i",
"--input",
type=str,
dest="CSV_FILE",
help="Input file in CSV format."
"-i", "--input", type=str, dest="CSV_FILE", help="Input file in CSV format."
)

parser.add_argument(
"-k",
"--key_field",
type=str,
dest="KEY_FIELD",
help="Name of the key/column grupping field in the input csv."
help="Name of the key/column grupping field in the input csv.",
)

parser.add_argument(
Expand All @@ -33,26 +28,32 @@ def parse_args(args=None):
type=str,
default="output_file",
dest="OUT_PREFIX",
help="Output file name"
help="Output file name",
)
return parser.parse_args(args)


def parse_csv(csv_file):
with open(csv_file, 'r') as c:
with open(csv_file, "r") as c:
csv_reader = csv.DictReader(c)
data = [ row for row in csv_reader]
data = [row for row in csv_reader]
return data


def create_yaml(data, key, output_prefix):
yaml_data = {entry[key]: {k: v for k, v in entry.items() if k != key} for entry in data}
with open( output_prefix + '.yaml' , 'w') as yaml_file:
yaml_data = {
entry[key]: {k: v for k, v in entry.items() if k != key} for entry in data
}
with open(output_prefix + ".yaml", "w") as yaml_file:
yaml.dump(yaml_data, yaml_file, default_flow_style=False)


def main(args=None):
args = parse_args(args)
file_list = parse_csv(args.CSV_FILE)

create_yaml(data=file_list, key=args.KEY_FIELD, output_prefix=args.OUT_PREFIX)


if __name__ == "__main__":
sys.exit(main())
30 changes: 14 additions & 16 deletions bin/download_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@
import argparse
import os

#import wget
# import wget
import requests


# TODO: Generate report
def parse_args(args=None):
Description = (
"download the reference files \
Description = "download the reference files \
(fna, faa, gff)from the reference NCBI file."
)
Epilog = """Usage example: \
python download_reference.py \
-file <file with the references created by find_common_reference> \
Expand All @@ -66,17 +65,13 @@ def parse_args(args=None):

parser = argparse.ArgumentParser(description=Description, epilog=Epilog)
parser.add_argument(
"-file",
help="File containing the ranking of references from kmerfinder."
"-file", help="File containing the ranking of references from kmerfinder."
)
parser.add_argument(
"-reference",
help="File containing the paths to bacterial references. See example in: https://ftp.ncbi.nlm.nih.gov/genomes/ASSEMBLY_REPORTS/assembly_summary_refseq.txt"
)
parser.add_argument(
"-out_dir",
help="Output directory."
help="File containing the paths to bacterial references. See example in: https://ftp.ncbi.nlm.nih.gov/genomes/ASSEMBLY_REPORTS/assembly_summary_refseq.txt",
)
parser.add_argument("-out_dir", help="Output directory.")

return parser.parse_args(args)

Expand All @@ -98,10 +93,9 @@ def download_references(file, reference, out_dir):
]
top_reference = infile[0][0]

with open(str(top_reference) + ".winner", 'w') as topref:
with open(str(top_reference) + ".winner", "w") as topref:
topref.write(top_reference)


# create the outdir (do nothing if already there)
try:
os.mkdir(out_dir)
Expand Down Expand Up @@ -134,7 +128,11 @@ def download_references(file, reference, out_dir):
dir_url.append(assembly_url)

if len(dir_url) == 0:
print("No assemblies responding to the top reference: ", top_reference, " were found")
print(
"No assemblies responding to the top reference: ",
top_reference,
" were found",
)
sys.exit(1)

dir_url = str(dir_url[0])
Expand All @@ -145,9 +143,9 @@ def download_references(file, reference, out_dir):
file_url = dir_url + r_end
print(file_url)

#wget.download(file_url, out_file)
# wget.download(file_url, out_file)
response = requests.get(file_url, stream=True)
with open(out_file, 'wb') as out:
with open(out_file, "wb") as out:
for chunk in response.iter_content(chunk_size=8192):
out.write(chunk)

Expand Down
12 changes: 4 additions & 8 deletions bin/kmerfinder_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@


def check_arg(args=None):

"""
Description:
Function collect arguments from command line using argparse
Expand All @@ -32,14 +31,14 @@ def check_arg(args=None):
parser = argparse.ArgumentParser(
prog="07-kmerfinder.py",
formatter_class=argparse.RawDescriptionHelpFormatter,
description="07-kmerfinder.py creates a csv file from results.txt file", # FIXME
description="07-kmerfinder.py creates a csv file from results.txt file", # FIXME
)

parser.add_argument(
"--path",
"-p",
required=True,
help="Insert path of results.txt file like /home/user/Service_folder/ANALYSIS/07-kmerfinder", # FIXME
help="Insert path of results.txt file like /home/user/Service_folder/ANALYSIS/07-kmerfinder", # FIXME
)

parser.add_argument(
Expand All @@ -61,7 +60,6 @@ def check_arg(args=None):


def kmerfinder_dictionary(file_txt):

"""
Description:
Function to extract the relevant part of result.txt file
Expand All @@ -71,7 +69,7 @@ def kmerfinder_dictionary(file_txt):
dictionary
"""

step = "07-kmerfinder_" # FIXME
step = "07-kmerfinder_" # FIXME

num_lines = sum(1 for line in open(file_txt))
hits = num_lines - 1 # to count the total number of hits
Expand Down Expand Up @@ -110,7 +108,6 @@ def kmerfinder_dictionary(file_txt):


def dictionary2bn(dictionary, binary_file):

"""
Description:
Expand All @@ -134,7 +131,6 @@ def dictionary2bn(dictionary, binary_file):


def dictionary2csv(dictionary, csv_file):

"""
Description:
Expand Down Expand Up @@ -185,7 +181,7 @@ def dictionary2csv(dictionary, csv_file):
kmer_all = {}

for sample in sample_list:
file_name = os.path.join(path, sample + "_results.txt" )
file_name = os.path.join(path, sample + "_results.txt")
kmer_all[sample] = kmerfinder_dictionary(file_name)

print("kmerfinder_dictionary done")
Expand Down
Loading

0 comments on commit 820ca64

Please sign in to comment.