Create reports of the findings

def report(self):
        """
        Create reports of the findings
        """
        # Initialise a variable to store the results
        data = ''
        for sample in self.metadata:
            if sample[self.analysistype].primers != 'NA':
                # Set the name of the strain-specific report
                sample[self.analysistype].report = os.path.join(sample[self.analysistype].reportdir,
                                                                '{}_{}.csv'.format(sample.name, self.analysistype))
                # Populate the strain-specific string with header, and strain name
                strainspecific = 'Strain,{},\n{},'.format(','.join(sorted(sample[self.analysistype].targets)),
                                                          sample.name)
                # Iterate through all the genes in the organism-specific analysis
                for gene in sorted(sample[self.analysistype].targets):
                    try:
                        # Extract the percent identity
                        percentidentity = sample[self.analysistype].blastresults[gene]['percent_identity']
                        # If the % identity is greater than the cutoff of 50%, the gene is considered to be present
                        if percentidentity > 50:
                            strainspecific += '{},'.format(percentidentity)
                        else:
                            strainspecific += '-,'
                    # If there are no BLAST results, then the gene is absent
                    except KeyError:
                        strainspecific += '-,'
                strainspecific += '\n'
                # Open and write the data to the strain-specific report
                with open(sample[self.analysistype].report, 'w') as specificreport:
                    specificreport.write(strainspecific)
                # Add all the data from each strain to the cumulative data string
                data += strainspecific
        # Open and write the cumulative data to the cumulative report
        with open(os.path.join(self.reportdir, '{}.csv'.format(self.analysistype)), 'w') as report:
            report.write(data)