code: def get_upstream_coords(uSite, uLen, seqlen, feat, children_list, gffdb):
      
      if uSite == "TSS":
          (upstream_start, upstream_stop) = \
                  (feat.start - uLen, feat.start - 1) \
                  if feat.strand == "+" else \
                  (feat.end + 1, feat.end + uLen)
      elif uSite == "TrSS":
          children = []
          for c in gffdb.children(feat.id, 1):
  
              if c.featuretype not in children_list:
                  continue
              children.append((c.start, c.stop))
  
          if not children:
              print("[warning] %s has no children with type %s" \
                                      % (feat.id, ','.join(children_list)), file=sys.stderr)
              return None, None
  
          cds_start, cds_stop = range_minmax(children)
          (upstream_start, upstream_stop) = \
                  (cds_start - uLen, cds_start - 1) \
                  if feat.strand == "+" else \
                  (cds_stop + 1, cds_stop + uLen)
  
      if feat.strand == "+" and upstream_start < 1:
          upstream_start = 1
      elif feat.strand == "-" and upstream_stop > seqlen:
          upstream_stop = seqlen
  
      actual_uLen = upstream_stop - upstream_start + 1
      if actual_uLen < uLen:
          print("[warning] sequence upstream of {0} ({1} bp) is less than upstream length {2}" \
                  .format(feat.id, actual_uLen, uLen), file=sys.stderr)
          return None, None
  
      return upstream_start, upstream_stop
docs: Subroutine takes upstream site, length, reference sequence length,
      parent mRNA feature (GffLine object), list of child feature types
      and a GFFutils.GFFDB object as the input
  
      If upstream of TSS is requested, use the parent feature coords
      to extract the upstream sequence
  
      If upstream of TrSS is requested,  iterates through all the
      children (CDS features stored in the sqlite GFFDB) and use child
      feature coords to extract the upstream sequence
  
      If success, returns the upstream start and stop coordinates
      else, returns None