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 test_if_missing_db_entry_is_reported(self): aa = Pseudoargs(blast_query=os.path.join(fwd, test_dir, 'RF00005_query.fasta'), blast_in=os.path.join(fwd, test_dir, 'RF00005.blastout'), blast_db=os.path.join(fwd, test_dir, 'blastdb', 'RF00001-art.blastdb'), b_type='plain', prediction_method=['rnafold'], blast_regexp=r'(?<=\|)[A-Z0-9]*\.?\d*$', enable_overwrite=True, mode='locarna') with self.assertRaises(SystemExit): lunch_with_args(aa)
def test_simple_extension(self): self.args.mode = 'simple' out = lunch_with_args(self.args) self.assertEqual(1, 1) # test_output for i in range(len(out)): out[0].to_csv(self.csv) j_obj = json.dumps(blastsearchrecompute2dict(out[0]), indent=2) with open(self.json, 'w') as ff: ff.write(j_obj) with open(self.html, 'wb') as h: h.write(write_html_output(out[0])) out[0].to_pandas_dump(self.pandas_dump) out[0].write_results_fasta(self.fasta) out[0].write_results_structures(self.fasta_structures) t = tab_output_equal( csvfile=self.csv, jsonfile=self.json, pdfile=self.pandas_dump, fastafile=self.fasta, fastastructures=self.fasta_structures, ref_seqs_file=os.path.join(fwd, test_data_dir, 'simple.json') ) self.assertEqual(t, True)
def test_logs_and_correct_seqs_joined(self): with self.assertLogs('rboAnalyzer', level='WARNING') as l: args = self.args args.mode = 'meta' out = lunch_with_args(args) for o in l.output: self.assertIn('Sequence cannot be extended sufficiently', o.split(':')[-1]) recs = out[0].res_2_record_list() with open(source_fasta, 'r') as fh: for seq in SeqIO.parse(fh, format='fasta'): ss = re.sub('[a-z]', '', str(seq.seq)) if 'rc' == seq.description.split()[-1]: strand = -1 else: strand = 1 for rec in recs: if seq.id in rec.id: if strand == 1: rec_s = str(rec.seq) else: rec_s = str(rec.seq.reverse_complement()) self.assertEqual(ss, rec_s)
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 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_continuation2(self): with open(blast_output, 'r') as f, open(self.test_backup_file, 'w') as ff: data = blastsearchrecomputefromdict(json.load(f)) data.args.blast_in = blast_in data.args.json = None data.args.html = test_output_file data.args.sha1 = self.sha1 data.args.prediction_method += ['centroid'] new_structures = {'rnafold': []} for h in data.hits: n = copy(h.extension) n.letter_annotations['ss0'] = n.letter_annotations['rnafold'] del n.letter_annotations['rnafold'] new_structures['rnafold'].append(n) json.dump([blastsearchrecompute2dict(data)], ff, indent=2) out = lunch_with_args(self.args) self.assertEqual(1, 1) # test_output for i in range(len(out)): out[0].to_csv(self.csv) j_obj = json.dumps(blastsearchrecompute2dict(out[0]), indent=2) with open(self.json, 'w') as ff: ff.write(j_obj) out[0].write_results_fasta(self.fasta) out[0].write_results_structures(self.fasta_structures) t = tab_output_equal(csvfile=self.csv, jsonfile=self.json, fastafile=self.fasta, fastastructures=self.fasta_structures, ref_seqs_file=os.path.join( fwd, test_data_dir, 'simple.json')) self.assertEqual(t, True)
def test_meta_complete_fail(self, callMock): self.args.mode = 'locarna' with self.assertRaises(SystemExit): out = lunch_with_args(self.args)