Link the sequence types to the strains. Create a .csv file of the linkages

def linker(self):
        """
        Link the sequence types to the strains. Create a .csv file of the linkages
        """

        strainprofile = os.path.join(self.profilelocation, 'strainprofiles.txt')
        if not os.path.isfile(strainprofile):
            header = 'Strain,SequenceType\n'
            data = ''
            # Sort the profiles based on sequence type
            sortedprofiles = sorted(self.profiles.items(), key=operator.itemgetter(1))
            # Associate the sequence type with each strain
            for strain, seqtype in sortedprofiles:
                for sample in self.runmetadata.samples:
                    if sample.name == strain:
                        sample.general.coretype = seqtype
                        data += '{},{}\n'.format(strain, seqtype)
            # Write the results to file
            with open(strainprofile, 'w') as profile:
                profile.write(header)
                profile.write(data)