code: def fix_orientation(self, tour):
          
          orientations = dict(tour)  # old configuration here
          scaffold_oo = defaultdict(list)
          scaffolds, oos = zip(*tour)
          for mlg in self.linkage_groups:
              lg = mlg.lg
              mapname = mlg.mapname
              for s, o in tour:
                  i = scaffolds.index(s)
                  L = [self.get_series(lg, x, xo) for x, xo in tour[:i]]
                  U = [self.get_series(lg, x, xo) for x, xo in tour[i + 1:]]
                  L, U = list(flatten(L)), list(flatten(U))
                  M = self.get_series(lg, s)
                  plus = lms(L + M + U)
                  minus = lms(L + M[::-1] + U)
                  d = plus[0] - minus[0]
                  if not d:
                      continue
                  scaffold_oo[s].append((d, mapname))  # reset orientation
  
          fixed = 0
          for s, v in scaffold_oo.items():
              d = self.weighted_mean(v)
              old_d = orientations[s]
              new_d = np.sign(d)
              if new_d != old_d:
                  orientations[s] = new_d
                  fixed += 1
  
          tour = [(x, orientations[x]) for x in scaffolds]
          logging.debug("Fixed orientations for {0} scaffolds.".format(fixed))
          return tour
docs: Test each scaffold if flipping will increass longest monotonic chain
          length.