Skip to content
Browse files

Pass all the tests again

  • Loading branch information...
1 parent c807ef9 commit 6f8805bdf923c730f950d65e09f2ab548e0fa22f Ben J Woodcroft committed May 3, 2012
Showing with 32 additions and 0 deletions.
  1. +32 −0 lib/bio/transmembrane.rb
View
32 lib/bio/transmembrane.rb
@@ -1,3 +1,35 @@
+
+# Monkey-patch Array#pair in
+class Array
+ # Return an array of all pairs of elements from this array (each is an array).
+ # If another_array is not nil, then do pairwise between this array and that (but not within each)
+ #
+ # NOT thread safe.
+ def pairs(another_array = nil)
+ pairs = []
+
+ if another_array #between this array and the next
+ (0..length-1).each do |index1|
+ (0..another_array.length-1).each do |index2|
+ pairs.push [self[index1], another_array[index2]]
+ end
+ end
+ else # within this array only
+ (0..length-1).each do |index1|
+ index2 = index1+1
+ while index2 < length
+ pairs.push [self[index1], self[index2]]
+ index2 += 1
+ end
+ end
+ end
+
+ return pairs
+ end
+end
+
+
+
# a simple class to represent a transmembrane domain, and a transmembrane domain containing protein
module Bio
module Transmembrane

0 comments on commit 6f8805b

Please sign in to comment.
Something went wrong with that request. Please try again.