From 34907a49a89c6a356e3d9b24bfd6e71932abe784 Mon Sep 17 00:00:00 2001 From: hoelzer Date: Wed, 14 Feb 2024 11:24:56 +0100 Subject: [PATCH] fix DNA valid check and output path --- correct_primer_positions.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/correct_primer_positions.py b/correct_primer_positions.py index fbdf8c8..8d16354 100644 --- a/correct_primer_positions.py +++ b/correct_primer_positions.py @@ -12,15 +12,16 @@ import os.path def verify(sequence): - '''This code verifies if a sequence is a DNA''' + '''This code verifies if a sequence is a DNA or contains ambiguous bases according to the IUPAC code.''' # set the input sequence seq = set(sequence) - # confirm if its elements is equal to the set of valid DNA bases - # Use a union method to ensure the sequence is verified if does not - # contain all the bases - if seq == {"A", "T", "C", "G"}.union(seq): + # Set of valid DNA bases including IUPAC ambiguity codes + valid_bases = {"A", "T", "C", "G", "Y", "R", "S", "W", "K", "M", "B", "D", "H", "V", "N"} + + # confirm if its elements are only from the set of valid DNA bases + if seq.issubset(valid_bases): return "DNA" else: return "Invalid DNA sequence" @@ -130,8 +131,8 @@ def main(argv): primer_bed_df.iloc[:,1] = s_pos primer_bed_df.iloc[:,2] = e_pos - primer_bed_df.to_csv(os.path.dirname(argv[3])+'/'+os.path.basename(argv[3])+'.position.corrected.bed', index=False, sep='\t', header=False) - print("Primer.bed file has been updated. See: \n"+os.path.dirname(argv[3])+'/'+os.path.basename(argv[3])+'.position.corrected.bed') + primer_bed_df.to_csv('./'+os.path.dirname(argv[3])+'/'+os.path.basename(argv[3])+'.position.corrected.bed', index=False, sep='\t', header=False) + print("Primer.bed file has been updated. See: \n./"+os.path.dirname(argv[3])+'/'+os.path.basename(argv[3])+'.position.corrected.bed') except Exception as e: # pragma: nocover return "An error has occured: " + str(e) if __name__ == "__main__": # pragma: nocover