def _extract_from_raw_reads(self, output_path, input_reads, raw_sequences_path, input_file_format, hits):
        '''
        _extract_from_raw_reads - call fxtract to extract the hit sequences
        of the hmm/diamond search from the raw sequences file. Output into
        specified file

        Parameters
        ----------
        output_path : str
            Path of the desired output file
        input_reads : list
            list of read IDS to extract.
        raw_sequences_path : str
            Path to the raw sequences
        input_file_format : var
            Variable, either FORMAT_FASTA_GZ, FORMAT_FASTQ_GZ, FORMAT_FASTQ or
            FORMAT_FASTA, denoting the format of the input sequence
        hits : dict
            A hash with the readnames as the keys and the spans as the values

        Returns
        -------
        output_path: str
            Path to file containing extracted reads.
        
        direction_information: dict
            
            {read_1: False
             ...
             read n: True}
            
            where True = Forward direction
            and False = Reverse direction
        '''

        with tempfile.NamedTemporaryFile(prefix='_raw_extracted_reads.fa') as tmp:
            # Run fxtract to obtain reads form original sequence file
            fxtract_cmd = "fxtract -H -X -f /dev/stdin " 
            if input_file_format == FORMAT_FASTA:
                cmd = "%s %s > %s" % (fxtract_cmd, raw_sequences_path, tmp.name)
            elif input_file_format == FORMAT_FASTQ_GZ:
                cmd = "%s -z %s | awk '{print \">\" substr($0,2);getline;print;getline;getline}' > %s" % (fxtract_cmd, raw_sequences_path, tmp.name)
            elif input_file_format == FORMAT_FASTA_GZ:
                cmd = "%s -z %s > %s" % (fxtract_cmd, raw_sequences_path, tmp.name)
            elif input_file_format == FORMAT_FASTQ:
                cmd = "%s %s | awk '{print \">\" substr($0,2);getline;print;getline;getline}' > %s" % (fxtract_cmd, raw_sequences_path, tmp.name)
            else:
                raise Exception("Programming error")

            process = subprocess.Popen(["bash", "-c", cmd], 
                                       stdin=subprocess.PIPE,
                                       stdout=subprocess.PIPE)
            process.communicate('\n'.join(input_reads))
            complement_info = self._extract_multiple_hits(hits, tmp.name, output_path)  # split them into multiple reads
        
        return output_path, complement_info
def _extract_from_raw_reads ( self , output_path , input_reads , raw_sequences_path , input_file_format , hits ) : with tempfile . NamedTemporaryFile ( prefix = '_raw_extracted_reads.fa' ) as tmp : fxtract_cmd = "fxtract -H -X -f /dev/stdin " if input_file_format == FORMAT_FASTA : cmd = "%s %s > %s" % ( fxtract_cmd , raw_sequences_path , tmp . name ) elif input_file_format == FORMAT_FASTQ_GZ : cmd = "%s -z %s | awk '{print \">\" substr($0,2);getline;print;getline;getline}' > %s" % ( fxtract_cmd , raw_sequences_path , tmp . name ) elif input_file_format == FORMAT_FASTA_GZ : cmd = "%s -z %s > %s" % ( fxtract_cmd , raw_sequences_path , tmp . name ) elif input_file_format == FORMAT_FASTQ : cmd = "%s %s | awk '{print \">\" substr($0,2);getline;print;getline;getline}' > %s" % ( fxtract_cmd , raw_sequences_path , tmp . name ) else : raise Exception ( "Programming error" ) process = subprocess . Popen ( [ "bash" , "-c" , cmd ] , stdin = subprocess . PIPE , stdout = subprocess . PIPE ) process . communicate ( '\n' . join ( input_reads ) ) complement_info = self . _extract_multiple_hits ( hits , tmp . name , output_path ) return output_path , complement_info
_extract_from_raw_reads - call fxtract to extract the hit sequences
        of the hmm/diamond search from the raw sequences file. Output into
        specified file

        Parameters
        ----------
        output_path : str
            Path of the desired output file
        input_reads : list
            list of read IDS to extract.
        raw_sequences_path : str
            Path to the raw sequences
        input_file_format : var
            Variable, either FORMAT_FASTA_GZ, FORMAT_FASTQ_GZ, FORMAT_FASTQ or
            FORMAT_FASTA, denoting the format of the input sequence
        hits : dict
            A hash with the readnames as the keys and the spans as the values

        Returns
        -------
        output_path: str
            Path to file containing extracted reads.
        
        direction_information: dict
            
            {read_1: False
             ...
             read n: True}
            
            where True = Forward direction
            and False = Reverse direction