Parse the results dictionaries, and create a final report

def create_epr_report(self):
        """
        Parse the results dictionaries, and create a final report
        """
        # Open the report as a .csv file
        with open(os.path.join(self.reportpath, 'ePCR_report.csv'), 'w') as report:
            # Initialise a string to store the header
            results = 'Sample,Gene,GenomeLocation,AmpliconSize,Contig,TotalMismatches,PrimerSet\n'
            for sample in self.vtyper_object.metadata:
                # Check to see if there are strain-specific results
                if sample[self.analysistype].result_dict:
                    for gene, result_dict in sample[self.analysistype].result_dict.items():
                        # Populate the string with the appropriate values extracted from the dictionary
                        results += '{sn},{gene},{genomelocation},{ampliconsize},{contig},{nm},{ps}\n'\
                            .format(sn=sample.name,
                                    gene=gene,
                                    genomelocation=result_dict['genome_pos'],
                                    ampliconsize=result_dict['amplicon_length'],
                                    contig=result_dict['contig'],
                                    nm=result_dict['total_mismatches'],
                                    ps=result_dict['primer_set'])
                        if self.export_amplicons:
                            self.ampliconfile(sample=sample,
                                              contig=result_dict['contig'],
                                              amplicon_range=result_dict['genome_pos'].split('-'),
                                              primer_set=result_dict['primer_set'])
                else:
                    results += '{sn}\n'.format(sn=sample.name)
            # Write the complete string to the report
            report.write(results)