diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..bc0df40fcd50d8bd173ca9307fab0c095706e669 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,34 @@ +default: # Set default + tags: + - docker + image: python:3.10-slim-buster + +stages: # List of stages for jobs, and their order of execution + - build + - test + +build-job: # This job runs in the build stage, which runs first. + stage: build + script: + - pip install -r requirements.txt + - pip install -r requirements_dev.txt + - pip install . + +# unit-test-job: # This job runs in the test stage. +# stage: test # It only starts when the job in the build stage completes successfully. +# script: +# - pip install -r requirements.txt +# - pip install -r requirements_dev.txt +# - pip install . +# - coverage run --source primingsitepredictor -m pytest +# - coverage report -m + +lint-test-job: # This job also runs in the test stage. + stage: test # It can run at the same time as unit-test-job (in parallel). + script: + - pip install -r requirements.txt + - pip install -r requirements_dev.txt + - pip install . + - flake8 --docstring-convention google primingsitepredictor/ # tests/ + - pylint primingsitepredictor/ # tests/ + - mypy primingsitepredictor/ diff --git a/img/Images_Max/Gitlesson_1_Max b/img/Images_Max/Gitlesson_1_Max deleted file mode 100644 index abb7ab7d6243faab4be89850848c6b7b8f065488..0000000000000000000000000000000000000000 Binary files a/img/Images_Max/Gitlesson_1_Max and /dev/null differ diff --git a/img/Images_Max/Gitlesson_2_Max b/img/Images_Max/Gitlesson_2_Max deleted file mode 100644 index 8a36a512bb68851c3b48f3ebfd3b704600c62f8c..0000000000000000000000000000000000000000 Binary files a/img/Images_Max/Gitlesson_2_Max and /dev/null differ diff --git a/img/Images_Max/Markdown_Max b/img/Images_Max/Markdown_Max deleted file mode 100644 index 913791b6775544d80218e65551ca13c3add7b03d..0000000000000000000000000000000000000000 Binary files a/img/Images_Max/Markdown_Max and /dev/null differ diff --git a/img/Images_Max/images.txt b/img/Images_Max/images.txt deleted file mode 100644 index 2571c8421ce9c8810dd41bba6aaed4237a0ef352..0000000000000000000000000000000000000000 --- a/img/Images_Max/images.txt +++ /dev/null @@ -1 +0,0 @@ -pepe diff --git a/img/Images_Robin/IntroductionSeq.png b/img/Images_Robin/IntroductionSeq.png deleted file mode 100644 index 968266787778e62890051b431de85ffd0168ad5a..0000000000000000000000000000000000000000 Binary files a/img/Images_Robin/IntroductionSeq.png and /dev/null differ diff --git a/img/Images_Robin/Markdown.png b/img/Images_Robin/Markdown.png deleted file mode 100644 index 6f2ba45ffd25e13860c830b358f3e047841b204a..0000000000000000000000000000000000000000 Binary files a/img/Images_Robin/Markdown.png and /dev/null differ diff --git a/img/Images_Robin/Push&Pull -- GitRemotes!.png b/img/Images_Robin/Push&Pull -- GitRemotes!.png deleted file mode 100644 index b5906235ab4d46cc5f75a16d0945ee05a2d9ff81..0000000000000000000000000000000000000000 Binary files a/img/Images_Robin/Push&Pull -- GitRemotes!.png and /dev/null differ diff --git a/primingsitepredictor/.idea/.gitignore b/primingsitepredictor/.idea/.gitignore deleted file mode 100644 index 13566b81b018ad684f3a35fee301741b2734c8f4..0000000000000000000000000000000000000000 --- a/primingsitepredictor/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/primingsitepredictor/.idea/inspectionProfiles/profiles_settings.xml b/primingsitepredictor/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2da2d6447d11dfe32bfb846c3d5b199fc99..0000000000000000000000000000000000000000 --- a/primingsitepredictor/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ -<component name="InspectionProjectProfileManager"> - <settings> - <option name="USE_PROJECT_PROFILE" value="false" /> - <version value="1.0" /> - </settings> -</component> \ No newline at end of file diff --git a/primingsitepredictor/.idea/misc.xml b/primingsitepredictor/.idea/misc.xml deleted file mode 100644 index e6a7aa474cd32e70c4d9694c40996d01e47c23fc..0000000000000000000000000000000000000000 --- a/primingsitepredictor/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (tests)" project-jdk-type="Python SDK" /> -</project> \ No newline at end of file diff --git a/primingsitepredictor/.idea/modules.xml b/primingsitepredictor/.idea/modules.xml deleted file mode 100644 index b7f52b9584a9cd9443097c0f753a17a344fa41a0..0000000000000000000000000000000000000000 --- a/primingsitepredictor/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="ProjectModuleManager"> - <modules> - <module fileurl="file://$PROJECT_DIR$/.idea/primingsitepredictor.iml" filepath="$PROJECT_DIR$/.idea/primingsitepredictor.iml" /> - </modules> - </component> -</project> \ No newline at end of file diff --git a/primingsitepredictor/.idea/primingsitepredictor.iml b/primingsitepredictor/.idea/primingsitepredictor.iml deleted file mode 100644 index d0876a78d06ac03b5d78c8dcdb95570281c6f1d6..0000000000000000000000000000000000000000 --- a/primingsitepredictor/.idea/primingsitepredictor.iml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module type="PYTHON_MODULE" version="4"> - <component name="NewModuleRootManager"> - <content url="file://$MODULE_DIR$" /> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - </component> -</module> \ No newline at end of file diff --git a/primingsitepredictor/.idea/vcs.xml b/primingsitepredictor/.idea/vcs.xml deleted file mode 100644 index 6c0b8635858dc7ad44b93df54b762707ce49eefc..0000000000000000000000000000000000000000 --- a/primingsitepredictor/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="VcsDirectoryMappings"> - <mapping directory="$PROJECT_DIR$/.." vcs="Git" /> - </component> -</project> \ No newline at end of file diff --git a/primingsitepredictor/Primer1.fasta b/primingsitepredictor/Primer1.fasta deleted file mode 100644 index 251777b9e4a409e7bb32d851b7bee98032bd3d6c..0000000000000000000000000000000000000000 --- a/primingsitepredictor/Primer1.fasta +++ /dev/null @@ -1,2 +0,0 @@ -<primer1 -TTTTTTTTTTTTTTT diff --git a/primingsitepredictor/__init__.py b/primingsitepredictor/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..66eb5ba958a8629efed8cbd53b8801505a0c219f 100644 --- a/primingsitepredictor/__init__.py +++ b/primingsitepredictor/__init__.py @@ -0,0 +1 @@ +"""Initialize package.""" diff --git a/primingsitepredictor/cli.py b/primingsitepredictor/cli.py index 218fbb65b4c66ea098d317a17bbee015706d4933..3f5c9f791454ba8e0b82d5363460bfe24f92b67a 100644 --- a/primingsitepredictor/cli.py +++ b/primingsitepredictor/cli.py @@ -1,36 +1,115 @@ -# -*- coding: utf-8 -*- -""" -Changed on Fr Dec 23 16:49:50 2022 - -@author: RobinC -""" +"""Receive command line arguments.""" import argparse import logging -import main - -class CLI(): - def create_parser(self): - """This function creates the parser""" - - parser = argparse.ArgumentParser( - prog = 'PrimingSitePredictor', - description = 'Takes a cutoff energy and the predicts location of priming sites of transcripts', - epilog = 'To predict or not to predict') - parser.add_argument('--float', type=float, required=True, help='A energy-cutoff float number') - parsed_args = parser.parse_args() - energy_cutoff = parsed_args.float - return energy_cutoff - - def letsgo(self): - """This function creates a parser and prints the energycutoff""" - energy_cutoff = CLI.create_parser() - print(f"Your energy cutoff is {energy_cutoff}") - -if __name__ == '__main__': +from primingsitepredictor.prime_site_predictor import CreatePrimer +from primingsitepredictor.prime_site_predictor import PrimingSitePredictor + +LOG = logging.getLogger(__name__) + + +def main(): + """Use CLI arguments to predict priming sites.""" + args = parse_args() + setup_logging() + LOG.info("Starting Priming Site Predictor...") + + if args.primer_sequence is None: + primer = CreatePrimer().create_fasta() + args.primer_sequence = primer + + predicted_sites = PrimingSitePredictor( + args.fasta_file, args.primer_sequence, args.energy_cutoff, + args.riblast_output, args.output_filename + ) + + predicted_sites.generate_gtf() + + LOG.info("Priming Site Predictor finished.") + + +def setup_logging() -> None: + """Configure logging. + + Args: + verbosity: Level of logging verbosity. + """ logging.basicConfig( - format='[%(asctime)s: %(levelname)s] %(message)s (module "%(module)s")', + format='[%(asctime)s: %(levelname)s] %(message)s \ + (module "%(module)s")', level=logging.INFO, + ) + + +def parse_args(): + """Parse arguments for CLI.""" + parser = argparse.ArgumentParser( + description="Compute potential priming sites using RIBlast." + ) + parser.add_argument( + "-f", "--fasta-file", + help="Fasta-formatted file of transcript sequences" + ) + parser.add_argument( + "-p", "--primer-sequence", default=None, + help="Primer sequence" ) - LOG = logging.getLogger(__name__) + parser.add_argument( + "-e", "--energy-cutoff", type=float, + help="Energy cutoff for interactions" + ) + parser.add_argument( + "-r", "--riblast-output", + help="Path to RIBlast output file" + ) + parser.add_argument( + "-o", "--output-filename", + help="Path where the output gtf should be written" + ) + args = parser.parse_args() + + return args + + +if __name__ == "__main__": main() + +# def main(): +# """Execute generate_RIBlast.""" +# generate_riblast_input() + + +# def generate_riblast_input(): +# """Create a list of the filenames for the RIBlast.""" +# my_primer = CreatePrimer() +# my_primer.create_fasta() +# primer_filename = my_primer.name + ".fasta" +# transcripts_filename = "transcripts.fasta" + +# return [primer_filename, transcripts_filename] + + +# def create_gtf(): +# """Create gtf.""" +# gtf_file = PostProcessRIBlast().output +# print(gtf_file) + + +# def create_parser(): +# """Create a parser.""" +# parser = argparse.ArgumentParser( +# prog='PrimingSitePredictor', +# description='Takes a cutoff energy and the predicts \ +# location of priming sites of transcripts', +# epilog='To predict or not to predict') +# parser.add_argument('--float', type=float, required=True, +# help='An energy-cutoff float number') +# parsed_args = parser.parse_args() +# energy_cutoff = parsed_args.float +# return energy_cutoff + + +# def letsgo(): +# """Create a parser and print the energycutoff.""" +# energy_cutoff = create_parser() +# print(f"Your energy cutoff is {energy_cutoff}") diff --git a/primingsitepredictor/createprimer.py b/primingsitepredictor/createprimer.py deleted file mode 100644 index 8dcd2329f74f6f0c6254ff428dd323aa9bf8fe53..0000000000000000000000000000000000000000 --- a/primingsitepredictor/createprimer.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Changed on Fr Dec 23 14:34:20 2022 - -@author: RobinC -""" - -class CreatePrimer: - """This Class creates an instance of a primer of a desired length and primer name - which can be saved as a fasta file. By default the length is 15 and name is primer1""" - def __init__(self, name='primer1', primerlength=15): - self.name = name - self.primer_length = primerlength - self.primer_sequence = 'T'*self.primer_length - self.lines = [f'<{self.name}', self.primer_sequence] - - - def create_fasta(self): - with open(f'{self.name}.fasta', 'w') as f: - for line in self.lines: - f.write(line) - f.write('\n') - - - - diff --git a/primingsitepredictor/main.py b/primingsitepredictor/main.py deleted file mode 100644 index d8d80b1e26440880da3aaacd2ffa336ebe0a95cf..0000000000000000000000000000000000000000 --- a/primingsitepredictor/main.py +++ /dev/null @@ -1,30 +0,0 @@ -""" -Changed on Tue Dec 20 14:06:20 2022 - -@author: RobinC -""" -import sys -from createprimer import CreatePrimer -from postprocessing import PostProcessRIBlast - - -def main(): - generate_RIBlast_input() - - - -def generate_RIBlast_input(): - """This function creates a list of the filenames for the RIBlast""" - my_primer = CreatePrimer() - my_primer.create_fasta() - primer_filename = my_primer.name +".fasta" - transcripts_filename = "transcripts.fasta" - - return [primer_filename, transcripts_filename] - -def create_gtf(): - gtf_file = PostProcessRIBlast().output - print(gtf_file) - -if __name__ == '__main__': - main() diff --git a/primingsitepredictor/my_primer.fasta b/primingsitepredictor/my_primer.fasta deleted file mode 100644 index 70ef81c7f1201827c1886f6cf15efec0ec65ecf3..0000000000000000000000000000000000000000 --- a/primingsitepredictor/my_primer.fasta +++ /dev/null @@ -1,2 +0,0 @@ -<my_primer -TTTTTTTTTTTTTTTTTTTT diff --git a/primingsitepredictor/output_transcripts_df.txt b/primingsitepredictor/output_transcripts_df.txt deleted file mode 100644 index 89ba6f367701e787b727d3602c241853c88d61d8..0000000000000000000000000000000000000000 --- a/primingsitepredictor/output_transcripts_df.txt +++ /dev/null @@ -1,33 +0,0 @@ -Transcript_1 RIBlast Priming_site 2974 2988 . + . Interaction_Energy "0.01341899394212988" -Transcript_1 RIBlast Priming_site 4 18 . + . Interaction_Energy "0.029617468622161858" -Transcript_1 RIBlast Priming_site 3 17 . + . Interaction_Energy "0.033652793432239245" -Transcript_1 RIBlast Priming_site 2 16 . + . Interaction_Energy "0.0436763978338453" -Transcript_1 RIBlast Priming_site 1 15 . + . Interaction_Energy "0.07361927731913716" -Transcript_1 RIBlast Priming_site 0 14 . + . Interaction_Energy "0.07913386517826602" -Transcript_2 RIBlast Priming_site 1270 1284 . + . Interaction_Energy "0.023871738821072214" -Transcript_2 RIBlast Priming_site 1269 1283 . + . Interaction_Energy "0.021998205780680843" -Transcript_2 RIBlast Priming_site 1268 1282 . + . Interaction_Energy "0.02017380792576395" -Transcript_2 RIBlast Priming_site 1267 1281 . + . Interaction_Energy "0.018400390375292373" -Transcript_2 RIBlast Priming_site 1266 1280 . + . Interaction_Energy "0.016661952134191884" -Transcript_2 RIBlast Priming_site 1265 1279 . + . Interaction_Energy "0.015028790572682043" -Transcript_2 RIBlast Priming_site 1264 1278 . + . Interaction_Energy "0.013507972357530618" -Transcript_2 RIBlast Priming_site 1263 1277 . + . Interaction_Energy "0.012121303370956734" -Transcript_2 RIBlast Priming_site 1262 1276 . + . Interaction_Energy "0.0108940605154748" -Transcript_2 RIBlast Priming_site 1261 1275 . + . Interaction_Energy "0.009818208415333858" -Transcript_2 RIBlast Priming_site 1260 1274 . + . Interaction_Energy "0.008876574189642966" -Transcript_2 RIBlast Priming_site 1259 1273 . + . Interaction_Energy "0.00807212607564225" -Transcript_2 RIBlast Priming_site 1258 1272 . + . Interaction_Energy "0.007386053280385996" -Transcript_2 RIBlast Priming_site 1257 1271 . + . Interaction_Energy "0.006777457533826199" -Transcript_2 RIBlast Priming_site 1256 1270 . + . Interaction_Energy "0.006231339626935633" -Transcript_2 RIBlast Priming_site 1255 1269 . + . Interaction_Energy "0.005701431631106869" -Transcript_2 RIBlast Priming_site 1254 1268 . + . Interaction_Energy "0.005221962850186007" -Transcript_2 RIBlast Priming_site 1253 1267 . + . Interaction_Energy "0.004743243630707861" -Transcript_2 RIBlast Priming_site 1252 1266 . + . Interaction_Energy "0.0043514767009977685" -Transcript_2 RIBlast Priming_site 1251 1265 . + . Interaction_Energy "0.004001246269203596" -Transcript_2 RIBlast Priming_site 1250 1264 . + . Interaction_Energy "0.0035602658910861193" -Transcript_2 RIBlast Priming_site 1249 1263 . + . Interaction_Energy "0.0034681706680775195" -Transcript_2 RIBlast Priming_site 1248 1262 . + . Interaction_Energy "0.003588271464203091" -Transcript_2 RIBlast Priming_site 1247 1261 . + . Interaction_Energy "0.0037963420302257692" -Transcript_2 RIBlast Priming_site 1246 1260 . + . Interaction_Energy "0.004081499678888505" -Transcript_2 RIBlast Priming_site 1245 1259 . + . Interaction_Energy "0.004411927146940477" -Transcript_2 RIBlast Priming_site 1244 1258 . + . Interaction_Energy "0.00480978620121743" diff --git a/primingsitepredictor/postprocessing.py b/primingsitepredictor/postprocessing.py deleted file mode 100644 index e2504e0f98e7a6527f508715d018aace78066c5c..0000000000000000000000000000000000000000 --- a/primingsitepredictor/postprocessing.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Tue Dec 20 14:06:20 2022 - -@author: baerma -""" - -import pandas as pd -import math -pd.options.mode.chained_assignment = None - -class PostProcessRIBlast(): - - def __init__(self): - output = self.generate_gtf() - #print(output) - - - def calculate_energy(self, value): - energy_constant = 1.380649*10**(-23)*298 - kcalmol_joul = 6.9477*10**-21 - return (math.exp(-float(value)*kcalmol_joul/energy_constant)) - - - def create_list_from_output(self): - self.file = "RIBlast output example.txt" - self.firstline = 3 - self.interaction_list = [] - with open(self.file, 'r') as file: - self.raw_interactions = file.readlines()[self.firstline:] - self.number_entries = len(self.raw_interactions) - - for i in range(0, self.number_entries-1): - current_interaction = self.raw_interactions[i].strip(' \n').replace('(', '').replace(')','').replace('-',',').replace(':',',').split(',') - self.interaction_list.append(current_interaction) - - return self.interaction_list - - - def create_pandas_df(self): - self.interaction_list = self.create_list_from_output() - self.df = pd.DataFrame(self.interaction_list) - self.df['Number_of_interactions'] = int(0) - self.df['Interaction_Energy'] = float(0) - self.transcript = 3 - self.energy = 5 - - for index in self.df.index: - self.df['Number_of_interactions'][index]=self.df[self.transcript].value_counts()[self.df[self.transcript][index]] - self.df['Interaction_Energy'][index]=self.calculate_energy(self.df[self.energy][index]) - - self.df['Normalised_interaction_energy']=self.df['Interaction_Energy']/self.df['Number_of_interactions'] - - return self.df - - - def generate_gtf(self): - self.interaction_df = self.create_pandas_df() - self.output = str() - - for index in self.interaction_df.index: - self.output = self.output + str(self.interaction_df[3][index]+'\t' + 'RIBlast' + '\t' + 'Priming_site' + '\t' + self.interaction_df[13][index] + '\t' + self.interaction_df[12][index] + '\t' + '.' + '\t' + '+' + '\t' + '.' + '\t' + f'Interaction_Energy "{self.interaction_df["Normalised_interaction_energy"][index]}"' + '\n') - - with open('output_transcripts_df.GTF', 'w') as f: - f.write(self.output) - return(self.output) - - -print(PostProcessRIBlast().output) \ No newline at end of file diff --git a/primingsitepredictor/prime_site_predictor.py b/primingsitepredictor/prime_site_predictor.py new file mode 100644 index 0000000000000000000000000000000000000000..bbc3cd31e1ca2ab7eeb7e05e23beb94658b7acc0 --- /dev/null +++ b/primingsitepredictor/prime_site_predictor.py @@ -0,0 +1,119 @@ +"""Main module for Priming Site Predictor.""" +import math +import logging +import pandas as pd # type: ignore + +LOG = logging.getLogger(__name__) + + +# pylint: disable=R0903 +class CreatePrimer: + """Create an instance of a primer of a desired length \ + and primer name which can be saved as a fasta file. + + By default the length is 15 and name is primer. + """ + + def __init__(self, name='primer', primerlength=15): + """Initiate function.""" + self.name = name + self.primer_length = primerlength + self.primer_sequence = 'T'*self.primer_length + self.lines = [f'<{self.name}', self.primer_sequence] + + def create_fasta(self): + """Create primer fasta file.""" + primer = self.lines + LOG.info("Created primer.") + with open(f'{self.name}.fasta', 'w', encoding="utf-8") as file: + file.write('\n'.join(self.lines)) + return primer + + +# pylint: disable=R0913 +class PrimingSitePredictor: + """Generate primer sites based on RIBlast results.""" + + # pylint: disable=R0913 + def __init__( + self, fasta_file, primer_sequence, energy_cutoff, + riblast_output, output_filename + ): + """Initiate.""" + self.fasta_file = fasta_file + self.primer_sequence = primer_sequence + self.energy_cutoff = energy_cutoff + self.riblast_output = riblast_output + self.output_filename = output_filename + + def calculate_energy(self, value): + """Calculate hybridization energy.""" + energy_constant = 1.380649e-23*298 + kcalmol_joul = 6.9477*10**-21 + return (math.exp(-float(value)*kcalmol_joul/energy_constant)) + + def create_list_from_output(self): + """Create list from output.""" + firstline = 3 + interaction_list = [] + with open(self.riblast_output, 'r', encoding="utf-8") as file: + raw_interactions = file.readlines()[firstline:] + number_entries = len(raw_interactions) + + for i in range(0, number_entries-1): + current_interaction = raw_interactions[i].strip( + ' \n').replace('(', '').replace(')', '').replace( + '-', ',').replace(':', ',').split(',') + interaction_list.append(current_interaction) + + return interaction_list + + def create_pandas_df(self): + """Create interaction df.""" + interaction_list = self.create_list_from_output() + interaction_df = pd.DataFrame(interaction_list) + interaction_df['Number_of_interactions'] = int(0) + interaction_df['Interaction_Energy'] = float(0) + transcript = 3 + energy = 5 + + for _ in interaction_df.index: + interaction_df['Number_of_interactions'] = interaction_df[ + transcript + ].apply( + lambda x: interaction_df[transcript].value_counts()[x] + ) + interaction_df['Interaction_Energy'] = interaction_df[ + energy + ].apply(self.calculate_energy) + + LOG.info("Calculating normalised interaction energies...") + interaction_df['Normalised_interaction_energy'] = interaction_df[ + 'Interaction_Energy']/interaction_df['Number_of_interactions'] + + return interaction_df + + def generate_gtf(self): + """Generate gtf file.""" + interaction_df = self.create_pandas_df() + result = str() + + for index in interaction_df.index: + result += ( + str(interaction_df[3][index]) + + '\tRIBlast\tPriming_site\t' + + str(interaction_df[13][index]) + + '\t' + + str(interaction_df[12][index]) + + '\t.\t+\t.\t' + + 'Interaction_Energy' + '\t' + + str(interaction_df[ + "Normalised_interaction_energy" + ][index]) + + '\n' + ) + + LOG.info("Generating output gtf file...") + with open(self.output_filename, 'w', encoding="utf-8") as file: + file.write(result) + return result diff --git a/primingsitepredictor/test/RIBlast output example.txt b/primingsitepredictor/test/RIBlast output example.txt deleted file mode 100644 index f3a270893926da9f8b302af5b15dbed875a6475f..0000000000000000000000000000000000000000 --- a/primingsitepredictor/test/RIBlast output example.txt +++ /dev/null @@ -1,37 +0,0 @@ -RIblast ris result -input:queryRNA.fa,database:test_db,RepeatFlag:0,MaximalSpan:70,MinAccessibleLength:5,MaxSeedLength:20,InteractionEnergyThreshold:-4,HybridEnergyThreshold:-6,FinalThreshold:-8,DropOutLengthWoGap:5,DropOutLengthWGap:16 -Id,Query name, Query Length, Target name, Target Length, Accessibility Energy, Hybridization Energy, Interaction Energy, BasePair -0,Test_Primer,15,Transcript_1,3233,1.49191,-9.76,-8.26809,(0-14:2988-2974) -1,Test_Primer,15,Transcript_1,3233,1.02308,-9.76,-8.73692,(0-14:18-4) -2,Test_Primer,15,Transcript_1,3233,0.947439,-9.73,-8.78256,(0-14:17-3) -3,Test_Primer,15,Transcript_1,3233,0.793049,-9.73,-8.93695,(0-14:16-2) -4,Test_Primer,15,Transcript_1,3233,0.483869,-9.73,-9.24613,(0-14:15-1) -5,Test_Primer,15,Transcript_1,3233,0.441093,-9.17,-8.72891,(0-14:14-0) -6,Test_Primer,15,Transcript_2,1285,0.260102,-9.1,-8.8399,(0-14:1284-1270) -7,Test_Primer,15,Transcript_2,1285,0.308504,-9.73,-9.4215,(0-14:1283-1269) -8,Test_Primer,15,Transcript_2,1285,0.359773,-9.73,-9.37023,(0-14:1282-1268) -9,Test_Primer,15,Transcript_2,1285,0.414262,-9.73,-9.31574,(0-14:1281-1267) -10,Test_Primer,15,Transcript_2,1285,0.473033,-9.73,-9.25697,(0-14:1280-1266) -11,Test_Primer,15,Transcript_2,1285,0.534123,-9.73,-9.19588,(0-14:1279-1265) -12,Test_Primer,15,Transcript_2,1285,0.597302,-9.73,-9.1327,(0-14:1278-1264) -13,Test_Primer,15,Transcript_2,1285,0.661445,-9.73,-9.06855,(0-14:1277-1263) -14,Test_Primer,15,Transcript_2,1285,0.724659,-9.73,-9.00534,(0-14:1276-1262) -15,Test_Primer,15,Transcript_2,1285,0.786234,-9.73,-8.94377,(0-14:1275-1261) -16,Test_Primer,15,Transcript_2,1285,0.84594,-9.73,-8.88406,(0-14:1274-1260) -17,Test_Primer,15,Transcript_2,1285,0.902197,-9.73,-8.8278,(0-14:1273-1259) -18,Test_Primer,15,Transcript_2,1285,0.954797,-9.73,-8.7752,(0-14:1272-1258) -19,Test_Primer,15,Transcript_2,1285,1.00572,-9.73,-8.72428,(0-14:1271-1257) -20,Test_Primer,15,Transcript_2,1285,1.05547,-9.73,-8.67453,(0-14:1270-1256) -21,Test_Primer,15,Transcript_2,1285,1.1081,-9.73,-8.6219,(0-14:1269-1255) -22,Test_Primer,15,Transcript_2,1285,1.16012,-9.73,-8.56988,(0-14:1268-1254) -23,Test_Primer,15,Transcript_2,1285,1.21706,-9.73,-8.51294,(0-14:1267-1253) -24,Test_Primer,15,Transcript_2,1285,1.26811,-9.73,-8.46189,(0-14:1266-1252) -25,Test_Primer,15,Transcript_2,1285,1.3178,-9.73,-8.4122,(0-14:1265-1251) -26,Test_Primer,15,Transcript_2,1285,1.38695,-9.73,-8.34305,(0-14:1264-1250) -27,Test_Primer,15,Transcript_2,1285,1.40247,-9.73,-8.32753,(0-14:1263-1249) -28,Test_Primer,15,Transcript_2,1285,1.38231,-9.73,-8.34769,(0-14:1262-1248) -29,Test_Primer,15,Transcript_2,1285,1.34893,-9.73,-8.38107,(0-14:1261-1247) -30,Test_Primer,15,Transcript_2,1285,1.30604,-9.73,-8.42396,(0-14:1260-1246) -31,Test_Primer,15,Transcript_2,1285,1.25994,-9.73,-8.47006,(0-14:1259-1245) -32,Test_Primer,15,Transcript_2,1285,1.20881,-9.76,-8.55119,(0-14:1258-1244) -33,Test_Primer,15,Transcript_2,1285,1.63873,-9.91,-8.27127,(0-14:674-660) diff --git a/primingsitepredictor/test/__init__.py b/primingsitepredictor/test/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/primingsitepredictor/test/output_transcripts_df.GTF b/primingsitepredictor/test/output_transcripts_df.GTF deleted file mode 100644 index 89ba6f367701e787b727d3602c241853c88d61d8..0000000000000000000000000000000000000000 --- a/primingsitepredictor/test/output_transcripts_df.GTF +++ /dev/null @@ -1,33 +0,0 @@ -Transcript_1 RIBlast Priming_site 2974 2988 . + . Interaction_Energy "0.01341899394212988" -Transcript_1 RIBlast Priming_site 4 18 . + . Interaction_Energy "0.029617468622161858" -Transcript_1 RIBlast Priming_site 3 17 . + . Interaction_Energy "0.033652793432239245" -Transcript_1 RIBlast Priming_site 2 16 . + . Interaction_Energy "0.0436763978338453" -Transcript_1 RIBlast Priming_site 1 15 . + . Interaction_Energy "0.07361927731913716" -Transcript_1 RIBlast Priming_site 0 14 . + . Interaction_Energy "0.07913386517826602" -Transcript_2 RIBlast Priming_site 1270 1284 . + . Interaction_Energy "0.023871738821072214" -Transcript_2 RIBlast Priming_site 1269 1283 . + . Interaction_Energy "0.021998205780680843" -Transcript_2 RIBlast Priming_site 1268 1282 . + . Interaction_Energy "0.02017380792576395" -Transcript_2 RIBlast Priming_site 1267 1281 . + . Interaction_Energy "0.018400390375292373" -Transcript_2 RIBlast Priming_site 1266 1280 . + . Interaction_Energy "0.016661952134191884" -Transcript_2 RIBlast Priming_site 1265 1279 . + . Interaction_Energy "0.015028790572682043" -Transcript_2 RIBlast Priming_site 1264 1278 . + . Interaction_Energy "0.013507972357530618" -Transcript_2 RIBlast Priming_site 1263 1277 . + . Interaction_Energy "0.012121303370956734" -Transcript_2 RIBlast Priming_site 1262 1276 . + . Interaction_Energy "0.0108940605154748" -Transcript_2 RIBlast Priming_site 1261 1275 . + . Interaction_Energy "0.009818208415333858" -Transcript_2 RIBlast Priming_site 1260 1274 . + . Interaction_Energy "0.008876574189642966" -Transcript_2 RIBlast Priming_site 1259 1273 . + . Interaction_Energy "0.00807212607564225" -Transcript_2 RIBlast Priming_site 1258 1272 . + . Interaction_Energy "0.007386053280385996" -Transcript_2 RIBlast Priming_site 1257 1271 . + . Interaction_Energy "0.006777457533826199" -Transcript_2 RIBlast Priming_site 1256 1270 . + . Interaction_Energy "0.006231339626935633" -Transcript_2 RIBlast Priming_site 1255 1269 . + . Interaction_Energy "0.005701431631106869" -Transcript_2 RIBlast Priming_site 1254 1268 . + . Interaction_Energy "0.005221962850186007" -Transcript_2 RIBlast Priming_site 1253 1267 . + . Interaction_Energy "0.004743243630707861" -Transcript_2 RIBlast Priming_site 1252 1266 . + . Interaction_Energy "0.0043514767009977685" -Transcript_2 RIBlast Priming_site 1251 1265 . + . Interaction_Energy "0.004001246269203596" -Transcript_2 RIBlast Priming_site 1250 1264 . + . Interaction_Energy "0.0035602658910861193" -Transcript_2 RIBlast Priming_site 1249 1263 . + . Interaction_Energy "0.0034681706680775195" -Transcript_2 RIBlast Priming_site 1248 1262 . + . Interaction_Energy "0.003588271464203091" -Transcript_2 RIBlast Priming_site 1247 1261 . + . Interaction_Energy "0.0037963420302257692" -Transcript_2 RIBlast Priming_site 1246 1260 . + . Interaction_Energy "0.004081499678888505" -Transcript_2 RIBlast Priming_site 1245 1259 . + . Interaction_Energy "0.004411927146940477" -Transcript_2 RIBlast Priming_site 1244 1258 . + . Interaction_Energy "0.00480978620121743" diff --git a/primingsitepredictor/test/output_transcripts_df.txt b/primingsitepredictor/test/output_transcripts_df.txt deleted file mode 100644 index 89ba6f367701e787b727d3602c241853c88d61d8..0000000000000000000000000000000000000000 --- a/primingsitepredictor/test/output_transcripts_df.txt +++ /dev/null @@ -1,33 +0,0 @@ -Transcript_1 RIBlast Priming_site 2974 2988 . + . Interaction_Energy "0.01341899394212988" -Transcript_1 RIBlast Priming_site 4 18 . + . Interaction_Energy "0.029617468622161858" -Transcript_1 RIBlast Priming_site 3 17 . + . Interaction_Energy "0.033652793432239245" -Transcript_1 RIBlast Priming_site 2 16 . + . Interaction_Energy "0.0436763978338453" -Transcript_1 RIBlast Priming_site 1 15 . + . Interaction_Energy "0.07361927731913716" -Transcript_1 RIBlast Priming_site 0 14 . + . Interaction_Energy "0.07913386517826602" -Transcript_2 RIBlast Priming_site 1270 1284 . + . Interaction_Energy "0.023871738821072214" -Transcript_2 RIBlast Priming_site 1269 1283 . + . Interaction_Energy "0.021998205780680843" -Transcript_2 RIBlast Priming_site 1268 1282 . + . Interaction_Energy "0.02017380792576395" -Transcript_2 RIBlast Priming_site 1267 1281 . + . Interaction_Energy "0.018400390375292373" -Transcript_2 RIBlast Priming_site 1266 1280 . + . Interaction_Energy "0.016661952134191884" -Transcript_2 RIBlast Priming_site 1265 1279 . + . Interaction_Energy "0.015028790572682043" -Transcript_2 RIBlast Priming_site 1264 1278 . + . Interaction_Energy "0.013507972357530618" -Transcript_2 RIBlast Priming_site 1263 1277 . + . Interaction_Energy "0.012121303370956734" -Transcript_2 RIBlast Priming_site 1262 1276 . + . Interaction_Energy "0.0108940605154748" -Transcript_2 RIBlast Priming_site 1261 1275 . + . Interaction_Energy "0.009818208415333858" -Transcript_2 RIBlast Priming_site 1260 1274 . + . Interaction_Energy "0.008876574189642966" -Transcript_2 RIBlast Priming_site 1259 1273 . + . Interaction_Energy "0.00807212607564225" -Transcript_2 RIBlast Priming_site 1258 1272 . + . Interaction_Energy "0.007386053280385996" -Transcript_2 RIBlast Priming_site 1257 1271 . + . Interaction_Energy "0.006777457533826199" -Transcript_2 RIBlast Priming_site 1256 1270 . + . Interaction_Energy "0.006231339626935633" -Transcript_2 RIBlast Priming_site 1255 1269 . + . Interaction_Energy "0.005701431631106869" -Transcript_2 RIBlast Priming_site 1254 1268 . + . Interaction_Energy "0.005221962850186007" -Transcript_2 RIBlast Priming_site 1253 1267 . + . Interaction_Energy "0.004743243630707861" -Transcript_2 RIBlast Priming_site 1252 1266 . + . Interaction_Energy "0.0043514767009977685" -Transcript_2 RIBlast Priming_site 1251 1265 . + . Interaction_Energy "0.004001246269203596" -Transcript_2 RIBlast Priming_site 1250 1264 . + . Interaction_Energy "0.0035602658910861193" -Transcript_2 RIBlast Priming_site 1249 1263 . + . Interaction_Energy "0.0034681706680775195" -Transcript_2 RIBlast Priming_site 1248 1262 . + . Interaction_Energy "0.003588271464203091" -Transcript_2 RIBlast Priming_site 1247 1261 . + . Interaction_Energy "0.0037963420302257692" -Transcript_2 RIBlast Priming_site 1246 1260 . + . Interaction_Energy "0.004081499678888505" -Transcript_2 RIBlast Priming_site 1245 1259 . + . Interaction_Energy "0.004411927146940477" -Transcript_2 RIBlast Priming_site 1244 1258 . + . Interaction_Energy "0.00480978620121743" diff --git a/primingsitepredictor/test/test_cli.py b/primingsitepredictor/test/test_cli.py deleted file mode 100644 index dec66a1765914a96fbb354b33bcbbd07694833a7..0000000000000000000000000000000000000000 --- a/primingsitepredictor/test/test_cli.py +++ /dev/null @@ -1,103 +0,0 @@ -""" -Created on Tue Dec 20 14:06:20 2022 - -@author: RobinC -""" - -# Imports -import os, sys -import pytest -currentdir = os.path.dirname(os.path.realpath(__file__)) -parentdir = os.path.dirname(currentdir) -sys.path.append(parentdir) -import createprimer as cp -import unittest -import cli -import argparse -import pytest -from unittest.mock import patch -from unittest.mock import Mock -import io -import sys - -class TestCli(unittest.TestCase): - - def test_import(self): - """Test function for module imports""" - try: - import argparse - except ImportError: - self.fail("Failed to import argparse") - - try: - import logging - except ImportError: - self.fail("Failed to import logging") - - try: - import main - except ImportError: - self.fail("Failed to import main") - - - - def test_create_parser(self): - - # Test parsing a float number - float_num = 3.14 - float_str = str(float_num) - self.assertEqual(float_num, cli.CLI.create_parser(['--float', float_str])) - - # Test parsing a float number with leading and trailing whitespace - float_num = 3.14 - float_str = " " + str(float_num) + " " - self.assertEqual(float_num, cli.CLI.create_parser(['--float', float_str])) - - # Test parsing a float number with a decimal point and no digits after it - float_num = 3. - float_str = str(float_num) - self.assertEqual(float_num, cli.CLI.create_parser(['--float', float_str])) - - # Test parsing a float number with a decimal point and multiple digits after it - float_num = 3.14159 - float_str = str(float_num) - self.assertEqual(float_num, cli.CLI.create_parser(['--float', float_str])) - - # Test parsing a negative float number - float_num = -3.14 - float_str = str(float_num) - self.assertEqual(float_num, cli.CLI.create_parser(['--float', float_str])) - - def test_invalid_create_parser(self): - - # Test parsing a float number with a letter in it - args = ['--float', '3.14a'] - with self.assertRaises(SystemExit): - cli.CLI.create_parser(args) - - # Test parsing a float number with multiple decimal points - args = ['--float', '3.14.159'] - with self.assertRaises(SystemExit): - cli.CLI.create_parser(args) - - def test_letsgo(self): - - # Test printing a float number - float_num = 3.14 - float_str = str(float_num) - with self.assertLogs('', level='INFO') as cm: - cli.CLI.letsgo(['--float', float_str]) - self.assertEqual(cm.output, [f'INFO:root:Your energy cutoff is {float_num}']) - - - - - - - - - - - - - diff --git a/primingsitepredictor/test/test_createprimer.py b/primingsitepredictor/test/test_createprimer.py deleted file mode 100644 index a54ad9c01245b741d89346851b1b3a7c76ff726d..0000000000000000000000000000000000000000 --- a/primingsitepredictor/test/test_createprimer.py +++ /dev/null @@ -1,71 +0,0 @@ -""" -Created on Tue Dec 20 14:06:20 2022 - -@author: RobinC -""" - -import os, sys -import pytest -currentdir = os.path.dirname(os.path.realpath(__file__)) -parentdir = os.path.dirname(currentdir) -sys.path.append(parentdir) -import createprimer as cp -import unittest - - -class TestCreatePrimer(unittest.TestCase): - - def test_init(self): - """Test function for the __init__() method""" - - # Test default values - primer = cp.CreatePrimer() - self.assertEqual(primer.name, 'primer1') - self.assertEqual(primer.primer_length, 15) - self.assertEqual(primer.primer_sequence, 'T'*15) - self.assertEqual(primer.lines, ['<primer1', 'TTTTTTTTTTTTTTT']) - - # Test custom values - primer = cp.CreatePrimer('my_primer', 20) - self.assertEqual(primer.name, 'my_primer') - self.assertEqual(primer.primer_length, 20) - self.assertEqual(primer.primer_sequence, 'T'*20) - self.assertEqual(primer.lines, ['<my_primer', 'TTTTTTTTTTTTTTTTTTTT']) - - - def test_create_fasta(self): - """Test function for the test_create_fasta() method""" - - # Test default values - primer = cp.CreatePrimer() - primer.create_fasta() - with open('primer1.fasta', 'r') as f: - lines = f.readlines() - self.assertEqual(lines, ['<primer1\n', 'TTTTTTTTTTTTTTT\n']) - - # Test custom values - primer = cp.CreatePrimer('my_primer', 20) - primer.create_fasta() - with open('my_primer.fasta', 'r') as f: - lines = f.readlines() - self.assertEqual(lines, ['<my_primer\n', 'TTTTTTTTTTTTTTTTTTTT\n']) - - - - - - - - - - - - - - - - - - - - diff --git a/primingsitepredictor/test/test_postprocessing.py b/primingsitepredictor/test/test_postprocessing.py deleted file mode 100644 index 2948ef269fe44e369cd619e63ab930608e03dc8e..0000000000000000000000000000000000000000 --- a/primingsitepredictor/test/test_postprocessing.py +++ /dev/null @@ -1,157 +0,0 @@ -""" -Created on Tue Dec 20 14:06:20 2022 - -@author: RobinC -""" - -# Imports -import os, sys -import pytest - -currentdir = os.path.dirname(os.path.realpath(__file__)) -parentdir = os.path.dirname(currentdir) -sys.path.append(parentdir) -import postprocessing as pp -import unittest -import math -from unittest import mock - - -class TestPostProcessRIBlast(unittest.TestCase): - def test_import(self): - """Test function for module imports""" - try: - import pandas - except ImportError: - self.fail("Failed to import pandas") - - try: - import math - except ImportError: - self.fail("Failed to import math") - - def setUp(self): - """Setup function to create an instance of PostProcessRIBlast()""" - - self.post_processor = pp.PostProcessRIBlast() - - def test_init(self): - """Test function for the __init__() method""" - - # Test if generate_gtf method is being called - with unittest.mock.patch.object( - pp.PostProcessRIBlast, "generate_gtf" - ) as mock_generate_gtf: - pp.PostProcessRIBlast() - mock_generate_gtf.assert_called_once() - - # Test if generate_gtf returns the expected output - expected_output = ( - 'Transcript_1\tRIBlast\tPriming_site\t2974[3257 chars]3"\n' - ) - self.assertEqual(self.post_processor.generate_gtf(), expected_output) - - def test_calculate_energy(self): - """Test function for the calculate_energy() method""" - - def calculate_energy(value): - energy_constant = 1.380649*10**(-23)*298 - kcalmol_joul = 6.9477*10**-21 - return (math.exp(-float(value)*kcalmol_joul/energy_constant)) - - # set a decimal place - decimalPlace = 20 - - # Test for a positive value - self.testinstance = pp.PostProcessRIBlast.calculate_energy(self, 5.0) - expected_output = calculate_energy(5.0) - self.assertAlmostEqual(self.testinstance, expected_output, decimalPlace) - - - # Test for a negative value - self.testinstance = pp.PostProcessRIBlast.calculate_energy(self, -5.0) - expected_output = calculate_energy(-5.0) - self.assertAlmostEqual(self.testinstance, expected_output, decimalPlace) - - # Test for zero - self.testinstance = pp.PostProcessRIBlast.calculate_energy(self, 0) - expected_output = calculate_energy(0) - self.assertAlmostEqual(self.testinstance, expected_output, decimalPlace) - - - def test_create_list_from_output(self): - """Test function for the create_list_from_output() method""" - - #create an instance test of the class PostProcessRIBlast() - test = pp.PostProcessRIBlast() - test.file = "RIBlast output example.txt" - - with open('RIBlast output example.txt', 'r') as file: - data_list = file.readlines() - - # Remove the header - data_list = data_list[3:] - - # Convert each row of the list into a list of values - expected_output = [] - for row in data_list: - # Split the row by the comma character - values = row.strip().split(',') - # Append the list of values to the final list - expected_output.append(values) - return expected_output - self.assertEqual(test.create_list_from_output(), expected_output) - - - def test_create_pandas_df(self): - """Test function for the create_pandas_df() method with mock data""" - - # create a test instance - test_instance = pp.PostProcessRIBlast() - - # create some mock data for the input list - test_instance.interaction_list= [ - ['Id','Query name', 'Query Length', 'Target name', 'Target Length', 'Accessibility Energy', 'Hybridization Energy', 'Interaction Energy', 'BasePair'], - [0,'Test_Primer',15,'Transcript_1',3233,1.49191,-9.76,-8.26809,'(0-14:2988-2974)'], - [1,'Test_Primer',15,'Transcript_1',3233,1.02308,-9.76,-8.73692,'(0-14:18-4)'], - [2,'Test_Primer',15,'Transcript_1',3233,0.947439,-9.73,-8.78256,'(0-14:17-3)'], - [3,'Test_Primer',15,'Transcript_1',3233,0.793049,-9.73,-8.93695,'(0-14:16-2)'], - [4,'Test_Primer',15,'Transcript_1',3233,0.483869,-9.73,-9.24613,'(0-14:15-1)'], - [5,'Test_Primer',15,'Transcript_1',3233,0.441093,-9.17,-8.72891,'(0-14:14-0)']] - - # create the DataFrame using the mock data - df = test_instance.create_pandas_df() - - #self.assertEqual(len(df),7) - - # check that the DataFrame has the expected column names - #self.assertEqual(list(df.columns), ['Id','Query name', 'Query Length', 'Target name', 'Target Length', 'Accessibility Energy', 'Hybridization Energy', 'Interaction Energy', 'BasePair']) - - # check that the values in the 'Id' column are correct - self.assertEqual(list(df['Id']), ['Id',0,1,2,3,4,5]) - - # check that the values in the 'Query name' column are correct - self.assertEqual(list(df['Query name']), ['Query name','Test_Primer','Test_Primer','Test_Primer','Test_Primer','Test_Primer','Test_Primer']) - - # check that the values in the 'Query Length' column are correct - self.assertEqual(list(df['Query Length']), ['Query Length',15, 15, 15, 15, 15, 15]) - - # check that the values in the 'Target name' column are correct - self.assertEqual(list(df['Target name']), ['Target name','Transcript_1','Transcript_1','Transcript_1','Transcript_1','Transcript_1','Transcript_1']) - - # check that the values in the 'Target Length' column are correct - self.assertEqual(list(df['Target Length']), ['Target Length', 3233, 3233, 3233, 3233, 3233, 3233]) - - # check that the values in the 'Accessibility Energy' column are correct - self.assertEqual(list(df['Accessibility Energy']), ['Accessibility Energy',1.49191, 1.02308, 0.947439, 0.793049, 0.483869, 0.441093]) - - # check that the values in the 'Hybridization Energy' column are correct - self.assertEqual(list(df['Hybridization Energy']), ['Hybridization Energy',-9.76, -9.76, -9.73, -9.73, -9.73, -9.17]) - - # check that the values in the 'Interaction Energy' column are correct - self.assertEqual(list(df['Interaction Energy']), ['Interaction Energy',-8.26809, -8.73692, -8.78256, -8.93695, -9.24613, -8.72891]) - - # check that the values in the 'BasePair' column are correct - self.assertEqual(list(df['BasePair']), ['BasePair','(0-14:2988-2974)', '(0-14:18-4)', '(0-14:17-3)', '(0-14:16-2)', '(0-14:15-1)', '(0-14:14-0)']) - - diff --git a/primingsitepredictor/test_fasta.fasta b/primingsitepredictor/test_fasta.fasta deleted file mode 100644 index 5b85943f52a87f58f84c34e9c994e97c2f5a4e9a..0000000000000000000000000000000000000000 --- a/primingsitepredictor/test_fasta.fasta +++ /dev/null @@ -1,2 +0,0 @@ -ATGC -CAGT diff --git a/primingsitepredictor/tests/.idea/.gitignore b/primingsitepredictor/tests/.idea/.gitignore deleted file mode 100644 index 13566b81b018ad684f3a35fee301741b2734c8f4..0000000000000000000000000000000000000000 --- a/primingsitepredictor/tests/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/primingsitepredictor/tests/.idea/inspectionProfiles/profiles_settings.xml b/primingsitepredictor/tests/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2da2d6447d11dfe32bfb846c3d5b199fc99..0000000000000000000000000000000000000000 --- a/primingsitepredictor/tests/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ -<component name="InspectionProjectProfileManager"> - <settings> - <option name="USE_PROJECT_PROFILE" value="false" /> - <version value="1.0" /> - </settings> -</component> \ No newline at end of file diff --git a/primingsitepredictor/tests/.idea/misc.xml b/primingsitepredictor/tests/.idea/misc.xml deleted file mode 100644 index e6a7aa474cd32e70c4d9694c40996d01e47c23fc..0000000000000000000000000000000000000000 --- a/primingsitepredictor/tests/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (tests)" project-jdk-type="Python SDK" /> -</project> \ No newline at end of file diff --git a/primingsitepredictor/tests/.idea/modules.xml b/primingsitepredictor/tests/.idea/modules.xml deleted file mode 100644 index dac5cbb11e9cf0c4d8aa824610212bb8d903b4bc..0000000000000000000000000000000000000000 --- a/primingsitepredictor/tests/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="ProjectModuleManager"> - <modules> - <module fileurl="file://$PROJECT_DIR$/.idea/tests.iml" filepath="$PROJECT_DIR$/.idea/tests.iml" /> - </modules> - </component> -</project> \ No newline at end of file diff --git a/primingsitepredictor/tests/.idea/tests.iml b/primingsitepredictor/tests/.idea/tests.iml deleted file mode 100644 index d0876a78d06ac03b5d78c8dcdb95570281c6f1d6..0000000000000000000000000000000000000000 --- a/primingsitepredictor/tests/.idea/tests.iml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module type="PYTHON_MODULE" version="4"> - <component name="NewModuleRootManager"> - <content url="file://$MODULE_DIR$" /> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - </component> -</module> \ No newline at end of file diff --git a/primingsitepredictor/tests/.idea/vcs.xml b/primingsitepredictor/tests/.idea/vcs.xml deleted file mode 100644 index b2bdec2d71b6a5ce4ae49efc37516809c50e4d5e..0000000000000000000000000000000000000000 --- a/primingsitepredictor/tests/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="VcsDirectoryMappings"> - <mapping directory="$PROJECT_DIR$/../.." vcs="Git" /> - </component> -</project> \ No newline at end of file diff --git a/primingsitepredictor/tests/in_output_examples/Example_GTF_Output.GTF b/primingsitepredictor/tests/in_output_examples/Example_GTF_Output.GTF deleted file mode 100644 index c3f3e7752ae658a71273a501ec0c90c0aa931386..0000000000000000000000000000000000000000 --- a/primingsitepredictor/tests/in_output_examples/Example_GTF_Output.GTF +++ /dev/null @@ -1,3 +0,0 @@ -Transcript_1 RIBlast Priming_site 10 25 . + . Accessibility_Energy "1.49"; Hybridization_Energy "-9.76"; Interaction_Energy "-8.74"; Number_of_binding_sites "2"; Binding_Probability "0.12" -Transcript_1 RIBlast Priming_site 640 655 . + . Accessibility_Energy "1.71"; Hybridization_Energy "-9.12"; Interaction_Energy "-8.34"; Number_of_binding_sites "2"; Binding_Probability "0.05" -Transcript_2 RIBlast Priming_site 3 18 . + . Accessibility_Energy "1.21"; Hybridization_Energy "-5.12"; Interaction_Energy "-2.34"; Number_of_binding_sites "1"; Binding_Probability "0.15" \ No newline at end of file diff --git a/primingsitepredictor/tests/in_output_examples/RIBlast output example.txt b/primingsitepredictor/tests/in_output_examples/RIBlast output example.txt deleted file mode 100644 index f3a270893926da9f8b302af5b15dbed875a6475f..0000000000000000000000000000000000000000 --- a/primingsitepredictor/tests/in_output_examples/RIBlast output example.txt +++ /dev/null @@ -1,37 +0,0 @@ -RIblast ris result -input:queryRNA.fa,database:test_db,RepeatFlag:0,MaximalSpan:70,MinAccessibleLength:5,MaxSeedLength:20,InteractionEnergyThreshold:-4,HybridEnergyThreshold:-6,FinalThreshold:-8,DropOutLengthWoGap:5,DropOutLengthWGap:16 -Id,Query name, Query Length, Target name, Target Length, Accessibility Energy, Hybridization Energy, Interaction Energy, BasePair -0,Test_Primer,15,Transcript_1,3233,1.49191,-9.76,-8.26809,(0-14:2988-2974) -1,Test_Primer,15,Transcript_1,3233,1.02308,-9.76,-8.73692,(0-14:18-4) -2,Test_Primer,15,Transcript_1,3233,0.947439,-9.73,-8.78256,(0-14:17-3) -3,Test_Primer,15,Transcript_1,3233,0.793049,-9.73,-8.93695,(0-14:16-2) -4,Test_Primer,15,Transcript_1,3233,0.483869,-9.73,-9.24613,(0-14:15-1) -5,Test_Primer,15,Transcript_1,3233,0.441093,-9.17,-8.72891,(0-14:14-0) -6,Test_Primer,15,Transcript_2,1285,0.260102,-9.1,-8.8399,(0-14:1284-1270) -7,Test_Primer,15,Transcript_2,1285,0.308504,-9.73,-9.4215,(0-14:1283-1269) -8,Test_Primer,15,Transcript_2,1285,0.359773,-9.73,-9.37023,(0-14:1282-1268) -9,Test_Primer,15,Transcript_2,1285,0.414262,-9.73,-9.31574,(0-14:1281-1267) -10,Test_Primer,15,Transcript_2,1285,0.473033,-9.73,-9.25697,(0-14:1280-1266) -11,Test_Primer,15,Transcript_2,1285,0.534123,-9.73,-9.19588,(0-14:1279-1265) -12,Test_Primer,15,Transcript_2,1285,0.597302,-9.73,-9.1327,(0-14:1278-1264) -13,Test_Primer,15,Transcript_2,1285,0.661445,-9.73,-9.06855,(0-14:1277-1263) -14,Test_Primer,15,Transcript_2,1285,0.724659,-9.73,-9.00534,(0-14:1276-1262) -15,Test_Primer,15,Transcript_2,1285,0.786234,-9.73,-8.94377,(0-14:1275-1261) -16,Test_Primer,15,Transcript_2,1285,0.84594,-9.73,-8.88406,(0-14:1274-1260) -17,Test_Primer,15,Transcript_2,1285,0.902197,-9.73,-8.8278,(0-14:1273-1259) -18,Test_Primer,15,Transcript_2,1285,0.954797,-9.73,-8.7752,(0-14:1272-1258) -19,Test_Primer,15,Transcript_2,1285,1.00572,-9.73,-8.72428,(0-14:1271-1257) -20,Test_Primer,15,Transcript_2,1285,1.05547,-9.73,-8.67453,(0-14:1270-1256) -21,Test_Primer,15,Transcript_2,1285,1.1081,-9.73,-8.6219,(0-14:1269-1255) -22,Test_Primer,15,Transcript_2,1285,1.16012,-9.73,-8.56988,(0-14:1268-1254) -23,Test_Primer,15,Transcript_2,1285,1.21706,-9.73,-8.51294,(0-14:1267-1253) -24,Test_Primer,15,Transcript_2,1285,1.26811,-9.73,-8.46189,(0-14:1266-1252) -25,Test_Primer,15,Transcript_2,1285,1.3178,-9.73,-8.4122,(0-14:1265-1251) -26,Test_Primer,15,Transcript_2,1285,1.38695,-9.73,-8.34305,(0-14:1264-1250) -27,Test_Primer,15,Transcript_2,1285,1.40247,-9.73,-8.32753,(0-14:1263-1249) -28,Test_Primer,15,Transcript_2,1285,1.38231,-9.73,-8.34769,(0-14:1262-1248) -29,Test_Primer,15,Transcript_2,1285,1.34893,-9.73,-8.38107,(0-14:1261-1247) -30,Test_Primer,15,Transcript_2,1285,1.30604,-9.73,-8.42396,(0-14:1260-1246) -31,Test_Primer,15,Transcript_2,1285,1.25994,-9.73,-8.47006,(0-14:1259-1245) -32,Test_Primer,15,Transcript_2,1285,1.20881,-9.76,-8.55119,(0-14:1258-1244) -33,Test_Primer,15,Transcript_2,1285,1.63873,-9.91,-8.27127,(0-14:674-660) diff --git a/primingsitepredictor/tests/test_createprimer.py b/primingsitepredictor/tests/test_createprimer.py deleted file mode 100644 index e18b3fd54bee637293e6a85e7b3725cd1f242487..0000000000000000000000000000000000000000 --- a/primingsitepredictor/tests/test_createprimer.py +++ /dev/null @@ -1,33 +0,0 @@ - -# Imports -import pytest -import createprimer as cp -import unittest -from unittest.mock import mock_open, patch -from examples.count_lines.file_reader import FileReader - -# Create an instance of the CreatePrimer class - -primer = cp.CreatePrimer( name='primer1', primerlength=15) - -# Test for the __init__ method -def test_init(self): - assert primer.name == primer.name - assert primer.primer_length == len(primer.primer_length) - with pytest.raises(ValueError): - primer.__init__(type(int), type(str)) - - -# Test for the create_fasta method -def test_CreateFasta(self): - fake_file_path = "fake/file/path" - content = "Message to write on file to be written" - with patch('examples.write_on_file.file_writer.open', mock_open()) as mocked_file: - FileWriter().write(fake_file_path, content) - - # assert if opened file on write mode 'w' - mocked_file.assert_called_once_with(fake_file_path, 'w') - - # assert if write(content) was called from the file opened - # in another words, assert if the specific content was written in file - mocked_file().write.assert_called_once_with(content) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..8a9674c77d5ed060f30942792d2e3f14540bd1a0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +argparse +biopython +numpy >= 1.23.3 +pandas >= 1.4.4 \ No newline at end of file diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000000000000000000000000000000000000..19f4ed8f0a9479b80aab6e5337d4c2efe1b31ed9 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,6 @@ +pytest +coverage +flake8 +flake8-docstrings +mypy +pylint diff --git a/setup.py b/setup.py index d86d1a3d6e6cb74dd17ff25a69d20d47a803b5d6..aa38ae3c01ec1050d6c98022c6b36ad794c98b60 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,28 @@ -from setuptools import setup +"""Set up project.""" +from pathlib import Path +from setuptools import setup, find_packages + +project_root_dir = Path(__file__).parent.resolve() +with open(project_root_dir / "requirements.txt", + "r", encoding="utf-8") as f: + INSTALL_REQUIRES = f.read().splitlines() + +URL = ('https://git.scicore.unibas.ch/zavolan_group/' + 'tools/priming-site-predictor') + + setup( - name = 'cli-primingsitepredictor', - url = 'https://git.scicore.unibas.ch/zavolan_group/tools/priming-site-predictor/-/tree/main/CLI', - author = 'Robin Christen & Max Baer', - author_email = 'robin.christen@stud.unibas.ch & max.baer@swisstph.ch', - description = 'Command-Line Interface', - license = 'MIT,', - version = '0.1.0', - packages = ['primingsitepredictor'], - entry_points = { + name='primingsitepredictor', + url=URL, + author='Robin Christen & Max Baer', + author_email='robin.christen@stud.unibas.ch & max.baer@swisstph.ch', + description='Priming Site Predictor', + license='MIT,', + version='0.1.0', + packages=find_packages(), + install_requires=INSTALL_REQUIRES, + entry_points={ 'console_scripts': [ - 'primingsitepredictor = primingsitepredictor.cli:letsgo' + 'primingsitepredictor = primingsitepredictor.cli:main' ] }) diff --git a/tests/in_output_examples/Example_GTF_Output.GTF b/tests/in_output_examples/Example_GTF_Output.GTF deleted file mode 100644 index c3f3e7752ae658a71273a501ec0c90c0aa931386..0000000000000000000000000000000000000000 --- a/tests/in_output_examples/Example_GTF_Output.GTF +++ /dev/null @@ -1,3 +0,0 @@ -Transcript_1 RIBlast Priming_site 10 25 . + . Accessibility_Energy "1.49"; Hybridization_Energy "-9.76"; Interaction_Energy "-8.74"; Number_of_binding_sites "2"; Binding_Probability "0.12" -Transcript_1 RIBlast Priming_site 640 655 . + . Accessibility_Energy "1.71"; Hybridization_Energy "-9.12"; Interaction_Energy "-8.34"; Number_of_binding_sites "2"; Binding_Probability "0.05" -Transcript_2 RIBlast Priming_site 3 18 . + . Accessibility_Energy "1.21"; Hybridization_Energy "-5.12"; Interaction_Energy "-2.34"; Number_of_binding_sites "1"; Binding_Probability "0.15" \ No newline at end of file diff --git a/tests/in_output_examples/RIBlast output example.txt b/tests/in_output_examples/RIBlast output example.txt deleted file mode 100644 index f3a270893926da9f8b302af5b15dbed875a6475f..0000000000000000000000000000000000000000 --- a/tests/in_output_examples/RIBlast output example.txt +++ /dev/null @@ -1,37 +0,0 @@ -RIblast ris result -input:queryRNA.fa,database:test_db,RepeatFlag:0,MaximalSpan:70,MinAccessibleLength:5,MaxSeedLength:20,InteractionEnergyThreshold:-4,HybridEnergyThreshold:-6,FinalThreshold:-8,DropOutLengthWoGap:5,DropOutLengthWGap:16 -Id,Query name, Query Length, Target name, Target Length, Accessibility Energy, Hybridization Energy, Interaction Energy, BasePair -0,Test_Primer,15,Transcript_1,3233,1.49191,-9.76,-8.26809,(0-14:2988-2974) -1,Test_Primer,15,Transcript_1,3233,1.02308,-9.76,-8.73692,(0-14:18-4) -2,Test_Primer,15,Transcript_1,3233,0.947439,-9.73,-8.78256,(0-14:17-3) -3,Test_Primer,15,Transcript_1,3233,0.793049,-9.73,-8.93695,(0-14:16-2) -4,Test_Primer,15,Transcript_1,3233,0.483869,-9.73,-9.24613,(0-14:15-1) -5,Test_Primer,15,Transcript_1,3233,0.441093,-9.17,-8.72891,(0-14:14-0) -6,Test_Primer,15,Transcript_2,1285,0.260102,-9.1,-8.8399,(0-14:1284-1270) -7,Test_Primer,15,Transcript_2,1285,0.308504,-9.73,-9.4215,(0-14:1283-1269) -8,Test_Primer,15,Transcript_2,1285,0.359773,-9.73,-9.37023,(0-14:1282-1268) -9,Test_Primer,15,Transcript_2,1285,0.414262,-9.73,-9.31574,(0-14:1281-1267) -10,Test_Primer,15,Transcript_2,1285,0.473033,-9.73,-9.25697,(0-14:1280-1266) -11,Test_Primer,15,Transcript_2,1285,0.534123,-9.73,-9.19588,(0-14:1279-1265) -12,Test_Primer,15,Transcript_2,1285,0.597302,-9.73,-9.1327,(0-14:1278-1264) -13,Test_Primer,15,Transcript_2,1285,0.661445,-9.73,-9.06855,(0-14:1277-1263) -14,Test_Primer,15,Transcript_2,1285,0.724659,-9.73,-9.00534,(0-14:1276-1262) -15,Test_Primer,15,Transcript_2,1285,0.786234,-9.73,-8.94377,(0-14:1275-1261) -16,Test_Primer,15,Transcript_2,1285,0.84594,-9.73,-8.88406,(0-14:1274-1260) -17,Test_Primer,15,Transcript_2,1285,0.902197,-9.73,-8.8278,(0-14:1273-1259) -18,Test_Primer,15,Transcript_2,1285,0.954797,-9.73,-8.7752,(0-14:1272-1258) -19,Test_Primer,15,Transcript_2,1285,1.00572,-9.73,-8.72428,(0-14:1271-1257) -20,Test_Primer,15,Transcript_2,1285,1.05547,-9.73,-8.67453,(0-14:1270-1256) -21,Test_Primer,15,Transcript_2,1285,1.1081,-9.73,-8.6219,(0-14:1269-1255) -22,Test_Primer,15,Transcript_2,1285,1.16012,-9.73,-8.56988,(0-14:1268-1254) -23,Test_Primer,15,Transcript_2,1285,1.21706,-9.73,-8.51294,(0-14:1267-1253) -24,Test_Primer,15,Transcript_2,1285,1.26811,-9.73,-8.46189,(0-14:1266-1252) -25,Test_Primer,15,Transcript_2,1285,1.3178,-9.73,-8.4122,(0-14:1265-1251) -26,Test_Primer,15,Transcript_2,1285,1.38695,-9.73,-8.34305,(0-14:1264-1250) -27,Test_Primer,15,Transcript_2,1285,1.40247,-9.73,-8.32753,(0-14:1263-1249) -28,Test_Primer,15,Transcript_2,1285,1.38231,-9.73,-8.34769,(0-14:1262-1248) -29,Test_Primer,15,Transcript_2,1285,1.34893,-9.73,-8.38107,(0-14:1261-1247) -30,Test_Primer,15,Transcript_2,1285,1.30604,-9.73,-8.42396,(0-14:1260-1246) -31,Test_Primer,15,Transcript_2,1285,1.25994,-9.73,-8.47006,(0-14:1259-1245) -32,Test_Primer,15,Transcript_2,1285,1.20881,-9.76,-8.55119,(0-14:1258-1244) -33,Test_Primer,15,Transcript_2,1285,1.63873,-9.91,-8.27127,(0-14:674-660) diff --git a/tests/in_output_examples/Yeast testfiles/dbRNA_test.fa b/tests/in_output_examples/Yeast testfiles/dbRNA_test.fa deleted file mode 100644 index e108075815031c42cf01142645040707d3125a8b..0000000000000000000000000000000000000000 --- a/tests/in_output_examples/Yeast testfiles/dbRNA_test.fa +++ /dev/null @@ -1,76 +0,0 @@ ->Transcript_1 -TTTTTTTTTTTTTTTTTTTATGGATGATTATCACGTAAATACTGCCTTCTCAATGGGCAGAGGTAACCAGCAGGATGAT -GGCAATAGTGAAAGCAACAGCATGCATACACAACCAAGCACTATGGCGCCCGCTACGCTG -AGAATGATGGGAAAAAGTCCACAGCAGCAGCAGCAGCAGAACACACCGCTAATGCCCCCG -GCGGATATCAAATACGCCAATAATGGTAACTCACATCAAGCAGAGCAAAAGGAGAGACAA -GTAGAACTTGAAGGTAAATCGAGAGAGAATGCACCAAAGCCAAATACTACCAGCCAGAGT -CGAGTTTCGTCTTCTCAGGGCATGCCTAAGCAGTTTCATCGAAAATCGTTAGGAGATTGG -GAGTTTGTTGAAACAGTTGGTGCAGGTTCTATGGGTAAAGTGAAGCTGGCAAAACATCGT -TACACTAATGAGGTTTGTGCAGTAAAAATTGTAAACCGTGCTACAAAGGCTTTCCTACAT -AAAGAACAAATGCTGCCACCACCCAAAAATGAACAAGATGTTTTGGAGAGACAGAAGAAA -TTAGAGAAGGAAATATCTAGGGACAAAAGAACTATTCGAGAAGCGTCCTTGGGACAAATC -TTATATCATCCACACATATGTAGACTTTTTGAGATGTGCACGTTGTCAAATCATTTCTAT -ATGTTGTTTGAATATGTTTCAGGTGGTCAGCTGTTAGACTATATCATCCAACATGGGTCA -ATACGAGAACACCAAGCGAGAAAGTTTGCTAGGGGTATCGCGAGCGCCTTAATATATTTG -CATGCTAACAACATCGTCCATAGAGATTTGAAGATAGAAAATATAATGATTTCAGATTCC -AGTGAAATCAAGATAATTGATTTTGGACTTTCAAATATTTATGATTCTAGGAAGCAGCTT -CATACATTCTGTGGCTCTCTGTATTTTGCCGCTCCCGAGCTGTTAAAAGCGAATCCTTAT -ACAGGACCTGAAGTAGATGTCTGGTCATTTGGTGTAGTTTTATTTGTTTTGGTATGCGGT -AAAGTGCCATTTGACGACGAAAATTCGAGCGTTTTACATGAAAAGATCAAGCAAGGTAAG -GTTGAATATCCCCAACATTTATCTATCGAAGTAATATCACTGTTATCCAAAATGTTGGTA -GTAGATCCGAAAAGAAGAGCCACACTTAAACAGGTTGTGGAGCACCACTGGATGGTAAGA -GGGTTCAATGGTCCCCCTCCTTCTTACTTACCGAAAAGAGTTCCCCTAACTATCGAAATG -CTTGATATAAATGTCTTAAAAGAAATGTACCGTTTAGAATTTATTGACGATGTAGAGGAA -ACAAGAAGTGTTTTGGTCAGTATAATCACAGATCCTACTTACGTTCTTCTCTCTAGACAA -TACTGGACTTTAGCGGCCAAAATGAACGCAGAATCCAGTGATAACGGAAACGCGCCAAAC -ATAACAGAGAGTTTTGAAGACCCAACTCGGGCATATCATCCAATGATTTCCATATATTAC -TTGACTTCTGAGATGCTTGATAGGAAACATGCGAAAATTCGGAATCAACAACAGCGACAG -AGCCACGAAAATATAGAAAAGCTTTCTGAAATACCGGAAAGTGTGAAGCAAAGGGACGTA -GAGGTCAATACAACCGCTATGAAATCAGAGCCAGAAGCCACGTTGGCGACAAAAGATACC -TCTGTGCCATTCACTCCAAAGAATAGCGATGGCACAGAGCCCCCCTTACATGTCTTAATT -CCACCGAGGTTAGCAATGCCAGAACAAGCGCATACGTCACCAACGAGTAGAAAAAGTTCT -GATAATCAACGCCGTGAAATGGAATATGCTCTCTCTCCAACTCCTCAGGGAAATGACTAT -CAACAATTTAGGGTACCTTCAACTACTGGCGATCCCTCAGAAAAGGCGAAGTTTGGGAAT -ATATTTAGAAAATTATCACAGCGCCGTAAAAAGACCATTGAACAGACATCTGTTAATAGT -AATAATAGTATCAATAAACCTGTGCAAAAGACGCATTCTCGCGCTGTTTCAGACTTTGTC -CCTGGTTTTGCTAAACCGAGTTATGATTCAAATTATACCATGAATGAGCCTGTCAAGACA -AACGATAGCAGAGGTGGCAATAAAGGTGACTTTCCAGCATTGCCTGCGGATGCAGAAAAT -ATGGTAGAGAAGCAAAGGGAGAAGCAAATTGAAGAAGATATAATGAAATTGCATGATATT -AATAAACAGAATAATGAAGTTGCAAAAGGAAGCGGGCGGGAAGCTTACGCTGCACAGAAG -TTTGAAGGAAGCGACGACGACGAGAATCATCCCTTACCACCTCTCAATGTTGCAAAAGGT -CGAAAACTACATCCAAGCGCAAGAGCTAAATCAGTTGGTCATGCTCGTCGTGAATCACTC -AAATATATGAGACCCCCAATGCCTTCATCTGCCTATCCTCAGCAAGAGCTTATAGATACT -GGGTTCTTAGAATCAAGTGACGATAACAAATCCGATAGTTTGGGAAATGTTACTTCACAG -ACGAATGATAGCGTCAGCGTGCATTCTGTGAACGCACACATAAACTCGCCATCTGTGGAG -AAGGAATTAACAGATGAAGAGATATTGCAGGAAGCTTCTAGAGCTCCAGCCGGTTCTATG -CCATCCATCGATTTCCCCCGTTCTTTATTTTTGAAGGGTTTCTTTTCTGTTCAGACAACT -TCATCGAAGCCTTTGCCAATTGTTAGATACAAGATTATGTTTGTTCTGAGGAAAATGAAT -ATAGAGTTCAAGGAGGTTAAGGGTGGTTTTGTTTGTATGCAAAGGTTCTCTTCCAATAAT -GTGGCAGCGAAGAGAGAAGGGACTCCAAGATCGATCATGCCACTTTCGCACCACGAATCC -ATTAGACGTCAAGGCTCTAATAAATACTCACCTTCTTCTCCTTTGACAACTAATTCCATT -CACCAGAGAAAAACATTTTTTTTTTTTTTTTTTTTCTATTACCGAAACCTATGGAGATGATAAGCATTCGGGAACATCT -TTGGAGAACATCCACCAACAAGGTGACGGTAGCGAAGGCATGACTACAACAGAAAAAGAG -CCCATCAAATTCGAAATTCATATCGTCAAGGTTCGTATTGTTGGTTTAGCCGGTGTGCAT -TTTAAGAAAATTTCTGGGAACACTTGGTTGTATAAAGAGCTGGCTTCTAGTATATTAAAA -GAACTAAAGTTGTAA ->Transcript_2 -TTTTTTTTTTTTTTTTTTTTTATGTATGTTGATCCGATGAACAACAATGAAATCAGGAAATTAAGCATTACTGCCAAGACA -GAAACAACTCCAGATAACGTTGGACAAGACATTCCTGTAAACGCACATTCGGTGCATGAG -GAATGTTCTTCCAACACACCCGTGGAGATAAATGGAAGAAACAGCGGAAAGTTGAAAGAA -GAAGCGTCTGCAGGTATTTGTTTGGTTAAAAAACCAATGCTACAATATAGAGATACCTCA -GGAAAGTATTCCCTAAGTGACTTTCAGATTTTAAGAACTTTGGGAACTGGCTCATTTGGG -AGAGTTCACCTAATTCGTTCCAATCACAATGGGAGGTTTTACGCTTTGAAGACATTGAAA -AAGCACACTATAGTGAAGCTGAAGCAGGTTGAACACACCAATGACGAACGCCGAATGCTT -TCAATTGTTTCACATCCATTCATCATTCGAATGTGGGGAACGTTCCAAGATTCTCAGCAA -GTTTTCATGGTAATGGACTACATTGAAGGTGGTGAATTATTTTCTTTACTACGTAAATCT -CAAAGATTTCCCAACCCAGTAGCCAAATTTTATGCCGCAGAGGTATGCTTAGCGTTGGAA -TATTTGCACAGTAAGGATATAATATATATTTTTTTTTTTTTTTTTTTTTTTTTTGAGACTTGAAACCAGAAAATATCCTTCTAGAT -AAAAACGGCCATATCAAGATAACCGACTTTGGCTTCGCAAAATACGTTCCCGATGTCACA -TACACATTATGTGGCACACCAGATTACATAGCGCCGGAAGTGGTCAGTACAAAACCGTAT -AATAAATCAGTGGATTGGTGGAGTTTTGGTGTGCTAATCTATGAAATGCTTGCCGGATAC -ACTCCATTTTACAATTCGAACACCATGAAAACTTACGAAAATATACTGAACGCCGAATTG -AAGTTCCCACCATTTTTCCATCCAGACGCGCAGGACTTATTGAAGAAGCTAATTACCAGA -GACTTAAGTGAAAGGTTGGGTAACTTACAAAATGGAAGTGAAGATGTCAAGAACCATCCG -TGGTTTAACGAAGTGATATGGGAGAAATTGTTAGCAAGATACATAGAAACGCCGTACGAA -CCACCAATCCAACAGGGCCAAGGTGACACTTCTCAATTTGACAGATACCCTGAAGAGGAA -TTCAACTATGGAATTCAAGGGGAGGATCCATATATGGATTTAATGAAAGAATTTTAATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT \ No newline at end of file diff --git a/tests/in_output_examples/Yeast testfiles/queryRNA_test.fa b/tests/in_output_examples/Yeast testfiles/queryRNA_test.fa deleted file mode 100644 index b6ea8a793ad75bd74504e08501892aab398dea92..0000000000000000000000000000000000000000 --- a/tests/in_output_examples/Yeast testfiles/queryRNA_test.fa +++ /dev/null @@ -1,2 +0,0 @@ ->Test_Primer -AAAAAAAAAAAAAAA \ No newline at end of file diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000000000000000000000000000000000000..94676a8ba6d32fe5a501c921fc0b80f45730377c --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,77 @@ +"""Test functions for cli.py.""" +import unittest +from unittest.mock import patch +from primingsitepredictor import cli + + +class TestCli(unittest.TestCase): + """Test cli.py methods.""" + + def test_parse_args(self): + """Test parsing --energy-cutoff as a float.""" + # Test parsing a valid float + float_num = 3.14 + float_str = str(float_num) + with patch("sys.argv", [ + "primingsitepredictor", "--energy-cutoff", float_str + ]): + args = cli.parse_args() + self.assertEqual(args.energy_cutoff, float(float_str)) + + # Test parsing a float number with leading and trailing whitespace + float_num = 3.14 + float_str = " " + str(float_num) + " " + with patch("sys.argv", [ + "primingsitepredictor", "--energy-cutoff", float_str + ]): + args = cli.parse_args() + self.assertEqual(args.energy_cutoff, float(float_str)) + + # Test parsing a float number with a decimal point \ + # and no digits after it + float_num = 3. + float_str = str(float_num) + with patch("sys.argv", [ + "primingsitepredictor", "--energy-cutoff", float_str + ]): + args = cli.parse_args() + self.assertEqual(args.energy_cutoff, float(float_str)) + + # Test parsing a float number with a decimal point \ + # and multiple digits after it + float_num = 3.14159 + float_str = str(float_num) + with patch("sys.argv", [ + "primingsitepredictor", "--energy-cutoff", float_str + ]): + args = cli.parse_args() + self.assertEqual(args.energy_cutoff, float(float_str)) + + # Test parsing a negative float number + float_num = -3.14 + float_str = str(float_num) + with patch("sys.argv", [ + "primingsitepredictor", "--energy-cutoff", float_str + ]): + args = cli.parse_args() + self.assertEqual(args.energy_cutoff, float(float_str)) + + def test_invalid_parse_args(self): + """Test parsing --energy-cutoff as an invalid float.""" + # Test parsing a float number with a letter in it + invalid_float_num = "3.14a" + invalid_float_str = str(invalid_float_num) + with patch("sys.argv", [ + "primingsitepredictor", "--energy-cutoff", invalid_float_str + ]): + with self.assertRaises(SystemExit): + cli.parse_args() + + # Test parsing a float number with multiple decimal points + invalid_float_num = "3.14.159" + invalid_float_str = str(invalid_float_num) + with patch("sys.argv", [ + "primingsitepredictor", "--energy-cutoff", invalid_float_str + ]): + with self.assertRaises(SystemExit): + cli.parse_args() diff --git a/tests/test_createprimer.py b/tests/test_createprimer.py new file mode 100644 index 0000000000000000000000000000000000000000..94e15043299e883f9858ee7e3f30c78883eddc91 --- /dev/null +++ b/tests/test_createprimer.py @@ -0,0 +1,55 @@ +"""Tests for createprimer.py.""" +import unittest +from unittest.mock import patch, mock_open +import pytest +from primingsitepredictor.prime_site_predictor import CreatePrimer + + +class TestCreatePrimer(unittest.TestCase): + """Test CreatePrimer function.""" + + def test_init(self): + """Test the __init__() default values.""" + primer = CreatePrimer() + self.assertEqual(primer.name, 'primer') + self.assertEqual(primer.primer_length, 15) + self.assertEqual(primer.primer_sequence, 'T'*15) + self.assertEqual(primer.lines, ['<primer', 'TTTTTTTTTTTTTTT']) + with pytest.raises(TypeError): + CreatePrimer(type(int), type(str)) + + def test_init_custom(self): + """Test the __init__() custom values.""" + primer = CreatePrimer('my_primer', 20) + self.assertEqual(primer.name, 'my_primer') + self.assertEqual(primer.primer_length, 20) + self.assertEqual(primer.primer_sequence, 'T'*20) + self.assertEqual(primer.lines, ['<my_primer', 'TTTTTTTTTTTTTTTTTTTT']) + + def test_create_fasta(self): + """Test the test_create_fasta default values.""" + with patch('builtins.open', new_callable=mock_open) as mock_file: + primer = CreatePrimer() + primer.create_fasta() + + # assert if opened file on write mode 'w' + mock_file.assert_called_once_with( + 'primer.fasta', 'w', encoding='utf-8' + ) + # assert if the specific content was written in file + expected_content = '<primer\nTTTTTTTTTTTTTTT' + mock_file().write.assert_called_once_with(expected_content) + + def test_create_fasta_custom(self): + """Test the test_create_fasta custom values.""" + with patch('builtins.open', new_callable=mock_open) as mock_file: + primer = CreatePrimer('my_primer', 20) + primer.create_fasta() + + # assert if opened file on write mode 'w' + mock_file.assert_called_once_with( + 'my_primer.fasta', 'w', encoding='utf-8' + ) + # assert if the specific content was written in file + expected_content = '<my_primer\nTTTTTTTTTTTTTTTTTTTT' + mock_file().write.assert_called_once_with(expected_content) diff --git a/primingsitepredictor/RIBlast output example.txt b/tests/test_files/RIBlast_output_example.txt similarity index 100% rename from primingsitepredictor/RIBlast output example.txt rename to tests/test_files/RIBlast_output_example.txt diff --git a/primingsitepredictor/output_transcripts_df.GTF b/tests/test_files/output_transcripts_df.gtf similarity index 100% rename from primingsitepredictor/output_transcripts_df.GTF rename to tests/test_files/output_transcripts_df.gtf diff --git a/primingsitepredictor/test/primer1.fasta b/tests/test_files/primer1.fasta similarity index 100% rename from primingsitepredictor/test/primer1.fasta rename to tests/test_files/primer1.fasta diff --git a/primingsitepredictor/test/test_fasta.fasta b/tests/test_files/test_fasta.fasta similarity index 100% rename from primingsitepredictor/test/test_fasta.fasta rename to tests/test_files/test_fasta.fasta diff --git a/primingsitepredictor/tests/in_output_examples/Yeast testfiles/dbRNA_test.fa b/tests/test_files/yeast_test_files/dbRNA_test.fa similarity index 100% rename from primingsitepredictor/tests/in_output_examples/Yeast testfiles/dbRNA_test.fa rename to tests/test_files/yeast_test_files/dbRNA_test.fa diff --git a/primingsitepredictor/tests/in_output_examples/Yeast testfiles/queryRNA_test.fa b/tests/test_files/yeast_test_files/queryRNA_test.fa similarity index 100% rename from primingsitepredictor/tests/in_output_examples/Yeast testfiles/queryRNA_test.fa rename to tests/test_files/yeast_test_files/queryRNA_test.fa diff --git a/primingsitepredictor/test/test_main.py b/tests/test_main.py similarity index 90% rename from primingsitepredictor/test/test_main.py rename to tests/test_main.py index 1ac3d3c6f6f77b3a7945be939347c7536357d633..d57812ddb70b516bd672b74e486ad1cb176d3f92 100644 --- a/primingsitepredictor/test/test_main.py +++ b/tests/test_main.py @@ -5,7 +5,8 @@ Created on Tue Dec 20 14:06:20 2022 """ # Imports -import os, sys +import os +import sys currentdir = os.path.dirname(os.path.realpath(__file__)) parentdir = os.path.dirname(currentdir) sys.path.append(parentdir) @@ -29,8 +30,8 @@ class TestMain(unittest.TestCase): except ImportError: self.fail("Failed to import PostProcessRIBlast") - def test_generate_RIBlast_input(self): - """Test funciton for the method generate_RIBlast_input()""" + def test_generate_riblast_input(self): + """Test funciton for the method generate_riblast_input()""" # Call the CreatePrimer() method and the create_fasta() method primer = cp.CreatePrimer() @@ -40,8 +41,8 @@ class TestMain(unittest.TestCase): primer_filename = primer.name+".fasta" transcript_filename = "transcripts.fasta" - # Call the generate_RIBlast_input() method - result = mn.generate_RIBlast_input() + # Call the generate_riblast_input() method + result = mn.generate_riblast_input() assert result == [primer_filename, transcript_filename] @@ -82,7 +83,7 @@ class TestMain(unittest.TestCase): transcripts_filename = "transcripts.fasta" # Get the results for the called methods - result1 = mn.generate_RIBlast_input() + result1 = mn.generate_riblast_input() result2 = mn.create_gtf() # Open the expected output diff --git a/tests/test_postprocessing.py b/tests/test_postprocessing.py new file mode 100644 index 0000000000000000000000000000000000000000..0132906fe1f4cf2e7efd59376be904e3f68129b7 --- /dev/null +++ b/tests/test_postprocessing.py @@ -0,0 +1,213 @@ + +import unittest +from unittest import mock +import math +from primingsitepredictor.prime_site_predictor import PrimingSitePredictor + + +class TestPrimingSitePredictor(unittest.TestCase): + """Test PrimingSitePredictor.""" + + def setUp(self): + """Create an instance of PrimingSitePredictor.""" + # You need to provide the required parameters to the constructor + self.post_processor = PrimingSitePredictor( + fasta_file="test.fasta", + primer_sequence="T" * 15, + energy_cutoff=0.5, + riblast_output="test_files/RIBlast_output_example.txt", + output_filename="test_output.gtf" + ) + + def test_generate_gtf(self): + """Test the generate_gtf() method.""" + # Create a mock DataFrame to be returned by create_pandas_df() + mock_df = mock.MagicMock() + mock_df.index = [0] + mock_df[3][0] = 'Transcript_1' + mock_df[13][0] = '(0-14:2988-2974)' + mock_df[12][0] = '+' + mock_df["Normalised_interaction_energy"][0] = 0.75 + + with mock.patch.object( + self.post_processor, "create_pandas_df", return_value=mock_df + ): + expected_output = ( + 'Transcript_1\tRIBlast\tPriming_site\t(0-14:2988-2974)\t+\t.\t+\t.\tInteraction_Energy\t0.75\n' + ) + print(self.post_processor.generate_gtf()) + print(expected_output) + # self.assertEqual(self.post_processor.generate_gtf(), expected_output) + + def test_calculate_energy(self): + """Test the calculate_energy() method.""" + test_instance = self.post_processor + decimal_place = 20 + + # Test for a positive value + self.assertAlmostEqual( + test_instance.calculate_energy(9.76), + math.exp(-9.76 * 6.9477 * 10 ** -21 / (1.380649e-23 * 298)), + decimal_place + ) + + # Test for a negative value + self.assertAlmostEqual( + test_instance.calculate_energy(-5.0), + math.exp(5.0 * 6.9477 * 10 ** -21 / (1.380649e-23 * 298)), + decimal_place + ) + + # Test for zero + self.assertAlmostEqual( + test_instance.calculate_energy(0), + math.exp(0 * 6.9477 * 10 ** -21 / (1.380649e-23 * 298)), + decimal_place + ) + + def test_create_list_from_output(self): + """Test the create_list_from_output() method.""" + # Mocking the file readlines method + mock_readlines = mock.MagicMock() + mock_readlines.return_value = [ + "header1\n", + "header2\n", + "header3\n", + "0,Test_Primer,15,Transcript_1,3233,1.49191,-9.76,-8.26809,(0-14:2988-2974)\n", + "1,Test_Primer,15,Transcript_1,3233,1.02308,-9.76,-8.73692,(0-14:18-4)\n", + ] + + with mock.patch("builtins.open", mock.mock_open(read_data="")) as m, \ + mock.patch.object( + m.return_value, "readlines", mock_readlines + ): + expected_output = [ + ['0', 'Test_Primer', '15', 'Transcript_1', '3233', '1.49191', '-9.76', '-8.26809', '(0-14:2988-2974)'], + ['1', 'Test_Primer', '15', 'Transcript_1', '3233', '1.02308', '-9.76', '-8.73692', '(0-14:18-4)'] + ] + self.assertEqual(self.post_processor.create_list_from_output(), expected_output) + + +if __name__ == "__main__": + unittest.main() + +# class TestPrimingSitePredictor(unittest.TestCase): +# """Test PrimingSitePredictor.""" + +# def setUp(self): +# """Setup function to create an instance of PrimingSitePredictor.""" +# self.post_processor = PrimingSitePredictor() + +# def test_init(self): +# """Test the __init__() method.""" +# # Test if generate_gtf method is being called +# with unittest.mock.patch.object( +# PrimingSitePredictor, "generate_gtf" +# ) as mock_generate_gtf: +# PrimingSitePredictor() +# mock_generate_gtf.assert_called_once() + +# # Test if generate_gtf returns the expected output +# expected_output = ( +# 'Transcript_1\tRIBlast\tPriming_site\t2974[3257 chars]3"\n' +# ) +# self.assertEqual(self.post_processor.generate_gtf(), expected_output) + +# def test_calculate_energy(self): +# """Test the calculate_energy() method.""" + +# def calculate_energy(value): +# energy_constant = 1.380649*10**(-23)*298 +# kcalmol_joul = 6.9477*10**-21 +# return (math.exp(-float(value)*kcalmol_joul/energy_constant)) + +# # set a decimal place +# decimalPlace = 20 + +# # Test for a positive value +# self.testinstance = pp.PostProcessRIBlast.calculate_energy(self, 5.0) +# expected_output = calculate_energy(5.0) +# self.assertAlmostEqual(self.testinstance, expected_output, decimalPlace) + + +# # Test for a negative value +# self.testinstance = pp.PostProcessRIBlast.calculate_energy(self, -5.0) +# expected_output = calculate_energy(-5.0) +# self.assertAlmostEqual(self.testinstance, expected_output, decimalPlace) + +# # Test for zero +# self.testinstance = pp.PostProcessRIBlast.calculate_energy(self, 0) +# expected_output = calculate_energy(0) +# self.assertAlmostEqual(self.testinstance, expected_output, decimalPlace) + +# def test_create_list_from_output(self): +# """Test the create_list_from_output() method.""" +# # create an instance test of the class PostProcessRIBlast() +# test = pp.PostProcessRIBlast() +# test.file = "RIBlast output example.txt" + +# with open('RIBlast output example.txt', 'r', encoding="utf-8") as file: +# data_list = file.readlines() + +# # Remove the header +# data_list = data_list[3:] + +# # Convert each row of the list into a list of values +# expected_output = [] +# for row in data_list: +# # Split the row by the comma character +# values = row.strip().split(',') +# # Append the list of values to the final list +# expected_output.append(values) +# return expected_output +# self.assertEqual(test.create_list_from_output(), expected_output) + +# def test_create_pandas_df(self): +# """Test the create_pandas_df() method with mock data.""" +# # create a test instance +# test_instance = pp.PostProcessRIBlast() + +# # create some mock data for the input list +# test_instance.interaction_list = [ +# ['Id', 'Query name', 'Query Length', 'Target name', 'Target Length', 'Accessibility Energy', 'Hybridization Energy', 'Interaction Energy', 'BasePair'], +# [0, 'Test_Primer', 15, 'Transcript_1', 3233, 1.49191, -9.76, -8.26809, '(0-14:2988-2974)'], +# [1, 'Test_Primer', 15, 'Transcript_1', 3233, 1.02308, -9.76, -8.73692, '(0-14:18-4)'], +# [2, 'Test_Primer', 15, 'Transcript_1', 3233, 0.947439, -9.73, -8.78256, '(0-14:17-3)'], +# [3, 'Test_Primer', 15, 'Transcript_1', 3233, 0.793049, -9.73, -8.93695, '(0-14:16-2)'], +# [4, 'Test_Primer', 15, 'Transcript_1', 3233, 0.483869, -9.73, -9.24613, '(0-14:15-1)'], +# [5, 'Test_Primer', 15, 'Transcript_1', 3233, 0.441093, -9.17, -8.72891, '(0-14:14-0)']] + +# # create the DataFrame using the mock data +# df = test_instance.create_pandas_df() + +# #self.assertEqual(len(df),7) + +# # check that the DataFrame has the expected column names +# #self.assertEqual(list(df.columns), ['Id','Query name', 'Query Length', 'Target name', 'Target Length', 'Accessibility Energy', 'Hybridization Energy', 'Interaction Energy', 'BasePair']) + +# # check that the values in the 'Id' column are correct +# self.assertEqual(list(df['Id']), ['Id',0,1,2,3,4,5]) + +# # check that the values in the 'Query name' column are correct +# self.assertEqual(list(df['Query name']), ['Query name','Test_Primer','Test_Primer','Test_Primer','Test_Primer','Test_Primer','Test_Primer']) + +# # check that the values in the 'Query Length' column are correct +# self.assertEqual(list(df['Query Length']), ['Query Length',15, 15, 15, 15, 15, 15]) + +# # check that the values in the 'Target name' column are correct +# self.assertEqual(list(df['Target name']), ['Target name','Transcript_1','Transcript_1','Transcript_1','Transcript_1','Transcript_1','Transcript_1']) + +# # check that the values in the 'Target Length' column are correct +# self.assertEqual(list(df['Target Length']), ['Target Length', 3233, 3233, 3233, 3233, 3233, 3233]) + +# # check that the values in the 'Accessibility Energy' column are correct +# self.assertEqual(list(df['Accessibility Energy']), ['Accessibility Energy',1.49191, 1.02308, 0.947439, 0.793049, 0.483869, 0.441093]) + +# # check that the values in the 'Hybridization Energy' column are correct +# self.assertEqual(list(df['Hybridization Energy']), ['Hybridization Energy',-9.76, -9.76, -9.73, -9.73, -9.73, -9.17]) + +# # check that the values in the 'Interaction Energy' column are correct +# self.assertEqual(list(df['Interaction Energy']), ['Interaction Energy',-8.26809, -8.73692, -8.78256, -8.93695, -9.24613, -8.72891]) + +# # check that the values in the 'BasePair' column are correct +# self.assertEqual(list(df['BasePair']), ['BasePair','(0-14:2988-2974)', '(0-14:18-4)', '(0-14:17-3)', '(0-14:16-2)', '(0-14:15-1)', '(0-14:14-0)'])