code: def sort_layout(thread, listfile, column=0):
      from jcvi.formats.base import DictFile
      outfile = listfile.rsplit(".", 1)[0] + ".sorted.list"
      threadorder = thread.order
      fw = open(outfile, "w")
      lt = DictFile(listfile, keypos=column, valuepos=None)
      threaded = []
      imported = set()
      for t in thread:
          accn = t.accn
          if accn not in lt:
              continue
          imported.add(accn)
          atoms = lt[accn]
          threaded.append(atoms)
      assert len(threaded) == len(imported)
      total = sum(1 for x in open(listfile))
      logging.debug("Total: {0}, currently threaded: {1}".format(total, len(threaded)))
      fp = open(listfile)
      for row in fp:
          atoms = row.split()
          accn = atoms[0]
          if accn in imported:
              continue
          insert_into_threaded(atoms, threaded, threadorder)
      for atoms in threaded:
          print("\t".join(atoms), file=fw)
      fw.close()
      logging.debug("File `{0}` sorted to `{1}`.".format(outfile, thread.filename))