[BioRuby-cvs] bioruby/lib/bio alignment.rb, 1.7, 1.8 db.rb, 0.27, 0.28 feature.rb, 1.5, 1.6 location.rb, 0.18, 0.19 pathway.rb, 1.29, 1.30 reference.rb, 1.16, 1.17 sequence.rb, 0.40, 0.41

Katayama Toshiaki k at pub.open-bio.org
Wed Sep 7 21:22:10 EDT 2005


Update of /home/repository/bioruby/bioruby/lib/bio
In directory pub.open-bio.org:/tmp/cvs-serv9021/lib/bio

Modified Files:
	alignment.rb db.rb feature.rb location.rb pathway.rb 
	reference.rb sequence.rb 
Log Message:
* expanded tab at the line head


Index: location.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/location.rb,v
retrieving revision 0.18
retrieving revision 0.19
diff -C2 -d -r0.18 -r0.19
*** location.rb	14 May 2004 03:07:26 -0000	0.18
--- location.rb	8 Sep 2005 01:22:08 -0000	0.19
***************
*** 30,42 ****
  
        if location
! 	if location =~ /:/				# (G) ID:location
! 	  xref_id, location = location.split(':')
! 	end
! 	if location =~ /</				# (I) <,>
! 	  lt = true
! 	end
! 	if location =~ />/
! 	  gt = true
! 	end
        end
  
--- 30,42 ----
  
        if location
!         if location =~ /:/				# (G) ID:location
!           xref_id, location = location.split(':')
!         end
!         if location =~ /</				# (I) <,>
!           lt = true
!         end
!         if location =~ />/
!           gt = true
!         end
        end
  
***************
*** 44,69 ****
        case location
        when /^[<>]?(\d+)$/				# (A, I) n
! 	s = e = $1.to_i
        when /^[<>]?(\d+)\.\.[<>]?(\d+)$/			# (B, I) n..m
! 	s = $1.to_i
! 	e = $2.to_i
! 	if e - s < 0
  #	  raise "[Error] invalid range : #{location}"
! 	  $stderr.puts "[Warning] invalid range : #{location}" if $DEBUG
! 	end
        when /^[<>]?(\d+)\^[<>]?(\d+)$/			# (C, I) n^m
! 	s = $1.to_i
! 	e = $2.to_i
! 	if e - s != 1
  #	  raise "[Error] invalid range : #{location}"
! 	  $stderr.puts "[Warning] invalid range : #{location}" if $DEBUG
! 	end
        when /^"?([ATGCatgc]+)"?$/			# (H) literal sequence
! 	sequence = $1.downcase
! 	s = e = nil
        when nil
! 	;
        else
! 	raise "[Error] unknown location format : #{location}"
        end
  
--- 44,69 ----
        case location
        when /^[<>]?(\d+)$/				# (A, I) n
!         s = e = $1.to_i
        when /^[<>]?(\d+)\.\.[<>]?(\d+)$/			# (B, I) n..m
!         s = $1.to_i
!         e = $2.to_i
!         if e - s < 0
  #	  raise "[Error] invalid range : #{location}"
!           $stderr.puts "[Warning] invalid range : #{location}" if $DEBUG
!         end
        when /^[<>]?(\d+)\^[<>]?(\d+)$/			# (C, I) n^m
!         s = $1.to_i
!         e = $2.to_i
!         if e - s != 1
  #	  raise "[Error] invalid range : #{location}"
!           $stderr.puts "[Warning] invalid range : #{location}" if $DEBUG
!         end
        when /^"?([ATGCatgc]+)"?$/			# (H) literal sequence
!         sequence = $1.downcase
!         s = e = nil
        when nil
!         ;
        else
!         raise "[Error] unknown location format : #{location}"
        end
  
***************
*** 71,75 ****
        @to	= e		# end position of the location
        @strand	= 1		# strand direction of the location
! 				#   forward => 1 or complement => -1
        @sequence	= sequence	# literal sequence of the location
        @lt	= lt		# true if the position contains '<'
--- 71,75 ----
        @to	= e		# end position of the location
        @strand	= 1		# strand direction of the location
!                                 #   forward => 1 or complement => -1
        @sequence	= sequence	# literal sequence of the location
        @lt	= lt		# true if the position contains '<'
***************
*** 105,112 ****
      def initialize(position)
        if position.is_a? Array
! 	@locations = position
        else
! 	position   = gbl_cleanup(position)	# preprocessing
! 	@locations = gbl_pos2loc(position)	# create an Array of Location
        end
      end
--- 105,112 ----
      def initialize(position)
        if position.is_a? Array
!         @locations = position
        else
!         position   = gbl_cleanup(position)	# preprocessing
!         @locations = gbl_pos2loc(position)	# create an Array of Location
        end
      end
***************
*** 115,119 ****
      def each
        @locations.each do |x|
! 	yield(x)
        end
      end
--- 115,119 ----
      def each
        @locations.each do |x|
!         yield(x)
        end
      end
***************
*** 145,153 ****
        len = 0
        @locations.each do |x|
! 	if x.sequence
! 	  len += x.sequence.size
! 	else
! 	  len += (x.to - x.from + 1)
! 	end
        end
        len
--- 145,153 ----
        len = 0
        @locations.each do |x|
!         if x.sequence
!           len += x.sequence.size
!         else
!           len += (x.to - x.from + 1)
!         end
        end
        len
***************
*** 158,170 ****
        case type
        when :location
! 	;
        when :aa
! 	if n = abs2rel(n)
! 	  (n - 1) / 3 + 1
! 	else
! 	  nil
! 	end
        else
! 	abs2rel(n)
        end
      end
--- 158,170 ----
        case type
        when :location
!         ;
        when :aa
!         if n = abs2rel(n)
!           (n - 1) / 3 + 1
!         else
!           nil
!         end
        else
!         abs2rel(n)
        end
      end
***************
*** 173,182 ****
        case type
        when :location
! 	;
        when :aa
! 	n = (n - 1) * 3 + 1
! 	rel2abs(n)
        else
! 	rel2abs(n)
        end
      end
--- 173,182 ----
        case type
        when :location
!         ;
        when :aa
!         n = (n - 1) * 3 + 1
!         rel2abs(n)
        else
!         rel2abs(n)
        end
      end
***************
*** 195,203 ****
        #     <match>   $1       ( $2         $3       not   )
        position.gsub!(/(\.{2})?\(?([<>\d]+)\.([<>\d]+)(?!:)\)?/) do |match|
! 	if $1
! 	  $1 + $3			# ..(n.m)  => ..m
! 	else
! 	  $2				# (?n.m)?  => n
! 	end
        end
  
--- 195,203 ----
        #     <match>   $1       ( $2         $3       not   )
        position.gsub!(/(\.{2})?\(?([<>\d]+)\.([<>\d]+)(?!:)\)?/) do |match|
!         if $1
!           $1 + $3			# ..(n.m)  => ..m
!         else
!           $2				# (?n.m)?  => n
!         end
        end
  
***************
*** 205,213 ****
        #     <match>   ..      one-of ($2     ,$3      )
        position.gsub!(/(\.{2})?one-of\(([^,]+),([^)]+)\)/) do |match|
! 	if $1
! 	  $1 + $3.gsub(/.*,(.*)/, '\1')	# ..one-of(n,m)  => ..m
! 	else
! 	  $2				# one-of(n,m)    => n
! 	end
        end
  
--- 205,213 ----
        #     <match>   ..      one-of ($2     ,$3      )
        position.gsub!(/(\.{2})?one-of\(([^,]+),([^)]+)\)/) do |match|
!         if $1
!           $1 + $3.gsub(/.*,(.*)/, '\1')	# ..one-of(n,m)  => ..m
!         else
!           $2				# one-of(n,m)    => n
!         end
        end
  
***************
*** 226,274 ****
  
        when /^join\((.*)\)$/				# (F) join()
! 	position = $1
  
! 	join_list = []		# sub positions to join
! 	bracket   = []		# position with bracket
! 	s_count   = 0		# stack counter
  
! 	position.split(',').each do |sub_pos|
! 	  case sub_pos
! 	  when /\(.*\)/
! 	    join_list << sub_pos
! 	  when /\(/
! 	    s_count += 1
! 	    bracket << sub_pos
! 	  when /\)/
! 	    s_count -= 1
! 	    bracket << sub_pos
! 	    if s_count == 0
! 	      join_list << bracket.join(',')
! 	    end
! 	  else
! 	    if s_count == 0
! 	      join_list << sub_pos
! 	    else
! 	      bracket << sub_pos
! 	    end
! 	  end
! 	end
  
! 	join_list.each do |position|
! 	  ary << gbl_pos2loc(position)
! 	end
  
        when /^complement\((.*)\)$/			# (J) complement()
! 	position =       $1
! 	gbl_pos2loc(position).reverse_each do |location|
! 	  ary << location.complement
! 	end
  
        when /^replace\(([^,]+),"?([^"]*)"?\)/		# (K) replace()
! 	position =    $1
! 	sequence =              $2
! 	ary << gbl_pos2loc(position).first.replace(sequence)
  
        else						# (A, B, C, G, H, I)
! 	ary << Location.new(position)
  
        end
--- 226,274 ----
  
        when /^join\((.*)\)$/				# (F) join()
!         position = $1
  
!         join_list = []		# sub positions to join
!         bracket   = []		# position with bracket
!         s_count   = 0		# stack counter
  
!         position.split(',').each do |sub_pos|
!           case sub_pos
!           when /\(.*\)/
!             join_list << sub_pos
!           when /\(/
!             s_count += 1
!             bracket << sub_pos
!           when /\)/
!             s_count -= 1
!             bracket << sub_pos
!             if s_count == 0
!               join_list << bracket.join(',')
!             end
!           else
!             if s_count == 0
!               join_list << sub_pos
!             else
!               bracket << sub_pos
!             end
!           end
!         end
  
!         join_list.each do |position|
!           ary << gbl_pos2loc(position)
!         end
  
        when /^complement\((.*)\)$/			# (J) complement()
!         position =       $1
!         gbl_pos2loc(position).reverse_each do |location|
!           ary << location.complement
!         end
  
        when /^replace\(([^,]+),"?([^"]*)"?\)/		# (K) replace()
!         position =    $1
!         sequence =              $2
!         ary << gbl_pos2loc(position).first.replace(sequence)
  
        else						# (A, B, C, G, H, I)
!         ary << Location.new(position)
  
        end
***************
*** 306,323 ****
        cursor = 0
        @locations.each do |x|
! 	if x.sequence
! 	  len = x.sequence.size
! 	else
! 	  len = x.to - x.from + 1
! 	end
! 	if n < x.from or n > x.to then
! 	  cursor += len
! 	else
! 	  if x.strand < 0 then
! 	    return x.to - (n - cursor - 1)
! 	  else
! 	    return n + cursor + 1 - x.from
! 	  end
! 	end
        end
        return nil				# out of range
--- 306,323 ----
        cursor = 0
        @locations.each do |x|
!         if x.sequence
!           len = x.sequence.size
!         else
!           len = x.to - x.from + 1
!         end
!         if n < x.from or n > x.to then
!           cursor += len
!         else
!           if x.strand < 0 then
!             return x.to - (n - cursor - 1)
!           else
!             return n + cursor + 1 - x.from
!           end
!         end
        end
        return nil				# out of range

Index: pathway.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/pathway.rb,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** pathway.rb	29 Jan 2004 01:29:15 -0000	1.29
--- pathway.rb	8 Sep 2005 01:22:08 -0000	1.30
***************
*** 50,55 ****
      def directed
        if undirected?
! 	@undirected = false
! 	self.to_list
        end
      end
--- 50,55 ----
      def directed
        if undirected?
!         @undirected = false
!         self.to_list
        end
      end
***************
*** 57,62 ****
      def undirected
        if directed?
! 	@undirected = true
! 	self.to_list
        end
      end
--- 57,62 ----
      def undirected
        if directed?
!         @undirected = true
!         self.to_list
        end
      end
***************
*** 83,87 ****
        @graph.clear
        @relations.each do |rel|
! 	append(rel, false)	# append to @graph without push to @relations
        end
      end
--- 83,87 ----
        @graph.clear
        @relations.each do |rel|
!         append(rel, false)	# append to @graph without push to @relations
        end
      end
***************
*** 90,97 ****
        @relations.push(rel) if add_rel
        if @graph[rel.from].nil?
! 	@graph[rel.from] = {}
        end
        if @graph[rel.to].nil?
! 	@graph[rel.to] = {}
        end
        @graph[rel.from][rel.to] = rel.relation
--- 90,97 ----
        @relations.push(rel) if add_rel
        if @graph[rel.from].nil?
!         @graph[rel.from] = {}
        end
        if @graph[rel.to].nil?
!         @graph[rel.to] = {}
        end
        @graph[rel.from][rel.to] = rel.relation
***************
*** 101,105 ****
      def delete(rel)
        @relations.delete_if do |x|
! 	x === rel
        end
        @graph[rel.from].delete(rel.to)
--- 101,105 ----
      def delete(rel)
        @relations.delete_if do |x|
!         x === rel
        end
        @graph[rel.from].delete(rel.to)
***************
*** 114,118 ****
        edges = 0
        @graph.each_value do |v|
! 	edges += v.size
        end
        edges
--- 114,118 ----
        edges = 0
        @graph.each_value do |v|
!         edges += v.size
        end
        edges
***************
*** 132,164 ****
        matrix = Array.new
        nodes.times do
! 	matrix.push(Array.new(nodes, default_value))
        end
  
        if diagonal_value
! 	nodes.times do |i|
! 	  matrix[i][i] = diagonal_value
! 	end
        end
  
        # assign index number for each node
        @graph.keys.each_with_index do |k, i|
! 	@index[k] = i
        end
  
        if @relations.empty?		# only used after clear_relations!
! 	@graph.each do |from, hash|
! 	  hash.each do |to, relation|
! 	    x = @index[from]
! 	    y = @index[to]
! 	    matrix[x][y] = relation
! 	  end
! 	end
        else
! 	@relations.each do |rel|
! 	  x = @index[rel.from]
! 	  y = @index[rel.to]
! 	  matrix[x][y] = rel.relation
! 	  matrix[y][x] = rel.relation if @undirected
! 	end
        end
        Matrix[*matrix]
--- 132,164 ----
        matrix = Array.new
        nodes.times do
!         matrix.push(Array.new(nodes, default_value))
        end
  
        if diagonal_value
!         nodes.times do |i|
!           matrix[i][i] = diagonal_value
!         end
        end
  
        # assign index number for each node
        @graph.keys.each_with_index do |k, i|
!         @index[k] = i
        end
  
        if @relations.empty?		# only used after clear_relations!
!         @graph.each do |from, hash|
!           hash.each do |to, relation|
!             x = @index[from]
!             y = @index[to]
!             matrix[x][y] = relation
!           end
!         end
        else
!         @relations.each do |rel|
!           x = @index[rel.from]
!           y = @index[rel.to]
!           matrix[x][y] = rel.relation
!           matrix[y][x] = rel.relation if @undirected
!         end
        end
        Matrix[*matrix]
***************
*** 171,175 ****
        sorted = @index.sort {|a,b| a[1] <=> b[1]}
        "[# " + sorted.collect{|x| x[0]}.join(", ") + "\n" +
! 	matrix.to_a.collect{|row| ' ' + row.inspect}.join(",\n") + "\n]"
      end
  
--- 171,175 ----
        sorted = @index.sort {|a,b| a[1] <=> b[1]}
        "[# " + sorted.collect{|x| x[0]}.join(", ") + "\n" +
!         matrix.to_a.collect{|row| ' ' + row.inspect}.join(",\n") + "\n]"
      end
  
***************
*** 178,187 ****
        list = ""
        @graph.each do |from, hash|
! 	list << "#{from} => "
! 	a = []
! 	hash.each do |to, relation|
! 	  a.push("#{to} (#{relation})")
! 	end
! 	list << a.join(", ") + "\n"
        end
        list
--- 178,187 ----
        list = ""
        @graph.each do |from, hash|
!         list << "#{from} => "
!         a = []
!         hash.each do |to, relation|
!           a.push("#{to} (#{relation})")
!         end
!         list << a.join(", ") + "\n"
        end
        list
***************
*** 192,207 ****
      def subgraph(list = nil)
        if list
! 	@label.clear
! 	list.each do |node|
! 	  @label[node] = true
! 	end
        end
        sub_graph = Pathway.new([], @undirected)
        @graph.each do |from, hash|
! 	next unless @label[from]
! 	hash.each do |to, relation|
! 	  next unless @label[to]
! 	  sub_graph.append(Relation.new(from, to, relation))
! 	end
        end
        return sub_graph
--- 192,207 ----
      def subgraph(list = nil)
        if list
!         @label.clear
!         list.each do |node|
!           @label[node] = true
!         end
        end
        sub_graph = Pathway.new([], @undirected)
        @graph.each do |from, hash|
!         next unless @label[from]
!         hash.each do |to, relation|
!           next unless @label[to]
!           sub_graph.append(Relation.new(from, to, relation))
!         end
        end
        return sub_graph
***************
*** 238,242 ****
        freq = Hash.new(0)
        @graph.each_value do |v|
! 	freq[v.size] += 1
        end
        return freq
--- 238,242 ----
        freq = Hash.new(0)
        @graph.each_value do |v|
!         freq[v.size] += 1
        end
        return freq
***************
*** 258,270 ****
  
        while from = queue.shift
! 	next unless @graph[from]
! 	@graph[from].each_key do |to|
! 	  unless visited[to]
! 	    visited[to] = true
! 	    distance[to] = distance[from] + 1
! 	    predecessor[to] = from
! 	    queue.push(to)
! 	  end
! 	end
        end
        return distance, predecessor
--- 258,270 ----
  
        while from = queue.shift
!         next unless @graph[from]
!         @graph[from].each_key do |to|
!           unless visited[to]
!             visited[to] = true
!             distance[to] = distance[from] + 1
!             predecessor[to] = from
!             queue.push(to)
!           end
!         end
        end
        return distance, predecessor
***************
*** 279,284 ****
        path = [ node2 ]
        while node != node1 and route[node]
! 	node = route[node]
! 	path.unshift(node)
        end
        return step, path
--- 279,284 ----
        path = [ node2 ]
        while node != node1 and route[node]
!         node = route[node]
!         path.unshift(node)
        end
        return step, path
***************
*** 298,334 ****
  
        dfs_visit = Proc.new { |from|
! 	visited[from] = true
! 	timestamp[from] = [count += 1]
! 	@graph[from].each_key do |to|
! 	  if visited[to]
! 	    if timestamp[to].size > 1
! 	      if timestamp[from].first < timestamp[to].first
! 		# forward edge (black)
! 		p "#{from} -> #{to} : forward edge" if $DEBUG
! 		forward_edges[from] = to
! 	      else
! 		# cross edge (black)
! 		p "#{from} -> #{to} : cross edge" if $DEBUG
! 		cross_edges[from] = to
! 	      end
! 	    else
! 	      # back edge (gray)
! 	      p "#{from} -> #{to} : back edge" if $DEBUG
! 	      back_edges[from] = to
! 	    end
! 	  else
! 	    # tree edge (white)
! 	    p "#{from} -> #{to} : tree edge" if $DEBUG
! 	    tree_edges[to] = from
! 	    dfs_visit.call(to)
! 	  end
! 	end
! 	timestamp[from].push(count += 1)
        }
  
        @graph.each_key do |node|
! 	unless visited[node]
! 	  dfs_visit.call(node)
! 	end
        end
        return timestamp, tree_edges, back_edges, cross_edges, forward_edges
--- 298,334 ----
  
        dfs_visit = Proc.new { |from|
!         visited[from] = true
!         timestamp[from] = [count += 1]
!         @graph[from].each_key do |to|
!           if visited[to]
!             if timestamp[to].size > 1
!               if timestamp[from].first < timestamp[to].first
!                 # forward edge (black)
!                 p "#{from} -> #{to} : forward edge" if $DEBUG
!                 forward_edges[from] = to
!               else
!                 # cross edge (black)
!                 p "#{from} -> #{to} : cross edge" if $DEBUG
!                 cross_edges[from] = to
!               end
!             else
!               # back edge (gray)
!               p "#{from} -> #{to} : back edge" if $DEBUG
!               back_edges[from] = to
!             end
!           else
!             # tree edge (white)
!             p "#{from} -> #{to} : tree edge" if $DEBUG
!             tree_edges[to] = from
!             dfs_visit.call(to)
!           end
!         end
!         timestamp[from].push(count += 1)
        }
  
        @graph.each_key do |node|
!         unless visited[node]
!           dfs_visit.call(node)
!         end
        end
        return timestamp, tree_edges, back_edges, cross_edges, forward_edges
***************
*** 355,362 ****
  
        while queue.size != 0
! 	min = queue.min {|a, b| a[1] <=> b[1]}
! 	u = min[0]		# extranct a node having minimal distance
          @graph[u].each do |k, v|
! 	  # relaxing procedure of root -> 'u' -> 'k'
            if distance[k] > distance[u] + v
              distance[k] = distance[u] + v
--- 355,362 ----
  
        while queue.size != 0
!         min = queue.min {|a, b| a[1] <=> b[1]}
!         u = min[0]		# extranct a node having minimal distance
          @graph[u].each do |k, v|
!           # relaxing procedure of root -> 'u' -> 'k'
            if distance[k] > distance[u] + v
              distance[k] = distance[u] + v
***************
*** 364,368 ****
            end
          end
! 	queue.delete(u)
        end
        return distance, predecessor
--- 364,368 ----
            end
          end
!         queue.delete(u)
        end
        return distance, predecessor
***************
*** 377,381 ****
          @graph.each_key do |u|
            @graph[u].each do |v, w|
! 	    # relaxing procedure of root -> 'u' -> 'v'
              if distance[v] > distance[u] + w
                distance[v] = distance[u] + w
--- 377,381 ----
          @graph.each_key do |u|
            @graph[u].each do |v, w|
!             # relaxing procedure of root -> 'u' -> 'v'
              if distance[v] > distance[u] + w
                distance[v] = distance[u] + w
***************
*** 516,528 ****
      def ===(rel)
        if self.edge == rel.edge
! 	if self.node[0] == rel.node[0] and self.node[1] == rel.node[1]
! 	  return true
! 	elsif self.node[0] == rel.node[1] and self.node[1] == rel.node[0]
! 	  return true
! 	else
! 	  return false
! 	end
        else
! 	return false
        end
      end
--- 516,528 ----
      def ===(rel)
        if self.edge == rel.edge
!         if self.node[0] == rel.node[0] and self.node[1] == rel.node[1]
!           return true
!         elsif self.node[0] == rel.node[1] and self.node[1] == rel.node[0]
!           return true
!         else
!           return false
!         end
        else
!         return false
        end
      end
***************
*** 531,535 ****
      def <=>(rel)
        unless self.edge.kind_of? Comparable
! 	raise "[Error] edges are not comparable"
        end
        if self.edge > rel.edge
--- 531,535 ----
      def <=>(rel)
        unless self.edge.kind_of? Comparable
!         raise "[Error] edges are not comparable"
        end
        if self.edge > rel.edge

Index: alignment.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/alignment.rb,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** alignment.rb	13 Nov 2004 15:41:10 -0000	1.7
--- alignment.rb	8 Sep 2005 01:22:08 -0000	1.8
***************
*** 39,53 ****
        seq = nil
        if seq.is_a?(Bio::Sequence) then
! 	seq = s
        else
! 	for m in [ :seq, :naseq, :aaseq ]
! 	  begin
! 	    seq = s.send(m)
! 	  rescue NameError, ArgumentError
! 	    seq = nil
! 	  end
[...1503 lines suppressed...]
!         p
        end
        module_function :ungapped_pos
  
        def gapped_pos(seq, pos, gap_regexp)
!         olen = seq.gsub(gap_regexp, '').length
!         pos = olen if pos >= olen
!         pos = olen + pos if pos < 0
!         
!         i = 0
!         l = pos + 1
!         while l > 0 and i < seq.length
!           x = seq[i, l].gsub(gap_regexp, '').length
!           i += l
!           l -= x
!         end
!         i -= 1 if i > 0
!         i
        end
        module_function :gapped_pos

Index: sequence.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/sequence.rb,v
retrieving revision 0.40
retrieving revision 0.41
diff -C2 -d -r0.40 -r0.41
*** sequence.rb	10 Aug 2005 12:53:02 -0000	0.40
--- sequence.rb	8 Sep 2005 01:22:08 -0000	0.41
***************
*** 69,75 ****
        ">#{header}\n" +
        if width
! 	self.to_s.gsub(Regexp.new(".{1,#{width}}"), "\\0\n")
        else
! 	self.to_s + "\n"
        end
      end
--- 69,75 ----
        ">#{header}\n" +
        if width
!         self.to_s.gsub(Regexp.new(".{1,#{width}}"), "\\0\n")
        else
!         self.to_s + "\n"
        end
      end
***************
*** 95,101 ****
        sum = 0.0
        self.each_byte do |x|
! 	begin
! 	  sum += hash[x.chr]
! 	end
        end
        return sum
--- 95,101 ----
        sum = 0.0
        self.each_byte do |x|
!         begin
!           sum += hash[x.chr]
!         end
        end
        return sum
***************
*** 105,109 ****
        count = Hash.new(0)
        self.scan(/./) do |x|
! 	count[x] += 1
        end
        return count
--- 105,109 ----
        count = Hash.new(0)
        self.scan(/./) do |x|
!         count[x] += 1
        end
        return count
***************
*** 113,120 ****
        length = self.length
        if hash
! 	count = hash.clone
! 	count.each_value {|x| length += x}
        else
! 	count = self.composition
        end
  
--- 113,120 ----
        length = self.length
        if hash
!         count = hash.clone
!         count.each_value {|x| length += x}
        else
!         count = self.composition
        end
  
***************
*** 122,136 ****
        tmp = {}
        length.times do 
! 	count.each do |k, v|
! 	  tmp[k] = v * rand
! 	end
! 	max = tmp.max {|a, b| a[1] <=> b[1]}
! 	count[max.first] -= 1
  
! 	if block_given?
! 	  yield max.first
! 	else
! 	  seq += max.first
! 	end
        end
        return self.class.new(seq)
--- 122,136 ----
        tmp = {}
        length.times do 
!         count.each do |k, v|
!           tmp[k] = v * rand
!         end
!         max = tmp.max {|a, b| a[1] <=> b[1]}
!         count[max.first] -= 1
  
!         if block_given?
!           yield max.first
!         else
!           seq += max.first
!         end
        end
        return self.class.new(seq)
***************
*** 144,161 ****
      def splicing(position)
        unless position.is_a?(Locations) then
! 	position = Locations.new(position)
        end
        s = ''
        position.each do |location|
! 	if location.sequence
! 	  s << location.sequence
! 	else
! 	  exon = self.subseq(location.from, location.to)
! 	  begin
! 	    exon.complement! if location.strand < 0
! 	  rescue NameError
! 	  end
! 	  s << exon
! 	end
        end
        return self.class.new(s)
--- 144,161 ----
      def splicing(position)
        unless position.is_a?(Locations) then
!         position = Locations.new(position)
        end
        s = ''
        position.each do |location|
!         if location.sequence
!           s << location.sequence
!         else
!           exon = self.subseq(location.from, location.to)
!           begin
!             exon.complement! if location.strand < 0
!           rescue NameError
!           end
!           s << exon
!         end
        end
        return self.class.new(s)
***************
*** 168,239 ****
  
        def initialize(str)
! 	super
! 	self.downcase!
! 	self.tr!(" \t\n\r",'')
        end
  
        # This method depends on Locations class, see bio/location.rb
        def splicing(position)
! 	mRNA = super
! 	if mRNA.rna?
! 	  mRNA.tr!('t', 'u')
! 	else
! 	  mRNA.tr!('u', 't')
! 	end
! 	mRNA
        end
  
        def complement
! 	s = self.class.new(self)
! 	s.complement!
! 	s
        end
  
        def complement!
! 	if self.rna?
! 	  self.reverse!
! 	  self.tr!('augcrymkdhvbswn', 'uacgyrkmhdbvswn')
! 	else
! 	  self.reverse!
! 	  self.tr!('atgcrymkdhvbswn', 'tacgyrkmhdbvswn')
! 	end
! 	self
        end
  
        def translate(frame = 1, table = 1, unknown = 'X')
          if table.is_a?(Bio::CodonTable)
! 	  ct = table
          else
            ct = Bio::CodonTable[table]
          end
! 	naseq = self.dna
! 	case frame
! 	when 1, 2, 3
! 	  frame -= 1
! 	when 4, 5, 6
! 	  frame -= 4
! 	  naseq.complement!
! 	when -1, -2, -3
! 	  frame = -1 - frame
! 	  naseq.complement!
! 	else
! 	  frame = 0
! 	end
          nalen = naseq.length - (naseq.length - frame) % 3
! 	aaseq = naseq[frame, nalen].gsub(/.{3}/) {|codon| ct[codon] or unknown}
! 	return Bio::Sequence::AA.new(aaseq)
        end
  
        def gc_percent
! 	count = self.composition
! 	at = count['a'] + count['t'] + count['u']
! 	gc = count['g'] + count['c']
! 	gc = format("%.1f", gc.to_f / (at + gc) * 100)
! 	return gc.to_f
        end
        alias :gc :gc_percent
  
        def illegal_bases
! 	self.scan(/[^atgcu]/).sort.uniq
        end
  
--- 168,239 ----
  
        def initialize(str)
!         super
!         self.downcase!
!         self.tr!(" \t\n\r",'')
        end
  
        # This method depends on Locations class, see bio/location.rb
        def splicing(position)
!         mRNA = super
!         if mRNA.rna?
!           mRNA.tr!('t', 'u')
!         else
!           mRNA.tr!('u', 't')
!         end
!         mRNA
        end
  
        def complement
!         s = self.class.new(self)
!         s.complement!
!         s
        end
  
        def complement!
!         if self.rna?
!           self.reverse!
!           self.tr!('augcrymkdhvbswn', 'uacgyrkmhdbvswn')
!         else
!           self.reverse!
!           self.tr!('atgcrymkdhvbswn', 'tacgyrkmhdbvswn')
!         end
!         self
        end
  
        def translate(frame = 1, table = 1, unknown = 'X')
          if table.is_a?(Bio::CodonTable)
!           ct = table
          else
            ct = Bio::CodonTable[table]
          end
!         naseq = self.dna
!         case frame
!         when 1, 2, 3
!           frame -= 1
!         when 4, 5, 6
!           frame -= 4
!           naseq.complement!
!         when -1, -2, -3
!           frame = -1 - frame
!           naseq.complement!
!         else
!           frame = 0
!         end
          nalen = naseq.length - (naseq.length - frame) % 3
!         aaseq = naseq[frame, nalen].gsub(/.{3}/) {|codon| ct[codon] or unknown}
!         return Bio::Sequence::AA.new(aaseq)
        end
  
        def gc_percent
!         count = self.composition
!         at = count['a'] + count['t'] + count['u']
!         gc = count['g'] + count['c']
!         gc = format("%.1f", gc.to_f / (at + gc) * 100)
!         return gc.to_f
        end
        alias :gc :gc_percent
  
        def illegal_bases
!         self.scan(/[^atgcu]/).sort.uniq
        end
  
***************
*** 248,252 ****
  
        def to_re
! 	if self.rna?
            NucleicAcid.to_re(self.dna, true)
          else
--- 248,252 ----
  
        def to_re
!         if self.rna?
            NucleicAcid.to_re(self.dna, true)
          else
***************
*** 256,264 ****
  
        def names
! 	array = []
! 	self.each_byte do |x|
! 	  array.push(NucleicAcid.names[x.chr.upcase])
! 	end
! 	return array
        end
  
--- 256,264 ----
  
        def names
!         array = []
!         self.each_byte do |x|
!           array.push(NucleicAcid.names[x.chr.upcase])
!         end
!         return array
        end
  
***************
*** 280,289 ****
  
        def rna?
! 	self.index('u')
        end
        protected :rna?
  
        def pikachu
! 	self.dna.tr("atgc", "pika")	# joke, of course :-)
        end
  
--- 280,289 ----
  
        def rna?
!         self.index('u')
        end
        protected :rna?
  
        def pikachu
!         self.dna.tr("atgc", "pika")	# joke, of course :-)
        end
  
***************
*** 296,302 ****
  
        def initialize(str)
! 	super
! 	self.upcase!
! 	self.tr!(" \t\n\r",'')
        end
  
--- 296,302 ----
  
        def initialize(str)
!         super
!         self.upcase!
!         self.tr!(" \t\n\r",'')
        end
  
***************
*** 307,325 ****
  
        def to_re
! 	AminoAcid.to_re(self)
        end
  
        def codes
! 	array = []
! 	self.each_byte do |x|
! 	  array.push(AminoAcid.names[x.chr])
! 	end
! 	return array
        end
  
        def names
! 	self.codes.map do |x|
! 	  AminoAcid.names[x]
! 	end
        end
  
--- 307,325 ----
  
        def to_re
!         AminoAcid.to_re(self)
        end
  
        def codes
!         array = []
!         self.each_byte do |x|
!           array.push(AminoAcid.names[x.chr])
!         end
!         return array
        end
  
        def names
!         self.codes.map do |x|
!           AminoAcid.names[x]
!         end
        end
  

Index: db.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db.rb,v
retrieving revision 0.27
retrieving revision 0.28
diff -C2 -d -r0.27 -r0.28
*** db.rb	7 Aug 2005 08:26:38 -0000	0.27
--- db.rb	8 Sep 2005 01:22:08 -0000	0.28
***************
*** 72,76 ****
      def field_fetch(tag, skip = 0)
        unless @data[tag]
! 	@data[tag] = fetch(tag, skip)
        end
        return @data[tag]
--- 72,76 ----
      def field_fetch(tag, skip = 0)
        unless @data[tag]
!         @data[tag] = fetch(tag, skip)
        end
        return @data[tag]
***************
*** 114,119 ****
  
        fields.each do |field|
! 	tag = tag_get(field)
! 	hash[tag] += field
        end
        return hash
--- 114,119 ----
  
        fields.each do |field|
!         tag = tag_get(field)
!         hash[tag] += field
        end
        return hash
***************
*** 141,148 ****
        hash = Hash.new('')
        entry.each_line do |line|
! 	tag = tag_get(line)
! 	next if tag == 'XX'
! 	tag = 'R' if tag =~ /^R./	# Reference lines
! 	hash[tag] += line
        end
        return hash
--- 141,148 ----
        hash = Hash.new('')
        entry.each_line do |line|
!         tag = tag_get(line)
!         next if tag == 'XX'
!         tag = 'R' if tag =~ /^R./	# Reference lines
!         hash[tag] += line
        end
        return hash

Index: feature.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/feature.rb,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** feature.rb	25 Feb 2003 12:22:00 -0000	1.5
--- feature.rb	8 Sep 2005 01:22:08 -0000	1.6
***************
*** 43,47 ****
      def each
        @qualifiers.each do |x|
! 	yield x
        end
      end
--- 43,47 ----
      def each
        @qualifiers.each do |x|
!         yield x
        end
      end
***************
*** 59,63 ****
  
        def initialize(key, value)
! 	@qualifier, @value = key, value
        end
        attr_reader :qualifier, :value
--- 59,63 ----
  
        def initialize(key, value)
!         @qualifier, @value = key, value
        end
        attr_reader :qualifier, :value
***************
*** 82,87 ****
      def each(arg = nil)
        @features.each do |x|
! 	next if arg and x.feature != arg
! 	yield x
        end
      end
--- 82,87 ----
      def each(arg = nil)
        @features.each do |x|
!         next if arg and x.feature != arg
!         yield x
        end
      end

Index: reference.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/reference.rb,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** reference.rb	26 May 2005 13:16:23 -0000	1.16
--- reference.rb	8 Sep 2005 01:22:08 -0000	1.17
***************
*** 52,78 ****
          return endnote
        when 'bibitem'
! 	return bibitem(option)
        when 'bibtex'
! 	return bibtex(option)
        when 'rd'
! 	return rd(option)
        when /^nature$/i
! 	return nature(option)
        when /^science$/i
! 	return science
        when /^genome\s*_*biol/i
! 	return genome_biol
        when /^genome\s*_*res/i
! 	return genome_res
        when /^nar$/i
! 	return nar
        when /^current/i
! 	return current
        when /^trends/i
! 	return trends
        when /^cell$/i
! 	return cell
        else
! 	return general
        end
      end
--- 52,78 ----
          return endnote
        when 'bibitem'
!         return bibitem(option)
        when 'bibtex'
!         return bibtex(option)
        when 'rd'
!         return rd(option)
        when /^nature$/i
!         return nature(option)
        when /^science$/i
!         return science
        when /^genome\s*_*biol/i
!         return genome_biol
        when /^genome\s*_*res/i
!         return genome_res
        when /^nar$/i
!         return nar
        when /^current/i
!         return current
        when /^trends/i
!         return trends
        when /^cell$/i
!         return cell
        else
!         return general
        end
      end
***************
*** 109,116 ****
        pages = @pages.sub('-', '--')
        return <<-"END".collect {|line| line.strip}.join("\n")
! 	\\bibitem{#{item}}
! 	#{@authors.join(', ')}
! 	#{@title},
! 	{\\em #{@journal}}, #{@volume}(#{@issue}):#{pages}, #{@year}.
        END
      end
--- 109,116 ----
        pages = @pages.sub('-', '--')
        return <<-"END".collect {|line| line.strip}.join("\n")
!         \\bibitem{#{item}}
!         #{@authors.join(', ')}
!         #{@title},
!         {\\em #{@journal}}, #{@volume}(#{@issue}):#{pages}, #{@year}.
        END
      end
***************
*** 121,133 ****
        pages   = @pages.sub('-', '--')
        return <<-"END".gsub(/\t/, '')
! 	@#{section}{PMID:#{@pubmed},
! 	  author  = {#{authors}},
! 	  title   = {#{@title}},
! 	  journal = {#{@journal}},
! 	  year    = {#{@year}},
! 	  volume  = {#{@volume}},
! 	  number  = {#{@issue}},
! 	  pages   = {#{pages}},
! 	}
        END
      end
--- 121,133 ----
        pages   = @pages.sub('-', '--')
        return <<-"END".gsub(/\t/, '')
!         @#{section}{PMID:#{@pubmed},
!           author  = {#{authors}},
!           title   = {#{@title}},
!           journal = {#{@journal}},
!           year    = {#{@year}},
!           volume  = {#{@volume}},
!           number  = {#{@issue}},
!           pages   = {#{pages}},
!         }
        END
      end
***************
*** 150,164 ****
      def nature(short = false)
        if short
! 	if @authors.size > 4
! 	  authors = "#{@authors[0]} et al."
! 	elsif @authors.size == 1
! 	  authors = "#{@authors[0]}"
! 	else
! 	  authors = authors_join(' & ')
! 	end
! 	"#{authors} #{@journal} #{@volume}, #{@pages} (#{@year})."
        else
! 	authors = authors_join(' & ')
! 	"#{authors} #{@title} #{@journal} #{@volume}, #{@pages} (#{@year})."
        end
      end
--- 150,164 ----
      def nature(short = false)
        if short
!         if @authors.size > 4
!           authors = "#{@authors[0]} et al."
!         elsif @authors.size == 1
!           authors = "#{@authors[0]}"
!         else
!           authors = authors_join(' & ')
!         end
!         "#{authors} #{@journal} #{@volume}, #{@pages} (#{@year})."
        else
!         authors = authors_join(' & ')
!         "#{authors} #{@title} #{@journal} #{@volume}, #{@pages} (#{@year})."
        end
      end
***************
*** 166,172 ****
      def science
        if @authors.size > 4
! 	authors = rev_name(@authors[0]) + " et al."
        else
! 	authors = @authors.collect {|name| rev_name(name)}.join(', ')
        end
        page_from, = @pages.split('-')
--- 166,172 ----
      def science
        if @authors.size > 4
!         authors = rev_name(@authors[0]) + " et al."
        else
!         authors = @authors.collect {|name| rev_name(name)}.join(', ')
        end
        page_from, = @pages.split('-')
***************
*** 198,206 ****
      def trends
        if @authors.size > 2
! 	authors = "#{@authors[0]} et al."
        elsif @authors.size == 1
! 	authors = "#{@authors[0]}"
        else
! 	authors = authors_join(' and ')
        end
        "#{authors} (#{@year}) #{@title} #{@journal} #{@volume}, #{@pages}"
--- 198,206 ----
      def trends
        if @authors.size > 2
!         authors = "#{@authors[0]} et al."
        elsif @authors.size == 1
!         authors = "#{@authors[0]}"
        else
!         authors = authors_join(' and ')
        end
        "#{authors} (#{@year}) #{@title} #{@journal} #{@volume}, #{@pages}"
***************
*** 217,226 ****
        authors = @authors.clone
        if authors.length > 1
! 	last = authors.pop
! 	authors = authors.join(sep) + "#{amp}" + last
        elsif authors.length == 1
! 	authors = authors.pop
        else
! 	authors = ""
        end
      end
--- 217,226 ----
        authors = @authors.clone
        if authors.length > 1
!         last = authors.pop
!         authors = authors.join(sep) + "#{amp}" + last
        elsif authors.length == 1
!         authors = authors.pop
        else
!         authors = ""
        end
      end
***************
*** 228,233 ****
      def rev_name(name)
        if name =~ /,/
! 	name, initial = name.split(/,\s+/)
! 	name = "#{initial} #{name}"
        end
        return name
--- 228,233 ----
      def rev_name(name)
        if name =~ /,/
!         name, initial = name.split(/,\s+/)
!         name = "#{initial} #{name}"
        end
        return name
***************
*** 251,255 ****
      def each
        @references.each do |x|
! 	yield x
        end
      end
--- 251,255 ----
      def each
        @references.each do |x|
!         yield x
        end
      end



More information about the bioruby-cvs mailing list