code: def blocks(aln, threshold=0.5, weights=None):
      assert len(aln)
      if weights == False:
          def pct_nongaps(col):
              return 1 - (float(col.count('-')) / len(col))
      else:
          if weights in (None, True):
              weights = sequence_weights(aln, 'avg1')
          def pct_nongaps(col):
              assert len(col) == len(weights)
              ngaps = sum(wt * (c == '-')
                          for wt, c in zip(weights, col))
              return 1 - (ngaps / len(col))
      seqstrs = [str(rec.seq) for rec in aln]
      clean_cols = [col for col in zip(*seqstrs)
                    if pct_nongaps(col) >= threshold]
      alphabet = aln[0].seq.alphabet
      clean_seqs = [Seq(''.join(row), alphabet)
                    for row in zip(*clean_cols)]
      clean_recs = []
      for rec, seq in zip(aln, clean_seqs):
          newrec = deepcopy(rec)
          newrec.seq = seq
          clean_recs.append(newrec)
      return MultipleSeqAlignment(clean_recs, alphabet=alphabet)