コード例 #1
0
 def _pcr_make_and_write_oligo_file_if_doesnt_exist(self):
     if self.pcr_oligo_file_path is None:
         oligo_file = [
             f'forward\t{self.pcr_fwd_primer}',
             f'reverse\t{self.pcr_rev_primer}'
         ]
         self.pcr_oligo_file_path = os.path.join(self.input_dir, f'{self.name}_oligo_file.oligo')
         write_list_to_destination(self.pcr_oligo_file_path, oligo_file)
コード例 #2
0
 def _make_contig_make_and_write_mothur_batch(self, dot_file_file_path):
     mothur_batch_file = [
         f'set.dir(input={self.input_dir})',
         f'set.dir(output={self.output_dir})',
         f'make.contigs(file={dot_file_file_path})'
     ]
     self._set_mothur_batch_file_path()
     write_list_to_destination(self.mothur_batch_file_path, mothur_batch_file)
コード例 #3
0
    def _dist_seqs_make_and_write_mothur_batch(self):
        mothur_batch_file = [
            f'set.dir(input={self.input_dir})',
            f'set.dir(output={self.output_dir})',
            f'dist.seqs(fasta={self.fasta_path}, countends=T, output=square)'
        ]

        self._set_mothur_batch_file_path()

        write_list_to_destination(self.mothur_batch_file_path, mothur_batch_file)
コード例 #4
0
    def _clearcut_make_and_write_mothur_batch(self):
        mothur_batch_file = [
            f'set.dir(input={self.input_dir})',
            f'set.dir(output={self.output_dir})',
            f'clearcut(phylip={self.dist_file_path}, verbose=t)'
        ]

        self._set_mothur_batch_file_path()

        write_list_to_destination(self.mothur_batch_file_path, mothur_batch_file)
コード例 #5
0
def remove_primer_mismatch_annotations_from_fasta(fasta_path):
    temp_fasta = []
    fasta_to_clean = read_defined_file_to_list(fasta_path)
    for i in range(len(fasta_to_clean) - 1):
        if fasta_to_clean[i]:
            if fasta_to_clean[i][0] == '>' and fasta_to_clean[i + 1]:
                if '|' in fasta_to_clean[i]:
                    temp_fasta.extend([fasta_to_clean[i].split('|')[0], fasta_to_clean[i + 1]])
                else:
                    temp_fasta.extend([fasta_to_clean[i].split('\t')[0], fasta_to_clean[i + 1]])
    write_list_to_destination(fasta_path, temp_fasta)
コード例 #6
0
    def _weighted_unifrac_make_and_write_mothur_batch(self):
        mothur_batch_file = [
            f'set.dir(input={self.input_dir})',
            f'set.dir(output={self.output_dir})',
            f'unifrac.weighted(tree={self.tree_file_path}, group={self.group_file_path}, name={self.name_file_path},'
            f' distance=square, processors={self.processors})'
        ]

        self._set_mothur_batch_file_path()

        write_list_to_destination(self.mothur_batch_file_path, mothur_batch_file)
コード例 #7
0
 def _split_abund_make_and_write_mothur_batch(self, abund_cutoff):
     if self.name_file_path:
         mothur_batch_file = [
             f'set.dir(input={self.input_dir})',
             f'set.dir(output={self.output_dir})',
             f'split.abund(fasta={self.fasta_path}, name={self.name_file_path}, cutoff={abund_cutoff})'
         ]
     else:
         raise RuntimeError(
             'Non name_file_path present. '
             'A name file is necessary to be able to assess the abundances of sequences in the .fasta file'
         )
     self._set_mothur_batch_file_path()
     write_list_to_destination(self.mothur_batch_file_path, mothur_batch_file)
コード例 #8
0
 def _summarise_make_and_write_mothur_batch(self):
     if self.name_file_path:
         mothur_batch_file = [
             f'set.dir(input={self.input_dir})',
             f'set.dir(output={self.output_dir})',
             f'summary.seqs(fasta={self.fasta_path}, name={self.name_file_path})'
         ]
     else:
         mothur_batch_file = [
             f'set.dir(input={self.input_dir})',
             f'set.dir(output={self.output_dir})',
             f'summary.seqs(fasta={self.fasta_path})'
         ]
     self._set_mothur_batch_file_path()
     write_list_to_destination(self.mothur_batch_file_path, mothur_batch_file)
コード例 #9
0
 def _if_scrap_fasta_exists_clean_and_write_out(self, fwd_output_scrapped_fasta_path):
     # NB Mothur will not output a scrap fasta file if there are no scrap fasta. Also NB that mothur will output
     # sequence names with no sequence for sequences that have multiple matches for a given primer.
     # we should screen for these and remove them.
     if fwd_output_scrapped_fasta_path == '':
         return False
     else:
         scrapped_fasta_as_list = read_defined_file_to_list(fwd_output_scrapped_fasta_path)
         if scrapped_fasta_as_list:
             new_scrapped_fasta = self._make_new_fasta_no_multi_match_lines(scrapped_fasta_as_list)
             if new_scrapped_fasta:
                 write_list_to_destination(fwd_output_scrapped_fasta_path, new_scrapped_fasta)
                 return True
             else:
                 return False
         else:
             return False
コード例 #10
0
 def write_out_as_fasta(self):
     self.file_path = self.infer_fasta_path_from_current_fastq_path()
     write_list_to_destination(destination=self.file_path, list_to_write=self.as_fasta())
コード例 #11
0
 def _screen_seqs_make_and_write_mothur_batch_file(self, argument_dictionary):
     mothur_batch_file = self._screen_seqs_make_mothur_batch_file(argument_dictionary)
     self._set_mothur_batch_file_path()
     write_list_to_destination(self.mothur_batch_file_path, mothur_batch_file)
コード例 #12
0
 def _pcr_make_and_write_mothur_batch_file(self):
     mothur_batch_file = self._pcr_make_mothur_batch_file()
     self._set_mothur_batch_file_path()
     write_list_to_destination(self.mothur_batch_file_path, mothur_batch_file)
コード例 #13
0
 def _rev_comp_make_and_write_mothur_batch_file(self):
     mothur_batch_file = self._make_rev_complement_mothur_batch_file()
     self._set_mothur_batch_file_path()
     write_list_to_destination(self.mothur_batch_file_path, mothur_batch_file)
コード例 #14
0
 def _make_contig_make_and_write_out_dot_file(self):
     dot_file_file = [f'{self.fastq_gz_fwd_path} {self.fastq_gz_rev_path}']
     dot_file_file_path = os.path.join(self.input_dir, f'{self.name}_fastq_pair.file')
     write_list_to_destination(dot_file_file_path, dot_file_file)
     return dot_file_file_path