def count_seqs_in_filepaths(fasta_filepaths, seq_counter=count_seqs):
 total = 0
 counts = []
 inaccessible_filepaths = []
 for fasta_filepath in fasta_filepaths:
  if (fasta_filepath.endswith('.fastq') or fasta_filepath.endswith('.fq')):
   parser = partial(parse_fastq, enforce_qual_range=False)
  elif (fasta_filepath.endswith('.tre') or fasta_filepath.endswith('.ph') or fasta_filepath.endswith('.ntree')):
   def parser(f):
    t = DndParser(f, constructor=PhyloNode)
    return zip(t.iterTips(), repeat(''))
  else:
   parser = parse_fasta
  try:
   current_count = seq_counter(fasta_filepath, parser=parser)
   counts.append((current_count, fasta_filepath))
   total += current_count[0]
  except IOError:
   inaccessible_filepaths.append(fasta_filepath)
 return (counts, total, inaccessible_filepaths)

def count_seqs_in_filepaths ( fasta_filepaths , seq_counter = count_seqs ) : total = 0 counts = [ ] inaccessible_filepaths = [ ] for fasta_filepath in fasta_filepaths : if ( fasta_filepath . endswith ( '.fastq' ) or fasta_filepath . endswith ( '.fq' ) ) : parser = partial ( parse_fastq , enforce_qual_range = False ) elif ( fasta_filepath . endswith ( '.tre' ) or fasta_filepath . endswith ( '.ph' ) or fasta_filepath . endswith ( '.ntree' ) ) : def parser ( f ) : t = DndParser ( f , constructor = PhyloNode ) return zip ( t . iterTips ( ) , repeat ( '' ) ) else : parser = parse_fasta try : current_count = seq_counter ( fasta_filepath , parser = parser ) counts . append ( ( current_count , fasta_filepath ) ) total += current_count [ 0 ] except IOError : inaccessible_filepaths . append ( fasta_filepath ) return ( counts , total , inaccessible_filepaths )
wrapper to apply seq_counter to fasta_filepaths fasta_filepaths: list of one or more fasta filepaths seq_counter: a function which takes a single filepath and returns the count of the number of sequences -- this is parameterized to facilitate unit testing .