code: def gene_by_id(self, gene_id):
          
          if gene_id not in self._genes:
              field_names = [
                  "seqname",
                  "start",
                  "end",
                  "strand",
              ]
              optional_field_names = [
                  "gene_name",
                  "gene_biotype",
              ]
              # Do not look for gene_name and gene_biotype if they are
              # not in the database.
              field_names.extend([
                  name for name in optional_field_names
                  if self.db.column_exists("gene", name)
              ])
              result = self.db.query_one(
                  field_names,
                  filter_column="gene_id",
                  filter_value=gene_id,
                  feature="gene")
              if not result:
                  raise ValueError("Gene not found: %s" % (gene_id,))
  
              gene_name, gene_biotype = None, None
              assert len(result) >= 4 and len(result) <= 6, \
                  "Result is not the expected length: %d" % len(result)
              contig, start, end, strand = result[:4]
              if len(result) == 5:
                  if "gene_name" in field_names:
                      gene_name = result[4]
                  else:
                      gene_biotype = result[4]
              elif len(result) == 6:
                  gene_name, gene_biotype = result[4:]
  
              self._genes[gene_id] = Gene(
                  gene_id=gene_id,
                  gene_name=gene_name,
                  contig=contig,
                  start=start,
                  end=end,
                  strand=strand,
                  biotype=gene_biotype,
                  genome=self)
  
          return self._genes[gene_id]
docs: Construct a Gene object for the given gene ID.