old_contents: import json
  
  from ctypes import *
  from CodonCountStruct import CodonCount
  
  from Bio import SeqIO
  
  
  # convert ctypes structure into a python dictionary
  def getdict(struct):
      return dict(
          (field, getattr(struct, field)) for field, _ in struct._fields_
          )
  
  
  # produce JSON from data object
  def writeCounts(data, pretty):
      if pretty:
          sort = True
          ident = 2
      else:
          sort = False
          ident = None
      print json.dumps(data, sort_keys=sort, indent=ident)
  
  
  # count codons and produce json containing the organism information & counts
  # args.infile = path to a file to parse
  # args.format = 'fasta' or 'genbank', the format of the file
  # args.pretty = boolean, whether or not to pretty-print the resulting JSON
  def count(args):
      counterc = CDLL('./lib/counterc.so')
      counterc.countcodons.argtypes = (c_char_p,)
      counterc.countcodons.restype = CodonCount
  
      data = []
  
      for seq_record in SeqIO.parse(args.infile, args.format):
          # only bother producing output if there is actual sequence data;
          # i.e., not all unknowns
          if len(seq_record.seq) != seq_record.seq.count("N"):
              # count the codons and put them in the data object along with
              # other metadata
              cstruct = counterc.countcodons(str(seq_record.seq))
              data += [{
                       "id": seq_record.id,
                       "name": seq_record.name,
                       "description": seq_record.description,
                       "annotations": str(seq_record.annotations),
                       "features": str(seq_record.features),
                       "dbxrefs": seq_record.dbxrefs,
                       "codoncount": getdict(cstruct)
                       }]
      # only write if data exists (i.e., we actually had sequence data
      if data:
          writeCounts(data, args.pretty)
  
new_contents: import json
  import Bio
  
  from ctypes import *
  from CodonCountStruct import CodonCount
  
  
  # convert ctypes structure into a python dictionary
  def getdict(struct):
      return dict(
          (field, getattr(struct, field)) for field, _ in struct._fields_
          )
  
  
  # produce JSON from data object
  def writeCounts(data, pretty):
      if pretty:
          sort = True
          ident = 2
      else:
          sort = False
          ident = None
      print json.dumps(data, sort_keys=sort, indent=ident)
  
  
  # count codons and produce json containing the organism information & counts
  # args.infile = path to a file to parse
  # args.format = 'fasta' or 'genbank', the format of the file
  # args.pretty = boolean, whether or not to pretty-print the resulting JSON
  def count(args):
      counterc = CDLL('./lib/counterc.so')
      counterc.countcodons.argtypes = (c_char_p,)
      counterc.countcodons.restype = CodonCount
  
      data = []
  
      for seq_record in SeqIO.parse(args.infile, args.format):
          # only bother producing output if there is actual sequence data;
          # i.e., not all unknowns
          if len(seq_record.seq) != seq_record.seq.count("N"):
              # count the codons and put them in the data object along with
              # other metadata
              cstruct = counterc.countcodons(str(seq_record.seq))
              data += [{
                       "id": seq_record.id,
                       "name": seq_record.name,
                       "description": seq_record.description,
                       "annotations": str(seq_record.annotations),
                       "features": str(seq_record.features),
                       "dbxrefs": seq_record.dbxrefs,
                       "codoncount": getdict(cstruct)
                       }]
      # only write if data exists (i.e., we actually had sequence data
      if data:
          writeCounts(data, args.pretty)
  
subject: Change import style to fit celery import of BioPython