def validate_sequence(sequence: str, sequence_is_as_nucleotide=True):
tmp_seq = tempfile.NamedTemporaryFile(mode="<STR_LIT>", delete=False)<EOL>if len(str(sequence).strip()) == <NUM_LIT:0>:<EOL><INDENT>raise forms.ValidationError(blast_settings.BLAST_CORRECT_SEQ_ERROR_MSG)<EOL><DEDENT>if str(sequence).strip()[<NUM_LIT:0>] != "<STR_LIT:>>":<EOL><INDENT>tmp_seq.write("<STR_LIT>".encode())<EOL><DEDENT>tmp_seq.write(sequence.encode())<EOL>tmp_seq.close()<EOL>records = SeqIO.index(tmp_seq.name, "<STR_LIT>")<EOL>record_count = len(records)<EOL>if record_count == <NUM_LIT:0>:<EOL><INDENT>raise forms.ValidationError(blast_settings.BLAST_CORRECT_SEQ_ERROR_MSG)<EOL><DEDENT>if record_count > blast_settings.BLAST_MAX_NUMBER_SEQ_IN_INPUT:<EOL><INDENT>raise forms.ValidationError(blast_settings.BLAST_CORRECT_SEQ_MAX_SEQ_NUMB_ERROR_MSG)<EOL><DEDENT>first_sequence_list_in_file = SeqIO.parse(tmp_seq.name, "<STR_LIT>")<EOL>for sequence in first_sequence_list_in_file:<EOL><INDENT>if len(sequence.seq) <= <NUM_LIT:10>:<EOL><INDENT>raise forms.ValidationError(blast_settings.BLAST_CORRECT_SEQ_TOO_SHORT_ERROR_MSG)<EOL><DEDENT>if sequence_is_as_nucleotide:<EOL><INDENT>check_allowed_letters(str(sequence.seq), ALLOWED_NUCL)<EOL><DEDENT>else:<EOL><INDENT>check_allowed_letters(str(sequence.seq), ALLOWED_AMINOACIDS)<EOL><DEDENT><DEDENT>return tmp_seq<EOL>
Validate sequence in blast/tblastn form.