def sortTitles(self, by):
        titles = sorted(iter(self))
        if by == 'length':
            return sorted(
                titles, reverse=True,
                key=lambda title: self[title].subjectLength)
        if by == 'maxScore':
            return sorted(
                titles, reverse=True, key=lambda title: self[title].bestHsp())
        if by == 'medianScore':
            return sorted(
                titles, reverse=True,
                key=lambda title: self.scoreClass(self[title].medianScore()))
        if by == 'readCount':
            return sorted(
                titles, reverse=True,
                key=lambda title: self[title].readCount())
        if by == 'title':
            return titles
        raise ValueError('Sort attribute must be one of "length", "maxScore", '
                         '"medianScore", "readCount", "title".')