def subsample_fasta(input_fasta_fp, output_fp, percent_subsample):
 input_fasta = open(input_fasta_fp, 'U')
 output_fasta = open(output_fp, 'w')
 for (label, seq) in parse_fasta(input_fasta):
  if (random() < percent_subsample):
   output_fasta.write(('>%s\n%s\n' % (label, seq)))
 input_fasta.close()
 output_fasta.close()

def subsample_fasta ( input_fasta_fp , output_fp , percent_subsample ) : input_fasta = open ( input_fasta_fp , 'U' ) output_fasta = open ( output_fp , 'w' ) for ( label , seq ) in parse_fasta ( input_fasta ) : if ( random ( ) < percent_subsample ) : output_fasta . write ( ( '>%s\n%s\n' % ( label , seq ) ) ) input_fasta . close ( ) output_fasta . close ( )
writes random percent_sample of sequences from input fasta filepath input_fasta_fp: input fasta filepath output_fp: output fasta filepath percent_subsample: percent of sequences to write .