def tearDown(self): files = glob.glob( os.path.join(fwd, test_data_dir, 'RF00001_short.blastout') + '.r-*') remove_files_with_try([ self.csv, self.html, self.json, self.fasta, self.fasta_structures ] + files)
def test_exit_on_unqual_blast_meta(self): op = os.path.join(test_data_dir, 'two_fasta.fa') with open(op, 'w') as f: f.write(">a\nCAGCATGCTAGCTGATGCTA\n>b\nAGCTGATCGTAGCTGCTAGTCGTA\n") self.args.blast_query = op self.args.mode = 'meta' with self.assertRaises(SystemExit): lunch_with_args(self.args) remove_files_with_try([op])
def test_exit_on_missing_rfam(self): op = os.path.join(test_data_dir, 'config_rfam_here.txt') with open(op, 'w') as f: f.write("[TOOL_PATHS]\n[DATA]\nrfam_dir = test_func/test_data\n") self.args.config_file = op self.args.download_rfam = False with self.assertRaises(SystemExit): lunch_with_args(lunch_with_args(self.args)) remove_files_with_try([op])
def setUp(self): f = open(ref_json_file, 'r') mydata = json.load(f) f.close() bb = convert_classes.blastsearchrecomputefromdict(mydata) self.data = bb ff, csv = tempfile.mkstemp(prefix='rba_', suffix='_t1') os.close(ff) self.csv = csv ff, html = tempfile.mkstemp(prefix='rba_', suffix='_t2') os.close(ff) self.html = blast_query + 'test_html.html' ff, pandas_dump = tempfile.mkstemp(prefix='rba_', suffix='_t3') os.close(ff) self.pandas_dump = pandas_dump ff, json_file = tempfile.mkstemp(prefix='rba_', suffix='_t4') os.close(ff) self.json = json_file ff, fasta = tempfile.mkstemp(prefix='rba_', suffix='_t5') os.close(ff) self.fasta = fasta ff, allHits_fasta = tempfile.mkstemp(prefix='rba_', suffix='_t6') with os.fdopen(ff, 'w') as f: SeqIO.write([i.extension for i in self.data.hits], f, 'fasta') self.fasta_structures = allHits_fasta self.args = Pseudoargs( blast_query, blast_in, blast_db, b_type='plain', prediction_method=['rnafold'], blast_regexp=r'(?<=\|)[A-Z0-9]*\.?\d*$', enable_overwrite=True, html=self.html, ) self.func_args = { 'query': self.data.query, 'seqs2predict_fasta': allHits_fasta, 'pred_method_params': {}, 'all_hits_list': [i.extension for i in self.data.hits], 'seqs2predict_list': [i.extension for i in self.data.hits], 'use_cm_file': 'abc', } remove_files_with_try([blast_in + '.tmp_rboAnalyzer'])
def test_wrong_blast_meta(self): op = os.path.join(test_data_dir, 'wrong_blast.txt') with open(self.args.blast_in, 'r') as f, open(op, 'w') as o: blast_raw = f.read() blast_altered = blast_raw.replace( 'CGGAGGGGGAACA-CCCGGTCCCATTCCGAACCC', 'CGGAGGGGGAACA-CCCGGTKYLATTCCGAACCC') if blast_raw == blast_altered: assert False o.write(blast_altered) self.args.blast_in = op self.args.mode = 'meta' with self.assertRaises(SystemExit): lunch_with_args(self.args) remove_files_with_try([op] + glob.glob(op + '.r-*'))
def run_with_fasta(fasta_example, func, expect): fd, fdpath = tempfile.mkstemp() with os.fdopen(fd, 'w') as f: f.write(fasta_example) a = base_script + [ '--blast_in', blast_in, '--blast_query', fdpath, '--blast_db', blast_db, '--mode', 'simple', '--blast_regexp', r'"(?<=\|)[A-Z0-9]*\.?\d*$"', '--b_type', 'plain', '--prediction_method', 'rnafold', '--enable_overwrite', '--html', test_html_file ] bb = subprocess.call(' '.join(a), cwd=root, shell=True) func(bb, expect) remove_files_with_try([ fdpath, test_html_file, ], '') print(test_html_file)
def test_meta_with_one_seq_fail(self): op = os.path.join(test_data_dir, 'wrong_blast.txt') with open(self.args.blast_in, 'r') as f, open(op, 'w') as o: blast_raw = f.read() blast_altered = re.sub( 'AGCGGAGGGGAAACCGCCCGGTCCCATTCCGAACCCGGAAGC', 'AGCGGAGGGGAAACCGCAGTCGATGTTTCCGAACCCACGTCG', blast_raw, 1) if blast_raw == blast_altered: assert False o.write(blast_altered) self.args.blast_in = op self.args.mode = 'meta' self.args.threads = 4 out = lunch_with_args(self.args) self.assertEqual(len(out[0].hits_failed), 0) remove_files_with_try([op] + glob.glob(op + '.r-*'))
def test_locarna_partial_fail(self): bb = self.data hit = bb.hits.pop(1) hit.extension = None bb.hits_failed.append(hit) fda, all_hits_fasta = tempfile.mkstemp(prefix='rba_', suffix='_22') os.close(fda) bb.write_results_fasta(all_hits_fasta) ih_model, analyzed_hits = find_and_extract_cm_model(bb.args, bb) # this part predicts homology - it is not truly part of repredict homology_prediction, homol_seqs, cm_file_rfam_user = infer_homology( analyzed_hits=bb, args=bb.args, cm_model_file=ih_model, multi_query=False, iteration=0) self.assertIsNone(cm_file_rfam_user) self.assertEqual(len(analyzed_hits.hits), len(homology_prediction)) remove_files_with_try([ih_model, all_hits_fasta])
def tearDown(self): remove_files_with_try([ self.csv, self.html, self.json, self.fasta, self.fasta_structures ], '')
def tearDown(self): files = glob.glob(blast_in + '.r-*') remove_files_with_try([ self.csv, self.html, self.json, self.fasta, self.fasta_structures ] + files, '')