Project: s41467-024-54392-x | Function: GetTopHitAA (cpp)

system: You are an expert C++ programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow C++ best practices and maintain consistent code style.
Return **only** the complete C++ function code.

user: Complete this C++ function:

**DESCRIPTION:** Scans amino acid sequences to find the highest-scoring match against a nifH PSSM model using sliding window approach

**KEY TERMS:** {
  "P": "PSSM model for nifH",
  "AASeq": "amino acid sequence to search",
  "L": "sequence length",
  "M": "PSSM model length",
  "BestScore": "highest alignment score",
  "BestPos": "position of best match",
  "MinScore": "minimum score threshold",
  "Hit": "structure storing match information"
}

**CONTEXT CODE:** #include "myutils.h"
#include "sfasta.h"
#include "pssm.h"
#include "pssmsearch.h"
#include <iostream>
#include <stdexcept>

#define TRACE	0


///
/// �����ѵ÷ֵİ���������Ƭ�Σ����ƣ�����Ϣ������ PSSMHitAA �ṹ��
/// 
/// P������������ PSSM ģ��
/// MinScore��\
/// Label�����������еı�ǩ
/// AASeq������������
/// L�����������еĳ���
/// Hit��PSSMHitAA �ṹ��

#include <climits>
#include <algorithm>

void GetTopHitAA(const PSSM &P, float MinScore,
  const string &Label, const char *AASeq, unsigned L,
  PSSMHitAA &Hit)
{
    const unsigned M = P.GetColCount();
    if (L < M)
    {
        Hit.AAPos = UINT_MAX;
        Hit.Score = -FLT_MAX;
        return;
    }

    Hit.Label = Label;
    Hit.AAPos = 0;
    Hit.Score = -FLT_MAX;

    for (unsigned Pos = 0; Pos <= L - M; ++Pos)
    {
        float Score = 0;
        for (unsigned j = 0; j < M; ++j)
        {
            char AA = AASeq[Pos + j];
            Score += P.GetScore(AA, j);
        }

        if (Score > Hit.Score)
        {
            Hit.AAPos = Pos;
            Hit.Score = Score;
        }
    }

    if (Hit.Score < MinScore)
        Hit.AAPos = UINT_MAX;
}


// ����� Query ���бȶԵ÷���ߵ� Group ���Լ���� group �� PSSMs �ıȶ���Ϣ
void SearchAATop()
	{
	asserta(optset_psm);
	const string InputFileName = string(opt_search_aa_top);		// �����ļ���
	const string OutputFileName = string(opt_output);			// ����ļ��� 
	asserta(InputFileName != "");
	asserta(OutputFileName != "");

	FILE *fOut = CreateStdioFile(OutputFileName);

	PSSM P;
	P.FromFile(opt_psm);						// ���ļ���ȡ PSSM ����
	unsigned M = P.GetColCount();				// ��� PSSM ���г���

	SFasta SF;					
	SF.Open(InputFileName);						// SFasta ��������ȡ fatsa �ļ�

	ProgressStep(0, 1002, "Search aa %s", SF.m_FileName.c_str());
	for (;;)
		{
		const char *Seq = SF.GetNextSeq();		// SF �洢 fasta �ļ��ĸ�����Ϣ��Seq Ϊָ�����п�ͷ��ָ��
		if (Seq == 0)
			break;
		ProgressStep(SF.GetPctDoneX10(), 1002, "Search aa %s", SF.m_FileName.c_str());

		const string Label = SF.GetLabel();
		const unsigned L = SF.GetSeqLength();

		PSSMHitAA Hit;
		GetTopHitAA(P, (float) opt_minscore, Label, (const char *) Seq, L, Hit);	// Hit �������˸� Query ��������ߵ÷� Group �� PSSMs �ıȶ���Ϣ
		unsigned Pos = Hit.AAPos;
		if (Pos == UINT_MAX)
			continue;

		fprintf(fOut, "%s", Label.c_str());
		fprintf(fOut, "\t%u", Pos + 1);
		fprintf(fOut, "\t%.3f", Hit.Score);
		fprintf(fOut, "\t%*.*s", M, M, Seq + Pos);
		fprintf(fOut, "\n");
		}
	ProgressStep(1001, 1002, "Search aa %s", SF.m_FileName.c_str());

	CloseStdioFile(fOut);
	}


Complete the function implementation replacing "throw std::runtime_error("Not implemented");".