def test_to_file(self): params = ProcessedSortmernaParams(1) fd, fp = mkstemp() close(fd) with open(fp, 'w') as f: params.to_file(f) with open(fp, 'U') as f: obs = f.read() self.assertEqual(obs, EXP_SMR_PARAMS_FILE)
def test_get_process_target_gene_cmd(self): preprocessed_data = PreprocessedData(1) params = ProcessedSortmernaParams(1) obs_cmd, obs_output_dir = _get_process_target_gene_cmd( preprocessed_data, params) _, ref_dir = get_mountpoint('reference')[0] _, preprocessed_dir = get_mountpoint('preprocessed_data')[0] exp_cmd = ("pick_closed_reference_otus.py -i {}1_seqs.fna -r " "{}GreenGenes_13_8_97_otus.fasta -o {} -p placeholder -t " "{}GreenGenes_13_8_97_otu_taxonomy.txt".format( preprocessed_dir, ref_dir, obs_output_dir, ref_dir)) obs_tokens = obs_cmd.split()[::-1] exp_tokens = exp_cmd.split()[::-1] self.assertEqual(len(obs_tokens), len(exp_tokens)) while obs_tokens: o_t = obs_tokens.pop() e_t = exp_tokens.pop() if o_t == '-p': # skip parameters file obs_tokens.pop() exp_tokens.pop() else: self.assertEqual(o_t, e_t)
def test_generate_param_str(self): params = ProcessedSortmernaParams(1) obs = generate_param_str(params) exp = ("<b>Reference:</b> Greengenes 13_8<br/>" "<b>similarity:</b> 0.97<br/>" "<b>sortmerna_e_value:</b> 1.0<br/>" "<b>sortmerna_max_pos:</b> 10000<br/>" "<b>threads:</b> 1<br/>" "<b>sortmerna_coverage:</b> 0.97") self.assertEqual(obs, exp)
def test_insert_processed_data_target_gene(self): fd, fna_fp = mkstemp(suffix='_seqs.fna') close(fd) fd, qual_fp = mkstemp(suffix='_seqs.qual') close(fd) filepaths = [ (fna_fp, convert_to_id('preprocessed_fasta', 'filepath_type')), (qual_fp, convert_to_id('preprocessed_fastq', 'filepath_type')) ] preprocessed_data = PreprocessedData.create( Study(1), "preprocessed_sequence_illumina_params", 1, filepaths, data_type="18S") params = ProcessedSortmernaParams(1) pick_dir = mkdtemp() path_builder = partial(join, pick_dir) db_path_builder = partial(join, get_mountpoint('processed_data')[0][1]) # Create a placeholder for the otu table with open(path_builder('otu_table.biom'), 'w') as f: f.write('\n') # Create a placeholder for the directory mkdir(path_builder('sortmerna_picked_otus')) # Create the log file fd, fp = mkstemp(dir=pick_dir, prefix='log_', suffix='.txt') close(fd) with open(fp, 'w') as f: f.write('\n') _insert_processed_data_target_gene(preprocessed_data, params, pick_dir) new_id = get_count('qiita.processed_data') # Check that the files have been copied db_files = [ db_path_builder("%s_otu_table.biom" % new_id), db_path_builder("%s_sortmerna_picked_otus" % new_id), db_path_builder("%s_%s" % (new_id, basename(fp))) ] for fp in db_files: self.assertTrue(exists(fp)) # Check that a new preprocessed data has been created self.assertTrue( self.conn_handler.execute_fetchone( "SELECT EXISTS(SELECT * FROM qiita.processed_data WHERE " "processed_data_id=%s)", (new_id, ))[0])
def render(self, study_id, preprocessed_data): user = self.current_user ppd_id = preprocessed_data.id ebi_status = preprocessed_data.submitted_to_insdc_status() ebi_study_accession = preprocessed_data.ebi_study_accession ebi_submission_accession = preprocessed_data.ebi_submission_accession vamps_status = preprocessed_data.submitted_to_vamps_status() filepaths = preprocessed_data.get_filepaths() is_local_request = self._is_local() show_ebi_btn = user.level == "admin" processing_status = preprocessed_data.processing_status processed_data = preprocessed_data.processed_data # Get all the ENA terms for the investigation type ontology = Ontology(convert_to_id('ENA', 'ontology')) # make "Other" show at the bottom of the drop down menu ena_terms = [] for v in sorted(ontology.terms): if v != 'Other': ena_terms.append('<option value="%s">%s</option>' % (v, v)) ena_terms.append('<option value="Other">Other</option>') # New Type is for users to add a new user-defined investigation type user_defined_terms = ontology.user_defined_terms + ['New Type'] if PrepTemplate.exists(preprocessed_data.prep_template): prep_template_id = preprocessed_data.prep_template prep_template = PrepTemplate(prep_template_id) raw_data_id = prep_template.raw_data inv_type = prep_template.investigation_type or "None Selected" else: prep_template_id = None raw_data_id = None inv_type = "None Selected" process_params = {param.id: (generate_param_str(param), param.name) for param in ProcessedSortmernaParams.iter()} # We just need to provide an ID for the default parameters, # so we can initialize the interface default_params = 1 return self.render_string( "study_description_templates/preprocessed_data_info_tab.html", ppd_id=ppd_id, show_ebi_btn=show_ebi_btn, ebi_status=ebi_status, ebi_study_accession=ebi_study_accession, ebi_submission_accession=ebi_submission_accession, filepaths=filepaths, is_local_request=is_local_request, prep_template_id=prep_template_id, raw_data_id=raw_data_id, inv_type=inv_type, ena_terms=ena_terms, vamps_status=vamps_status, user_defined_terms=user_defined_terms, process_params=process_params, default_params=default_params, study_id=preprocessed_data.study, processing_status=processing_status, processed_data=processed_data)
def test_to_str(self): params = ProcessedSortmernaParams(1) obs = params.to_str() exp = ("--similarity 0.97 --sortmerna_coverage 0.97 " "--sortmerna_e_value 1.0 --sortmerna_max_pos 10000 --threads 1") self.assertEqual(obs, exp)