Skip to content

Instantly share code, notes, and snippets.

@brentp
Created March 28, 2011 14:10
Show Gist options
  • Save brentp/890525 to your computer and use it in GitHub Desktop.
Save brentp/890525 to your computer and use it in GitHub Desktop.
non-working, ugly patch for keep_cols
+ def _keep_cols(self, tmpfn, other, keep_new):
+ """
+ called after performing and operation to keep only
+ the desired columns
+ """
+
+
+ # TODO: handle > 1 feature_classes
+ """
+ all_slots = self._feature_classes[0].__slots__ \
+ + other._feature_classes[0].__slots__
+
+ tmp_klass = type('TMP', (self.__class__, ), dict(__slots__=all_slots))
+ """
+
+ this_cols = sum(len(f.__slots__) for f in self._feature_classes)
+ keep_idxs = range(this_cols)
+
+ oslots = other._feature_classes[0].__slots__
+ print >>sys.stderr, oslots
+ keep_idxs += [len(keep_idxs) + oslots.index(k) for k in keep_new]
+
+ fh = open(self._tmp(), "w")
+
+ for row in bedtool(tmpfn): #, _feature_classes=tmp_klass):
+ toks = row.split("\t")
+ print >>fh, "\t".join(toks[i] for i in keep_idxs)
+ fh.close()
+
+
+ slots = []
+ for c in self._feature_classes:
+ slots.extend(c.__slots__)
+
+ keep_new = list(keep_new)
+ for i, k in enumerate(keep_new):
+ if keep_new[i] in slots:
+ keep_new[i] += "_1"
+ slots.extend(keep_new)
+ print >>sys.stderr, "\nSLOTS:", slots
+
+ class f_klass(self._feature_classes[0].__class__):
+ __slots__ = tuple(slots)
+ return bedtool(fh.name, _feature_classes=[f_klass])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment