Creates .fasta files containing all alleles for each gene

def corewriter(self):
        """
        Creates .fasta files containing all alleles for each gene
        """
        printtime('Creating core allele files', self.start)
        for gene in sorted(self.genesequence):
            self.geneset.add(gene)
            # Set the name of the allele file
            genefile = os.path.join(self.coregenelocation, '{}.fasta'.format(gene))
            # If the file doesn't exist, create it
            if not os.path.isfile(genefile):
                with open(genefile, 'w') as core:
                    for count, sequence in enumerate(self.genesequence[gene]):
                        # The definition line is the gene name, and the allele number (count (+ 1 to compensate for
                        # base zero))
                        definitionline = '{}-{}'.format(gene, count + 1)
                        # Create a sequence record using BioPython
                        fasta = SeqRecord(Seq(sequence),
                                          # Without this, the header will be improperly formatted
                                          description='',
                                          # Use >:definitionline as the header
                                          id=definitionline)
                        # Use the SeqIO module to properly format the new sequence record
                        SeqIO.write(fasta, core, 'fasta')
                        for strain in self.coresequence[sequence]:
                            # Record the strain name, the gene name, and the allele number.
                            # [:-6] removes the contig number: 2014-SEQ-0276_00001 becomes 2014-SEQ-0276
                            try:
                                self.corealleles[strain[:-6]].update({gene: count + 1})
                            except KeyError:
                                self.corealleles[strain[:-6]] = {gene: count + 1}
            else:
                # If the file exists, don't recreate it; only iterate through the dictionary of gene sequences
                for count, sequence in enumerate(self.genesequence[gene]):
                    for strain in self.coresequence[sequence]:
                        # Populate the dictionary as above
                        try:
                            self.corealleles[strain[:-6]].update({gene: count + 1})
                        except KeyError:
                            self.corealleles[strain[:-6]] = {gene: count + 1}
        # Create a combined file of all the core genes to be used in typing strain(s) of interest
        if not os.path.isfile(os.path.join(self.coregenelocation, 'core_combined.fasta')):
            fastafiles = glob(os.path.join(self.coregenelocation, '*.fasta'))
            # Run the method for each allele
            self.combinealleles(fastafiles)
        # Run the profiler
        self.profiler()