Refactored. Working.
Transitioned to subproc call to use megablast. Also filter for median seq length and build combined fasta all in this single script now.