def set
time0 = Time.new.strftime("%Y-%m-%d %X")
- File.open(path, mode="w") { |file| file.puts [time0, ARGV.join(" ")].join(";") }
+ File.open(path, mode="w") do |fh|
+ fh.puts [time0, ARGV.join(" ")].join(";")
+ end
end
# Append the a temporary directory path to the status file.
- def set_tmpdir(tmp_path)
- status = File.open(path, mode="r").read.chomp
+ def set_tmpdir(tmpdir_path)
+ File.open(path, mode="r") do |fh|
+ fh.read.chomp
+ end
File.open(path, mode="w") do |fh|
- fh << [status, tmp_path].join(";") + "\n"
+ fh << [status, tmpdir_path].join(";") + "\n"
end
end
# Extract the temporary directory path from the status file,
# and return this or nil if not found.
def get_tmpdir
- tmp_path = File.open(path, mode="r").read.chomp.split(";").last
+ File.open(path, mode="r") do |fh|
+ tmpdir_path = fh.read.chomp.split(";").last
+ return tmpdir_path if File.directory?(tmpdir_path)
+ end
- File.directory?(tmp_path) ? tmp_path : nil
+ nil
end
# Write the Biopiece status to the log file.
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 19</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 43</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">test</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">input</span>=<span class="ruby-constant">STDIN</span>, <span class="ruby-identifier">output</span>=<span class="ruby-constant">STDOUT</span>)
<span class="ruby-ivar">@test</span> = <span class="ruby-identifier">test</span>
<span class="ruby-ivar">@input</span> = <span class="ruby-identifier">input</span>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 30</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 54</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">argv</span>, <span class="ruby-identifier">cast_list</span>=[], <span class="ruby-identifier">script_path</span>=<span class="ruby-identifier">$0</span>)
<span class="ruby-identifier">casts</span> = <span class="ruby-constant">Casts</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">cast_list</span>)
<span class="ruby-identifier">option_handler</span> = <span class="ruby-constant">OptionHandler</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">argv</span>, <span class="ruby-identifier">casts</span>, <span class="ruby-identifier">script_path</span>, <span class="ruby-ivar">@test</span>)
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 38</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 62</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each_record</span>
<span class="ruby-ivar">@in</span> = <span class="ruby-constant">Stream</span><span class="ruby-operator">::</span><span class="ruby-identifier">open</span>(<span class="ruby-ivar">@options</span>, <span class="ruby-identifier">mode</span>=<span class="ruby-value str">"r"</span>, <span class="ruby-ivar">@input</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@in</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">IO</span>
+ <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@in</span>.<span class="ruby-identifier">nil?</span>
<span class="ruby-identifier">record</span> = {}
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 63</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 88</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">puts</span>(<span class="ruby-identifier">record</span>)
<span class="ruby-ivar">@out</span> = <span class="ruby-constant">Stream</span><span class="ruby-operator">::</span><span class="ruby-identifier">open</span>(<span class="ruby-ivar">@options</span>, <span class="ruby-identifier">mode</span>=<span class="ruby-value str">"w"</span>, <span class="ruby-ivar">@output</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@out</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">IO</span>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 74</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 99</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mktmpdir</span>
<span class="ruby-identifier">time</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">to_i</span>
<span class="ruby-identifier">user</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">"USER"</span>]
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 100</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 125</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">cast_list</span>=[])
<span class="ruby-ivar">@cast_list</span> = <span class="ruby-identifier">cast_list</span>
<span class="ruby-identifier">ubiquitous</span>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 225</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 250</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">argv</span>, <span class="ruby-identifier">casts</span>, <span class="ruby-identifier">script_path</span>, <span class="ruby-identifier">test</span>=<span class="ruby-keyword kw">nil</span>)
<span class="ruby-ivar">@argv</span> = <span class="ruby-identifier">argv</span>
<span class="ruby-ivar">@casts</span> = <span class="ruby-identifier">casts</span>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 235</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 260</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_parse</span>
<span class="ruby-ivar">@options</span> = {}
<span class="ruby-identifier">option_parser</span> = <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">option</span><span class="ruby-operator">|</span>
<span class="ruby-ivar">@casts</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">cast</span><span class="ruby-operator">|</span>
- <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:type</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'flag'</span>
+ <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:type</span>]
+ <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'flag'</span>
<span class="ruby-identifier">option</span>.<span class="ruby-identifier">on</span>(<span class="ruby-node">"-#{cast[:short]}"</span>, <span class="ruby-node">"--#{cast[:long]}"</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]] = <span class="ruby-identifier">o</span>
<span class="ruby-keyword kw">end</span>
- <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:type</span>] <span class="ruby-operator">=~</span> <span class="ruby-constant">REGEX_LIST</span>
+ <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'float'</span>
+ <span class="ruby-identifier">option</span>.<span class="ruby-identifier">on</span>(<span class="ruby-node">"-#{cast[:short]}"</span>, <span class="ruby-node">"--#{cast[:long]} F"</span>, <span class="ruby-constant">Float</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
+ <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]] = <span class="ruby-identifier">f</span>
+ <span class="ruby-keyword kw">end</span>
+ <span class="ruby-keyword kw">when</span> <span class="ruby-constant">REGEX_LIST</span>
<span class="ruby-identifier">option</span>.<span class="ruby-identifier">on</span>( <span class="ruby-node">"-#{cast[:short]}"</span>, <span class="ruby-node">"--#{cast[:long]} A"</span>, <span class="ruby-constant">Array</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span>
<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]] = <span class="ruby-identifier">a</span>
<span class="ruby-keyword kw">end</span>
- <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:type</span>] <span class="ruby-operator">=~</span> <span class="ruby-constant">REGEX_INT</span>
+ <span class="ruby-keyword kw">when</span> <span class="ruby-constant">REGEX_INT</span>
<span class="ruby-identifier">option</span>.<span class="ruby-identifier">on</span>(<span class="ruby-node">"-#{cast[:short]}"</span>, <span class="ruby-node">"--#{cast[:long]} I"</span>, <span class="ruby-constant">Integer</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]] = <span class="ruby-identifier">i</span>
<span class="ruby-keyword kw">end</span>
- <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:type</span>] <span class="ruby-operator">=~</span> <span class="ruby-constant">REGEX_STRING</span>
+ <span class="ruby-keyword kw">when</span> <span class="ruby-constant">REGEX_STRING</span>
<span class="ruby-identifier">option</span>.<span class="ruby-identifier">on</span>(<span class="ruby-node">"-#{cast[:short]}"</span>, <span class="ruby-node">"--#{cast[:long]} S"</span>, <span class="ruby-constant">String</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span>
<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]] = <span class="ruby-identifier">s</span>
<span class="ruby-keyword kw">end</span>
- <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:type</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'float'</span>
- <span class="ruby-identifier">option</span>.<span class="ruby-identifier">on</span>(<span class="ruby-node">"-#{cast[:short]}"</span>, <span class="ruby-node">"--#{cast[:long]} F"</span>, <span class="ruby-constant">Float</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
- <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]] = <span class="ruby-identifier">f</span>
- <span class="ruby-keyword kw">end</span>
<span class="ruby-keyword kw">else</span>
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"Unknown option type: '#{cast[:type]}'"</span>
<span class="ruby-keyword kw">end</span>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 282</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 308</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wiki_path</span>
<span class="ruby-identifier">path</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">"BP_DIR"</span>] <span class="ruby-operator">+</span> <span class="ruby-value str">"/bp_usage/"</span> <span class="ruby-operator">+</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-ivar">@script_path</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">".wiki"</span>
<span class="ruby-identifier">raise</span> <span class="ruby-node">"No such wiki file: #{path}"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">file?</span> <span class="ruby-identifier">path</span>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 289</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 315</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">print_usage_full?</span>
<span class="ruby-ivar">@options</span>[<span class="ruby-value str">"help"</span>]
<span class="ruby-keyword kw">end</span></pre>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 294</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 320</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">print_usage_short?</span>
<span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">$stdin</span>.<span class="ruby-identifier">tty?</span>
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 311</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 337</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">print_usage_and_exit</span>(<span class="ruby-identifier">full</span>=<span class="ruby-keyword kw">nil</span>)
<span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@test</span>
<span class="ruby-keyword kw">return</span>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 328</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 354</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_default</span>
<span class="ruby-ivar">@casts</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">cast</span><span class="ruby-operator">|</span>
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:default</span>]
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 338</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 364</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_glob</span>
<span class="ruby-ivar">@casts</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">cast</span><span class="ruby-operator">|</span>
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:type</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'files'</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:type</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'files!'</span>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 361</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 387</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_check</span>
<span class="ruby-ivar">@casts</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">cast</span><span class="ruby-operator">|</span>
<span class="ruby-identifier">options_check_mandatory</span>(<span class="ruby-identifier">cast</span>)
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 375</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 401</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_check_mandatory</span>(<span class="ruby-identifier">cast</span>)
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:mandatory</span>]
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"Mandatory argument: --#{cast[:long]}"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 382</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 408</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_check_int</span>(<span class="ruby-identifier">cast</span>)
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:type</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'int'</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]
<span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]].<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Integer</span>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 391</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 417</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_check_uint</span>(<span class="ruby-identifier">cast</span>)
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:type</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'uint'</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]
<span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]].<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Integer</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]] <span class="ruby-operator">>=</span> <span class="ruby-value">0</span>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 400</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 426</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_check_file</span>(<span class="ruby-identifier">cast</span>)
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:type</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'file!'</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"No such file: '#{@options[cast[:long]]}'"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">file?</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]]
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 407</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 433</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_check_files</span>(<span class="ruby-identifier">cast</span>)
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:type</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'files!'</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]
<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 416</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 442</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_check_dir</span>(<span class="ruby-identifier">cast</span>)
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:type</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'dir!'</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"No such directory: '#{@options[cast[:long]]}'"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]]
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 423</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 449</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_check_allowed</span>(<span class="ruby-identifier">cast</span>)
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:allowed</span>] <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]
<span class="ruby-identifier">allowed_hash</span> = {}
- <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:allowed</span>].<span class="ruby-identifier">split</span>(<span class="ruby-value str">','</span>).<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">allowed_hash</span>[<span class="ruby-identifier">a</span>] = <span class="ruby-value">1</span> }
+ <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:allowed</span>].<span class="ruby-identifier">split</span>(<span class="ruby-value str">','</span>).<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">allowed_hash</span>[<span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-value">1</span> }
- <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"Argument '#{@options[cast[:long]]}' to --#{cast[:long]} not allowed"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">allowed_hash</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]]
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"Argument '#{@options[cast[:long]]}' to --#{cast[:long]} not allowed"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">allowed_hash</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]].<span class="ruby-identifier">to_s</span>
<span class="ruby-keyword kw">end</span>
<span class="ruby-keyword kw">end</span></pre>
</body>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 433</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 459</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_check_disallowed</span>(<span class="ruby-identifier">cast</span>)
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:disallowed</span>] <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]
<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:disallowed</span>].<span class="ruby-identifier">split</span>(<span class="ruby-value str">','</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">val</span><span class="ruby-operator">|</span>
- <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"Argument '#{@options[cast[:long]]}' to --#{cast[:long]} is disallowed"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">val</span> <span class="ruby-operator">==</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]]
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"Argument '#{@options[cast[:long]]}' to --#{cast[:long]} is disallowed"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">==</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">cast</span>[<span class="ruby-identifier">:long</span>]].<span class="ruby-identifier">to_s</span>
<span class="ruby-keyword kw">end</span>
<span class="ruby-keyword kw">end</span>
<span class="ruby-keyword kw">end</span></pre>
<td><strong>Parent:</strong></td>
<td>
- String
+ Object
</td>
</tr>
<div id="contextContent">
- <div id="description">
- <p>
-Class containing generic sequence methods and nucleic acid and amino acid
-subclasses.
-</p>
-
- </div>
-
</div>
<div class="name-list">
- <a href="#M000034">generate</a>
+ <a href="#M000043">complement</a>
+
+ <a href="#M000044">generate</a>
+
+ <a href="#M000037">is_dna</a>
+
+ <a href="#M000039">is_protein</a>
+
+ <a href="#M000038">is_rna</a>
- <a href="#M000035">generate!</a>
+ <a href="#M000036">len</a>
- <a href="#M000031">guess_type</a>
+ <a href="#M000035">length</a>
- <a href="#M000032">wrap</a>
+ <a href="#M000042">to_bp</a>
- <a href="#M000033">wrap!</a>
+ <a href="#M000041">to_dna</a>
+
+ <a href="#M000040">to_rna</a>
</div>
</div>
<div id="section">
- <div id="class-list">
- <h3 class="section-bar">Classes and Modules</h3>
- Class <a href="Seq/AA.html" class="link">Seq::AA</a><br />
-Class <a href="Seq/NA.html" class="link">Seq::NA</a><br />
- </div>
+ <div id="attribute-list">
+ <h3 class="section-bar">Attributes</h3>
+
+ <div class="name-list">
+ <table>
+ <tr class="top-aligned-row context-row">
+ <td class="context-item-name">qual</td>
+
+ <td class="context-item-value"> [RW] </td>
+
+ <td class="context-item-desc"></td>
+ </tr>
+ <tr class="top-aligned-row context-row">
+ <td class="context-item-name">seq</td>
+
+ <td class="context-item-value"> [RW] </td>
+
+ <td class="context-item-desc"></td>
+ </tr>
+
+ <tr class="top-aligned-row context-row">
+ <td class="context-item-name">seq_name</td>
+
+ <td class="context-item-value"> [RW] </td>
+
+ <td class="context-item-desc"></td>
+ </tr>
+
+ <tr class="top-aligned-row context-row">
+ <td class="context-item-name">type</td>
+
+ <td class="context-item-value"> [RW] </td>
+
+ <td class="context-item-desc"></td>
+ </tr>
+
+ </table>
+ </div>
+ </div>
<!-- if method_list -->
<h3 class="section-bar">Public Instance methods</h3>
- <div id="method-M000034" class="method-detail">
- <a name="M000034"></a>
+ <div id="method-M000043" class="method-detail">
+ <a name="M000043"></a>
+
+ <div class="method-heading">
+
+ <a href="Seq.src/M000043.html" target="Code" class="method-signature"
+ onclick="popupCode('Seq.src/M000043.html');return false;">
+
+ <span class="method-name">complement</span><span class="method-args">()</span>
+
+ </a>
+
+ </div>
+
+ <div class="method-description">
+
+ <p>
+Method that complements sequence including ambiguity codes.
+</p>
+
+ </div>
+ </div>
+
+
+ <div id="method-M000044" class="method-detail">
+ <a name="M000044"></a>
<div class="method-heading">
- <a href="Seq.src/M000034.html" target="Code" class="method-signature"
- onclick="popupCode('Seq.src/M000034.html');return false;">
+ <a href="Seq.src/M000044.html" target="Code" class="method-signature"
+ onclick="popupCode('Seq.src/M000044.html');return false;">
- <span class="method-name">generate</span><span class="method-args">( length )</span>
+ <span class="method-name">generate</span><span class="method-args">(length,type)</span>
</a>
</div>
+ <div id="method-M000037" class="method-detail">
+ <a name="M000037"></a>
+
+ <div class="method-heading">
+
+ <a href="Seq.src/M000037.html" target="Code" class="method-signature"
+ onclick="popupCode('Seq.src/M000037.html');return false;">
+
+ <span class="method-name">is_dna</span><span class="method-args">()</span>
+
+ </a>
+
+ </div>
+
+ <div class="method-description">
+
+ <p>
+Method that returns true is a given sequence type is DNA.
+</p>
+
+ </div>
+ </div>
+
+
+ <div id="method-M000039" class="method-detail">
+ <a name="M000039"></a>
+
+ <div class="method-heading">
+
+ <a href="Seq.src/M000039.html" target="Code" class="method-signature"
+ onclick="popupCode('Seq.src/M000039.html');return false;">
+
+ <span class="method-name">is_protein</span><span class="method-args">()</span>
+
+ </a>
+
+ </div>
+
+ <div class="method-description">
+
+ </div>
+ </div>
+
+
+ <div id="method-M000038" class="method-detail">
+ <a name="M000038"></a>
+
+ <div class="method-heading">
+
+ <a href="Seq.src/M000038.html" target="Code" class="method-signature"
+ onclick="popupCode('Seq.src/M000038.html');return false;">
+
+ <span class="method-name">is_rna</span><span class="method-args">()</span>
+
+ </a>
+
+ </div>
+
+ <div class="method-description">
+
+ </div>
+ </div>
+
+
+ <div id="method-M000036" class="method-detail">
+ <a name="M000036"></a>
+
+ <div class="method-heading">
+
+ <span class="method-name">len</span><span class="method-args">()</span>
+
+ </div>
+
+ <div class="method-description">
+
+ <p>
+Alias for <a href="Seq.html#M000035">length</a>
+</p>
+
+ </div>
+ </div>
+
+
<div id="method-M000035" class="method-detail">
<a name="M000035"></a>
<a href="Seq.src/M000035.html" target="Code" class="method-signature"
onclick="popupCode('Seq.src/M000035.html');return false;">
- <span class="method-name">generate!</span><span class="method-args">( length )</span>
+ <span class="method-name">length</span><span class="method-args">()</span>
</a>
<div class="method-description">
- <p>
-Method that replaces sequence with a randomly generated sequence of a given
-length.
-</p>
-
</div>
</div>
- <div id="method-M000031" class="method-detail">
- <a name="M000031"></a>
+ <div id="method-M000042" class="method-detail">
+ <a name="M000042"></a>
<div class="method-heading">
- <a href="Seq.src/M000031.html" target="Code" class="method-signature"
- onclick="popupCode('Seq.src/M000031.html');return false;">
+ <a href="Seq.src/M000042.html" target="Code" class="method-signature"
+ onclick="popupCode('Seq.src/M000042.html');return false;">
- <span class="method-name">guess_type</span><span class="method-args">()</span>
+ <span class="method-name">to_bp</span><span class="method-args">()</span>
</a>
<div class="method-description">
<p>
-Guess the sequence type by analyzing the first 100 residues allowing for
-ambiguity codes.
+Method that given a <a href="Seq.html">Seq</a> entry returns a <a
+href="Biopieces.html">Biopieces</a> record (a hash).
</p>
</div>
</div>
- <div id="method-M000032" class="method-detail">
- <a name="M000032"></a>
+ <div id="method-M000041" class="method-detail">
+ <a name="M000041"></a>
<div class="method-heading">
- <a href="Seq.src/M000032.html" target="Code" class="method-signature"
- onclick="popupCode('Seq.src/M000032.html');return false;">
+ <a href="Seq.src/M000041.html" target="Code" class="method-signature"
+ onclick="popupCode('Seq.src/M000041.html');return false;">
- <span class="method-name">wrap</span><span class="method-args">( width = 80, delimit = "\n" )</span>
+ <span class="method-name">to_dna</span><span class="method-args">()</span>
</a>
<div class="method-description">
<p>
-Method to wrap a sequence to a given width using a given delimiter.
+Method to reverse-transcribe RNA to DNA.
</p>
</div>
</div>
- <div id="method-M000033" class="method-detail">
- <a name="M000033"></a>
+ <div id="method-M000040" class="method-detail">
+ <a name="M000040"></a>
<div class="method-heading">
- <a href="Seq.src/M000033.html" target="Code" class="method-signature"
- onclick="popupCode('Seq.src/M000033.html');return false;">
+ <a href="Seq.src/M000040.html" target="Code" class="method-signature"
+ onclick="popupCode('Seq.src/M000040.html');return false;">
- <span class="method-name">wrap!</span><span class="method-args">( width = 80, delimit = "\n" )</span>
+ <span class="method-name">to_rna</span><span class="method-args">()</span>
</a>
<div class="method-description">
<p>
-Method to wrap and replace a sequence to a given width using a given
-delimiter.
+Method to transcribe DNA to RNA.
</p>
</div>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
- <title>generate! (Seq)</title>
+ <title>length (Seq)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File seq.rb, line 40</span>
- <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">generate!</span>( <span class="ruby-identifier">length</span> )
- <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">replace</span>( <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">generate</span>( <span class="ruby-identifier">length</span> ) )
- <span class="ruby-keyword kw">end</span></pre>
+ <pre><span class="ruby-comment cmt"># File seq.rb, line 11</span>
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">length</span>
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">seq</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-value">? </span><span class="ruby-value">0</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">seq</span>.<span class="ruby-identifier">length</span>
+ <span class="ruby-keyword kw">end</span></pre>
</body>
</html>
<a href="Status.src/M000026.html" target="Code" class="method-signature"
onclick="popupCode('Status.src/M000026.html');return false;">
- <span class="method-name">set_tmpdir</span><span class="method-args">(tmp_path)</span>
+ <span class="method-name">set_tmpdir</span><span class="method-args">(tmpdir_path)</span>
</a>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 448</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 474</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set</span>
<span class="ruby-identifier">time0</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-value str">"%Y-%m-%d %X"</span>)
- <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">mode</span>=<span class="ruby-value str">"w"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span> <span class="ruby-identifier">file</span>.<span class="ruby-identifier">puts</span> [<span class="ruby-identifier">time0</span>, <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">" "</span>)].<span class="ruby-identifier">join</span>(<span class="ruby-value str">";"</span>) }
+ <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">mode</span>=<span class="ruby-value str">"w"</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">fh</span><span class="ruby-operator">|</span>
+ <span class="ruby-identifier">fh</span>.<span class="ruby-identifier">puts</span> [<span class="ruby-identifier">time0</span>, <span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">" "</span>)].<span class="ruby-identifier">join</span>(<span class="ruby-value str">";"</span>)
+ <span class="ruby-keyword kw">end</span>
<span class="ruby-keyword kw">end</span></pre>
</body>
</html>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 455</span>
- <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_tmpdir</span>(<span class="ruby-identifier">tmp_path</span>)
- <span class="ruby-identifier">status</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">mode</span>=<span class="ruby-value str">"r"</span>).<span class="ruby-identifier">read</span>.<span class="ruby-identifier">chomp</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 483</span>
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_tmpdir</span>(<span class="ruby-identifier">tmpdir_path</span>)
+ <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">mode</span>=<span class="ruby-value str">"r"</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">fh</span><span class="ruby-operator">|</span>
+ <span class="ruby-identifier">fh</span>.<span class="ruby-identifier">read</span>.<span class="ruby-identifier">chomp</span>
+ <span class="ruby-keyword kw">end</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">mode</span>=<span class="ruby-value str">"w"</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">fh</span><span class="ruby-operator">|</span>
- <span class="ruby-identifier">fh</span> <span class="ruby-operator"><<</span> [<span class="ruby-identifier">status</span>, <span class="ruby-identifier">tmp_path</span>].<span class="ruby-identifier">join</span>(<span class="ruby-value str">";"</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">"\n"</span>
+ <span class="ruby-identifier">fh</span> <span class="ruby-operator"><<</span> [<span class="ruby-identifier">status</span>, <span class="ruby-identifier">tmpdir_path</span>].<span class="ruby-identifier">join</span>(<span class="ruby-value str">";"</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">"\n"</span>
<span class="ruby-keyword kw">end</span>
<span class="ruby-keyword kw">end</span></pre>
</body>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 465</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 495</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_tmpdir</span>
- <span class="ruby-identifier">tmp_path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">mode</span>=<span class="ruby-value str">"r"</span>).<span class="ruby-identifier">read</span>.<span class="ruby-identifier">chomp</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">";"</span>).<span class="ruby-identifier">last</span>
+ <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">mode</span>=<span class="ruby-value str">"r"</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">fh</span><span class="ruby-operator">|</span>
+ <span class="ruby-identifier">tmpdir_path</span> = <span class="ruby-identifier">fh</span>.<span class="ruby-identifier">read</span>.<span class="ruby-identifier">chomp</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">";"</span>).<span class="ruby-identifier">last</span>
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">tmpdir_path</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-identifier">tmpdir_path</span>)
+ <span class="ruby-keyword kw">end</span>
- <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-identifier">tmp_path</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">tmp_path</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
+ <span class="ruby-keyword kw">nil</span>
<span class="ruby-keyword kw">end</span></pre>
</body>
</html>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 472</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 505</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">log</span>(<span class="ruby-identifier">exit_status</span>)
<span class="ruby-identifier">time1</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-value str">"%Y-%m-%d %X"</span>)
<span class="ruby-identifier">user</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">"USER"</span>]
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 489</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 522</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">path</span>)
<span class="ruby-keyword kw">end</span></pre>
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File biopieces.rb, line 514</span>
+ <pre><span class="ruby-comment cmt"># File biopieces.rb, line 547</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">options</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">stdio</span>)
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">mode</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"r"</span>
<span class="ruby-identifier">$stdin</span>.<span class="ruby-identifier">tty?</span> <span class="ruby-value">? </span><span class="ruby-identifier">read</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value str">"stream_in"</span>]) <span class="ruby-operator">:</span> <span class="ruby-identifier">stdio</span>
-Fri, 06 Aug 2010 15:47:42 +0200
+Tue, 17 Aug 2010 15:43:49 +0200
</tr>
<tr class="top-aligned-row">
<td><strong>Last Update:</strong></td>
- <td>2010-08-06 13:58:09 +0200</td>
+ <td>2010-08-17 14:23:28 +0200</td>
</tr>
</table>
</div>
<div id="contextContent">
+ <div id="description">
+ <p>
+Copyright (C) 2007-2010 Martin A. Hansen.
+</p>
+
+ </div>
+
<div id="requires-list">
<h3 class="section-bar">Required files</h3>
</tr>
<tr class="top-aligned-row">
<td><strong>Last Update:</strong></td>
- <td>2009-08-10 09:00:55 +0200</td>
+ <td>2010-08-17 08:33:38 +0200</td>
</tr>
</table>
</div>
<div id="contextContent">
- <div id="description">
- <p>
-Class containing generic sequence methods and nucleic acid and amino acid
-subclasses.
-</p>
-
- </div>
-
</div>
<div id="section">
+ <div id="constants-list">
+ <h3 class="section-bar">Constants</h3>
+
+ <div class="name-list">
+ <table summary="Constants">
+
+ <tr class="top-aligned-row context-row">
+ <td class="context-item-name">DNA</td>
+ <td>=</td>
+ <td class="context-item-value">%w[a t c g]</td>
+
+ </tr>
+
+ <tr class="top-aligned-row context-row">
+ <td class="context-item-name">RNA</td>
+ <td>=</td>
+ <td class="context-item-value">%w[a u c g]</td>
+
+ </tr>
+
+ <tr class="top-aligned-row context-row">
+ <td class="context-item-name">PROTEIN</td>
+ <td>=</td>
+ <td class="context-item-value">%w[f l s y c w p h q r i m t n k v a d e g]</td>
+
+ </tr>
+
+ </table>
+ </div>
+ </div>
+
<a href="classes/Casts.html">Casts</a><br />
- <a href="classes/OptionHandler.html">OptionHandler</a><br />
-
- <a href="classes/Seq.html">Seq</a><br />
+ <a href="classes/Fasta.html">Fasta</a><br />
- <a href="classes/Seq/AA.html">Seq::AA</a><br />
+ <a href="classes/FastaError.html">FastaError</a><br />
- <a href="classes/Seq/NA.html">Seq::NA</a><br />
+ <a href="classes/OptionHandler.html">OptionHandler</a><br />
- <a href="classes/Seq/NA/DNA.html">Seq::NA::DNA</a><br />
+ <a href="classes/Seq.html">Seq</a><br />
- <a href="classes/Seq/NA/RNA.html">Seq::NA::RNA</a><br />
+ <a href="classes/SeqError.html">SeqError</a><br />
<a href="classes/Status.html">Status</a><br />
<a href="files/biopieces_rb.html">biopieces.rb</a><br />
+ <a href="files/fasta_rb.html">fasta.rb</a><br />
+
<a href="files/seq_rb.html">seq.rb</a><br />
</div>
<h1 class="section-bar">Methods</h1>
<div id="index-entries">
- <a href="classes/Seq/NA/RNA.html#M000043">complement (Seq::NA::RNA)</a><br />
-
- <a href="classes/Seq/NA/DNA.html#M000040">complement (Seq::NA::DNA)</a><br />
+ <a href="classes/Seq.html#M000043">complement (Seq)</a><br />
<a href="classes/Status.html#M000029">delete (Status)</a><br />
+ <a href="classes/Fasta.html#M000033">each (Fasta)</a><br />
+
<a href="classes/Biopieces.html#M000004">each (Biopieces)</a><br />
<a href="classes/Biopieces.html#M000003">each_record (Biopieces)</a><br />
- <a href="classes/Seq.html#M000034">generate (Seq)</a><br />
+ <a href="classes/Seq.html#M000044">generate (Seq)</a><br />
- <a href="classes/Seq.html#M000035">generate! (Seq)</a><br />
+ <a href="classes/Fasta.html#M000034">get_entry (Fasta)</a><br />
<a href="classes/Status.html#M000027">get_tmpdir (Status)</a><br />
- <a href="classes/Seq.html#M000031">guess_type (Seq)</a><br />
+ <a href="classes/Seq.html#M000037">is_dna (Seq)</a><br />
+
+ <a href="classes/Seq.html#M000039">is_protein (Seq)</a><br />
+
+ <a href="classes/Seq.html#M000038">is_rna (Seq)</a><br />
+
+ <a href="classes/Seq.html#M000036">len (Seq)</a><br />
+
+ <a href="classes/Seq.html#M000035">length (Seq)</a><br />
<a href="classes/Status.html#M000028">log (Status)</a><br />
<a href="classes/Biopieces.html#M000006">mktmpdir (Biopieces)</a><br />
- <a href="classes/Seq/AA.html#M000037">mol_weight (Seq::AA)</a><br />
+ <a href="classes/OptionHandler.html#M000008">new (OptionHandler)</a><br />
<a href="classes/Casts.html#M000007">new (Casts)</a><br />
- <a href="classes/OptionHandler.html#M000008">new (OptionHandler)</a><br />
+ <a href="classes/Fasta.html#M000032">new (Fasta)</a><br />
<a href="classes/Biopieces.html#M000001">new (Biopieces)</a><br />
<a href="classes/Stream.html#M000030">open (Stream)</a><br />
+ <a href="classes/Fasta.html#M000031">open (Fasta)</a><br />
+
<a href="classes/OptionHandler.html#M000016">options_check (OptionHandler)</a><br />
<a href="classes/OptionHandler.html#M000023">options_check_allowed (OptionHandler)</a><br />
<a href="classes/Biopieces.html#M000005">puts (Biopieces)</a><br />
- <a href="classes/Seq/NA/RNA.html#M000041">residues (Seq::NA::RNA)</a><br />
-
- <a href="classes/Seq/NA/DNA.html#M000038">residues (Seq::NA::DNA)</a><br />
-
- <a href="classes/Seq/AA.html#M000036">residues (Seq::AA)</a><br />
-
<a href="classes/Status.html#M000025">set (Status)</a><br />
<a href="classes/Status.html#M000026">set_tmpdir (Status)</a><br />
- <a href="classes/Seq/NA/RNA.html#M000042">to_DNA (Seq::NA::RNA)</a><br />
+ <a href="classes/Seq.html#M000042">to_bp (Seq)</a><br />
- <a href="classes/Seq/NA/DNA.html#M000039">to_RNA (Seq::NA::DNA)</a><br />
+ <a href="classes/Seq.html#M000041">to_dna (Seq)</a><br />
- <a href="classes/OptionHandler.html#M000010">wiki_path (OptionHandler)</a><br />
-
- <a href="classes/Seq.html#M000032">wrap (Seq)</a><br />
+ <a href="classes/Seq.html#M000040">to_rna (Seq)</a><br />
- <a href="classes/Seq.html#M000033">wrap! (Seq)</a><br />
+ <a href="classes/OptionHandler.html#M000010">wiki_path (OptionHandler)</a><br />
</div>
</div>
--- /dev/null
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# http://www.gnu.org/copyleft/gpl.html
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# This software is part of the Biopieces framework (www.biopieces.org).
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+require 'seq'
+
+# Error class for all exceptions to do with FASTA.
+class FastaError < StandardError; end
+
+class Fasta
+ include Enumerable
+
+ # Class method allowing open to be used on files.
+ # See File.open.
+ def self.open(*args)
+ ios = File.open(*args)
+ fasta = self.new(ios)
+
+ if block_given?
+ begin
+ yield fasta
+ ensure
+ ios.close
+ end
+
+ return true
+ else
+ return fasta
+ end
+ end
+
+ def initialize(io, type=nil)
+ @io = io
+ @type = type
+ end
+
+ # Iterator method for parsing FASTA enries.
+ def each
+ while entry = get_entry do
+ yield entry
+ end
+ end
+
+ # Method to get the next FASTA entry form an ios and return this
+ # as a Seq object. If no entry is found or eof then nil is returned.
+ def get_entry
+ block = @io.gets($/ + '>')
+ return nil if block.nil?
+
+ block.chomp!($/ + '>')
+
+ (seq_name, seq) = block.split($/, 2)
+
+ raise FastaError, "Bad FASTA format" if seq_name.nil? or seq.nil?
+
+ entry = Seq.new
+ entry.type = @type.nil? ? nil : @type.downcase
+ entry.seq = seq.gsub(/\s/, '')
+ entry.seq_name = seq_name.sub(/^>/, '').rstrip
+
+ raise FastaError, "Bad FASTA format" if entry.seq_name.empty?
+ raise FastaError, "Bad FASTA format" if entry.seq.empty?
+
+ entry
+ end
+end
+
+
+__END__
+DNA = %w[a t c g]
+RNA = %w[a u c g]
+PROTEIN = %w[f l s y c w p h q r i m t n k v a d e g]
+
+# Error class for all exceptions to do with Seq.
+class SeqError < StandardError; end
+
+class Seq
+ attr_accessor :seq_name, :seq, :type, :qual
+
+ def length
+ self.seq.nil? ? 0 : self.seq.length
+ end
+
+ alias len length
+
+ # Method that returns true is a given sequence type is DNA.
+ def is_dna
+ self.type == 'dna'
+ end
+
+ def is_rna
+ self.type == 'rna'
+ end
+
+ def is_protein
+ self.type == 'protein'
+ end
+
+ # Method to transcribe DNA to RNA.
+ def to_rna
+ raise SeqError, "Cannot transcribe 0 length sequence" if self.length == 0
+ raise SeqError, "Cannot transcribe sequence type: #{self.type}" unless self.is_dna
+ self.type = 'rna'
+ self.seq.tr!('Tt','Uu')
+ end
+
+ # Method to reverse-transcribe RNA to DNA.
+ def to_dna
+ raise SeqError, "Cannot reverse-transcribe 0 length sequence" if self.length == 0
+ raise SeqError, "Cannot reverse-transcribe sequence type: #{self.type}" unless self.is_rna
+ self.type = 'dna'
+ self.seq.tr!('Uu','Tt')
+ end
+
+ # Method that given a Seq entry returns a Biopieces record (a hash).
+ def to_bp
+ raise SeqError, "Missing seq_name" if self.seq_name.nil?
+ raise SeqError, "Missing seq" if self.seq.nil?
+ record = {}
+ record['SEQ_NAME'] = self.seq_name
+ record['SEQ'] = self.seq
+ record['SEQ_LEN'] = self.length
+ record
+ end
+
+ # Method that complements sequence including ambiguity codes.
+ def complement
+ raise SeqError, "Cannot complement 0 length sequence" if self.length == 0
+
+ if self.is_dna
+ self.seq.tr!( 'AGCUTRYWSMKHDVBNagcutrywsmkhdvbn', 'TCGAAYRWSKMDHBVNtcgaayrwskmdhbvn' )
+ elsif self.is_rna
+ self.seq.tr!( 'AGCUTRYWSMKHDVBNagcutrywsmkhdvbn', 'UCGAAYRWSKMDHBVNucgaayrwskmdhbvn' )
+ else
+ raise SeqError, "Cannot complement sequence type: #{self.type}"
+ end
+ end
+
+ # Method that generates a random sequence of a given length.
+ def generate(length,type)
+ raise SeqError, "Cannot generate negative sequence length: #{length}" if length <= 0
+
+ case type.downcase
+ when "dna"
+ alph = DNA
+ when "rna"
+ alph = RNA
+ when "protein"
+ alph = PROTEIN
+ else
+ raise SeqError, "Unknown sequence type: #{type}"
+ end
+
+ seq_new = Array.new(length) { alph[rand(alph.size)] }.join("")
+ self.seq = seq_new
+ self.type = type.downcase
+ seq_new
+ end
+end
+
+__END__
+
+
+
+
+
# Class containing generic sequence methods and nucleic acid and amino acid subclasses.
class Seq < String
- # Guess the sequence type by analyzing the first 100 residues allowing for ambiguity codes.
- def guess_type
- raise ArgumentError, "No sequence." if self.empty?
-
- seq_beg = self[0, 100].upcase
-
- if seq_beg.count( "FLPQIE" ) > 0
- Seq::AA.new(self)
- elsif seq_beg.count("U") > 0
- Seq::NA::RNA.new(self)
- else
- Seq::NA::DNA.new(self)
- end
- end
-
- # Method to wrap a sequence to a given width using a given delimiter.
- def wrap(width = 80, delimit = $/)
- raise ArgumentError, "Cannot wrap sequence to negative width: #{width}." if width <= 0
-
- self.delete!(" \t\n\r")
- self.gsub(/.{#{width}}(?!$)/, "\\0#{delimit}")
- end
-
- # Method to wrap and replace a sequence to a given width using a given delimiter.
- def wrap!(width = 80, delimit = $/)
- self.replace(self.wrap(width, delimit))
- end
-
- # Method that generates a random sequence of a given length.
- def generate(length)
- raise ArgumentError, "Cannot generate negative sequence length: #{length}." if length <= 0
-
- alph = self.residues
- Array.new(length) { alph[rand(alph.size)] }.join("")
- end
-
- # Method that replaces sequence with a randomly generated sequence of a given length.
- def generate!(length)
- self.replace(self.generate(length))
- end
-
- # Class containing methods specific for amino acid (AA) sequences.
- class AA < Seq
- # Method that returns an array of amino acid residues.
- def residues
- %w{ F L S Y C W P H Q R I M T N K V A D E G }
- end
-
- # Calculate the molecular weight of an amino acid seuqunce.
- # The caluculation is only approximate since there is no correction
- # for amino bond formation and the MW used are somewhat imprecise:
- # http://www.expasy.ch/tools/pscale/Molecularweight.html
- def mol_weight
- raise ArgumentError, "invalid residues found: #{self.delete("#{residues.join( "" )}")}" if self.upcase =~ /[^#{residues.join( "" )}]/
-
- mol_weight_aa = {
- "A" => 89.000, # Ala
- "R" => 174.000, # Arg
- "N" => 132.000, # Asn
- "D" => 133.000, # Asp
- "C" => 121.000, # Cys
- "Q" => 146.000, # Gln
- "E" => 147.000, # Glu
- "G" => 75.000, # Gly
- "H" => 155.000, # His
- "I" => 131.000, # Ile
- "L" => 131.000, # Leu
- "K" => 146.000, # Lys
- "M" => 149.000, # Met
- "F" => 165.000, # Phe
- "P" => 115.000, # Pro
- "S" => 105.000, # Ser
- "T" => 119.000, # Thr
- "W" => 204.000, # Trp
- "Y" => 181.000, # Tyr
- "V" => 117.000, # Val
- }
-
- mw = 0.0
-
- self.upcase.each_char { |c| mw += mol_weight_aa[ c ] }
-
- mw
- end
- end
-
- # Class containing methods specific for nucleic acid (NA) sequences.
- class NA < Seq
- # Class containing methods specific for DNA sequences.
- class DNA < NA
- # Method that returns an array of DNA residues.
- def residues
- %w{ A T C G }
- end
-
- # Method to transcribe DNA to RNA.
- def to_RNA
- Seq::NA::RNA.new( self.tr( 'Tt', 'Uu' ) )
- end
-
- # Method that complements DNA sequence including ambiguity codes.
- def complement
- self.tr!( 'AGCUTRYWSMKHDVBNagcutrywsmkhdvbn', 'TCGAAYRWSKMDHBVNtcgaayrwskmdhbvn' )
- end
- end
-
- # Class containing methods specific for RNA sequences.
- class RNA < NA
- # Method that returns an array of RNA residues.
- def residues
- %w{ A U C G }
- end
-
- # Method to reverse transcribe RNA to DNA.
- def to_DNA
- Seq::NA::DNA.new( self.tr( 'Uu', 'Tt' ) )
- end
-
- # Method that complements RNA sequence including ambiguity codes.
- def complement
- self.tr!( 'AGCUTRYWSMKHDVBNagcutrywsmkhdvbn', 'UCGAAYRWSKMDHBVNucgaayrwskmdhbvn' )
- end
- end
- end
-end
+ # Guess the sequence type by analyzing the first 100 residues allowing for ambiguity codes.
+ def guess_type
+ raise ArgumentError, "No sequence." if self.empty?
+
+ seq_beg = self[0, 100].upcase
+
+ if seq_beg.count( "FLPQIE" ) > 0
+ Seq::AA.new(self)
+ elsif seq_beg.count("U") > 0
+ Seq::NA::RNA.new(self)
+ else
+ Seq::NA::DNA.new(self)
+ end
+ end
+
+ # Method to wrap a sequence to a given width using a given delimiter.
+ def wrap(width = 80, delimit = $/)
+ raise ArgumentError, "Cannot wrap sequence to negative width: #{width}." if width <= 0
+
+ self.delete!(" \t\n\r")
+ self.gsub(/.{#{width}}(?!$)/, "\\0#{delimit}")
+ end
+
+ # Method to wrap and replace a sequence to a given width using a given delimiter.
+ def wrap!(width = 80, delimit = $/)
+ self.replace(self.wrap(width, delimit))
+ end
+
+ # Method that generates a random sequence of a given length.
+ def generate(length)
+ raise ArgumentError, "Cannot generate negative sequence length: #{length}." if length <= 0
+
+ alph = self.residues
+ Array.new(length) { alph[rand(alph.size)] }.join("")
+ end
+
+ # Method that replaces sequence with a randomly generated sequence of a given length.
+ def generate!(length)
+ self.replace(self.generate(length))
+ end
+
+ # Class containing methods specific for amino acid (AA) sequences.
+ class AA < Seq
+ # Method that returns an array of amino acid residues.
+ def residues
+ %w{ F L S Y C W P H Q R I M T N K V A D E G }
+ end
+
+ # Calculate the molecular weight of an amino acid seuqunce.
+ # The caluculation is only approximate since there is no correction
+ # for amino bond formation and the MW used are somewhat imprecise:
+ # http://www.expasy.ch/tools/pscale/Molecularweight.html
+ def mol_weight
+ raise ArgumentError, "invalid residues found: #{self.delete("#{residues.join( "" )}")}" if self.upcase =~ /[^#{residues.join( "" )}]/
+
+ mol_weight_aa = {
+ "A" => 89.000, # Ala
+ "R" => 174.000, # Arg
+ "N" => 132.000, # Asn
+ "D" => 133.000, # Asp
+ "C" => 121.000, # Cys
+ "Q" => 146.000, # Gln
+ "E" => 147.000, # Glu
+ "G" => 75.000, # Gly
+ "H" => 155.000, # His
+ "I" => 131.000, # Ile
+ "L" => 131.000, # Leu
+ "K" => 146.000, # Lys
+ "M" => 149.000, # Met
+ "F" => 165.000, # Phe
+ "P" => 115.000, # Pro
+ "S" => 105.000, # Ser
+ "T" => 119.000, # Thr
+ "W" => 204.000, # Trp
+ "Y" => 181.000, # Tyr
+ "V" => 117.000, # Val
+ }
+
+ mw = 0.0
+
+ self.upcase.each_char { |c| mw += mol_weight_aa[ c ] }
+
+ mw
+ end
+ end
#!/usr/bin/env ruby
-# $:.unshift File.join(File.dirname(__FILE__),'..','lib')
+$:.unshift File.join(File.dirname(__FILE__),'..','lib')
# Copyright (C) 2007-2010 Martin A. Hansen.
DUMMY_FILE = __FILE__
SCRIPT_PATH = "write_fasta"
-class OptionTest < Test::Unit::TestCase
+class BiopiecesTest < Test::Unit::TestCase
def setup
@input = StringIO.new
--- /dev/null
+#!/usr/bin/env ruby
+$:.unshift File.join(File.dirname(__FILE__),'..','lib')
+
+# Copyright (C) 2007-2010 Martin A. Hansen.
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# http://www.gnu.org/copyleft/gpl.html
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# This software is part of the Biopieces framework (www.biopieces.org).
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+require 'test/unit'
+require 'fasta'
+require 'stringio'
+require 'pp'
+
+class FastaTest < Test::Unit::TestCase
+ test "Fasta#get_entry obtains the correct seq_name" do
+ fasta = Fasta.new(StringIO.new(">test\nATCG\n"))
+ assert_equal(fasta.get_entry.seq_name, "test")
+ end
+
+ test "Fasta#get_entry obtains the correct seq without trailing newlines" do
+ fasta = Fasta.new(StringIO.new(">test\nATCG"))
+ assert_equal(fasta.get_entry.seq, "ATCG")
+ end
+
+ test "Fasta#get_entry obtains the correct seq with trailing newlines" do
+ fasta = Fasta.new(StringIO.new(">test\nATCG\n\n\n"))
+ assert_equal(fasta.get_entry.seq, "ATCG")
+ end
+
+ test "Fasta#get_entry obtains the correct type" do
+ fasta = Fasta.new(StringIO.new(">test\nATCG\n"), 'DNA')
+ assert_equal(fasta.get_entry.type, "dna")
+ end
+
+ test "Fasta#get_entry rstrips whitespace from seq_name" do
+ fasta = Fasta.new(StringIO.new(">test\n\r\t ATCG\n"))
+ assert_equal(fasta.get_entry.seq_name, "test")
+ end
+
+ test "Fasta#get_entry strips whitespace from seq" do
+ fasta = Fasta.new(StringIO.new(">test\n\r\t AT\n\r\t CG\n\r\t "))
+ assert_equal(fasta.get_entry.seq, "ATCG")
+ end
+
+ test "Fasta#get_entry with two entries obtain correct" do
+ fasta = Fasta.new(StringIO.new(">test1\n\r\t AT\n\r\t CG\n\r\t \n>test2\n\r\t atcg\n"))
+ assert_equal(fasta.get_entry.seq, "ATCG")
+ assert_equal(fasta.get_entry.seq, "atcg")
+ end
+
+ test "Fasta#get_entry without seq_name raises" do
+ fasta = Fasta.new(StringIO.new("ATCG\n"))
+ assert_raise( FastaError ) { fasta.get_entry }
+ end
+
+ test "Fasta#get_entry without seq raises" do
+ fasta = Fasta.new(StringIO.new(">test\n\n"))
+ assert_raise( FastaError ) { fasta.get_entry }
+ end
+
+ test "Fasta#get_entry with leading newline raises" do
+ fasta = Fasta.new(StringIO.new("\n>test\nATCG\n"))
+ assert_raise( FastaError ) { fasta.get_entry }
+ end
+
+# FIXME
+# test "Fasta#get_entry raises on missing > in seq_name" do
+# fasta = Fasta.new(StringIO.new("test\nATCG\n"))
+# assert_raise( FastaError ) { fasta.get_entry }
+# end
+end
require 'pp'
class TestSeq < Test::Unit::TestCase
- # Testing Seq#initialize
+ def setup
+ @entry = Seq.new
+ end
+
+ # test "Seq# autoremoves whitespace, newlines, and carriage returns" do
+ # dna = Seq.new
+ # dna.seq = "A\tT\r\tC\nG "
+ # assert_equal(dna.seq, "ATCG")
+ # end
+
+ test "Seq#is_dna with no sequence type returns false" do
+ assert_false(@entry.is_dna)
+ end
+
+ test "Seq#is_dna with dna sequence type returns true" do
+ @entry.type = 'dna'
+ assert_true(@entry.is_dna)
+ end
+
+ test "Seq#is_rna with no sequence type returns false" do
+ assert_false(@entry.is_rna)
+ end
+
+ test "Seq#is_rna with rna sequence type returns true" do
+ @entry.type = 'rna'
+ assert_true(@entry.is_rna)
+ end
+
+ test "Seq#is_protein with no sequence type returns false" do
+ assert_false(@entry.is_protein)
+ end
+
+ test "Seq#is_protein with protein sequence type returns true" do
+ @entry.type = 'protein'
+ assert_true(@entry.is_protein)
+ end
+
+ test "Sequence length is correct" do
+ @entry.seq = 'ATCG'
+ assert_equal(@entry.length, 4)
+ end
+
+ test "Seq#to_rna raises if no sequence" do
+ @entry.type = 'dna'
+ assert_raise(SeqError) { @entry.to_rna }
+ end
+
+ test "Seq#to_rna raises on bad type" do
+ @entry.seq = 'ATCG'
+ @entry.type = 'rna'
+ assert_raise(SeqError) { @entry.to_rna }
+ end
+
+ test "Seq#to_rna transcribes correctly" do
+ @entry.seq = 'ATCGatcg'
+ @entry.type = 'dna'
+ assert_equal(@entry.to_rna, "AUCGaucg")
+ end
+
+ test "Seq#to_rna changes entry type to rna" do
+ @entry.seq = 'ATCGatcg'
+ @entry.type = 'dna'
+ @entry.to_rna
+ assert_equal(@entry.type, "rna")
+ end
+
+ test "Seq#to_dna raises if no sequence" do
+ @entry.type = 'rna'
+ assert_raise(SeqError) { @entry.to_dna }
+ end
+
+ test "Seq#to_dna raises on bad type" do
+ @entry.seq = 'AUCG'
+ @entry.type = 'dna'
+ assert_raise(SeqError) { @entry.to_dna }
+ end
+
+ test "Seq#to_dna transcribes correctly" do
+ @entry.seq = 'AUCGaucg'
+ @entry.type = 'rna'
+ assert_equal(@entry.to_dna, "ATCGatcg")
+ end
+
+ test "Seq#to_dna changes entry type to dna" do
+ @entry.seq = 'AUCGaucg'
+ @entry.type = 'rna'
+ @entry.to_dna
+ assert_equal(@entry.type, "dna")
+ end
+
+ test "Seq#to_bp returns correct record" do
+ @entry.seq_name = 'test'
+ @entry.seq = 'ATCG'
+ assert_equal(@entry.to_bp, {"SEQ_NAME"=>"test", "SEQ"=>"ATCG", "SEQ_LEN"=>4})
+ end
+
+ test "Seq#to_bp raises on missing seq_name" do
+ @entry.seq = 'ATCG'
+ assert_raise(SeqError) { @entry.to_bp }
+ end
+
+ test "Seq#to_bp raises on missing sequence" do
+ @entry.seq_name = 'test'
+ assert_raise(SeqError) { @entry.to_bp }
+ end
+
+ test "Seq#complement raises if no sequence" do
+ @entry.type = 'dna'
+ assert_raise(SeqError) { @entry.complement }
+ end
+
+ test "Seq#complement raises on bad type" do
+ @entry.seq = 'ATCG'
+ @entry.type = 'protein'
+ assert_raise(SeqError) { @entry.complement }
+ end
+
+ test "Seq#complement for DNA is correct" do
+ @entry.seq = 'ATCGatcg'
+ @entry.type = 'dna'
+ assert_equal(@entry.complement, "TAGCtagc")
+ end
+
+ test "Seq#complement for RNA is correct" do
+ @entry.seq = 'AUCGaucg'
+ @entry.type = 'rna'
+ assert_equal(@entry.complement, "UAGCuagc")
+ end
+
+ test "Seq#generate raises if length <= 0" do
+ assert_raise(SeqError) { @entry.generate(-10, "dna") }
+ assert_raise(SeqError) { @entry.generate(0, "dna") }
+ end
+
+ test "Seq#generate raises on bad type" do
+ assert_raise(SeqError) { @entry.generate(10, "foo") }
+ end
+
+ test "Seq#generate don't raise on ok type" do
+ %w[ dna DNA rna RNA protein Protein ].each do |type|
+ assert_nothing_raised { @entry.generate(10, type) }
+ end
+ end
+end
+
- # test marked for deletion - too simple and not informative
- def test_Seq_initialize_with_0_args
- s = Seq.new
- assert_equal( "", s.to_s )
- end
+__END__
+
+class TestSeq < Test::Unit::TestCase
+ # Testing Seq#guess_type
- # test marked for deletion - too simple and not informative
- def test_Seq_initialize_with_1_args
- s = Seq.new( "ATCG" )
- assert_equal( "ATCG", s.to_s )
- end
+ def test_guess_type_raise_if_no_sequence
+ s = Seq.new
- # Testing Seq#to_s
- def test_to_s
- s = Seq.new( "ATCG" )
- assert_equal( "ATCG", s.to_s )
- end
+ assert_raise( ArgumentError ) { s.guess_type }
+ end
- # Testing Seq#guess_type
+ def test_guess_type_AA_uppercase
+ s1 = Seq.new( "SEQ" )
+ s2 = Seq::AA.new( "SEQ" )
+ assert_equal( s1.guess_type.class, s2.class )
+ end
- def test_guess_type_raise_if_no_sequence
- s = Seq.new
+ def test_guess_type_AA_lowercase
+ s1 = Seq.new( "seq" )
+ s2 = Seq::AA.new( "seq" )
- assert_raise( ArgumentError ) { s.guess_type }
- end
+ assert_equal( s1.guess_type.class, s2.class )
+ end
- def test_guess_type_AA_uppercase
- s1 = Seq.new( "SEQ" )
- s2 = Seq::AA.new( "SEQ" )
- assert_equal( s1.guess_type.class, s2.class )
- end
+ def test_guess_type_DNA_uppercase
+ s1 = Seq.new( "ATCG" )
+ s2 = Seq::NA::DNA.new( "ATCG" )
- def test_guess_type_AA_lowercase
- s1 = Seq.new( "seq" )
- s2 = Seq::AA.new( "seq" )
+ assert_equal( s1.guess_type.class, s2.class )
+ end
- assert_equal( s1.guess_type.class, s2.class )
- end
+ def test_guess_type_DNA_lowercase
+ s1 = Seq.new( "atcg" )
+ s2 = Seq::NA::DNA.new( "atcg" )
- def test_guess_type_DNA_uppercase
- s1 = Seq.new( "ATCG" )
- s2 = Seq::NA::DNA.new( "ATCG" )
+ assert_equal( s1.guess_type.class, s2.class )
+ end
- assert_equal( s1.guess_type.class, s2.class )
- end
+ def test_guess_type_RNA_uppercase
+ s1 = Seq.new( "AUCG" )
+ s2 = Seq::NA::RNA.new( "AUCG" )
- def test_guess_type_DNA_lowercase
- s1 = Seq.new( "atcg" )
- s2 = Seq::NA::DNA.new( "atcg" )
+ assert_equal( s1.guess_type.class, s2.class )
+ end
- assert_equal( s1.guess_type.class, s2.class )
- end
+ def test_guess_type_RNA_lowercase
+ s1 = Seq.new( "aucg" )
+ s2 = Seq::NA::RNA.new( "aucg" )
- def test_guess_type_RNA_uppercase
- s1 = Seq.new( "AUCG" )
- s2 = Seq::NA::RNA.new( "AUCG" )
+ assert_equal( s1.guess_type.class, s2.class )
+ end
- assert_equal( s1.guess_type.class, s2.class )
- end
+ # Testing Seq#wrap
- def test_guess_type_RNA_lowercase
- s1 = Seq.new( "aucg" )
- s2 = Seq::NA::RNA.new( "aucg" )
+ def test_wrap_arg_is_a_positive_number
+ s = Seq.new
- assert_equal( s1.guess_type.class, s2.class )
- end
+ assert_raise( ArgumentError ) { s.wrap( 0 ) }
+ assert_raise( ArgumentError ) { s.wrap( -10 ) }
+ end
- # Testing Seq#wrap
+ def test_wrap_with_0_args
+ s = Seq.new( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACGACTACGACT" )
- def test_wrap_arg_is_a_positive_number
- s = Seq.new
+ assert_equal( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACG\nACTACGACT", s.wrap.to_s )
+ end
- assert_raise( ArgumentError ) { s.wrap( 0 ) }
- assert_raise( ArgumentError ) { s.wrap( -10 ) }
- end
+ def test_wrap_with_1_args
+ s = Seq.new( "ATCG" )
- def test_wrap_with_0_args
- s = Seq.new( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACGACTACGACT" )
+ assert_equal( "AT\nCG", s.wrap( 2 ).to_s )
+ end
- assert_equal( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACG\nACTACGACT", s.wrap.to_s )
- end
+ def test_wrap_with_2_args
+ s = Seq.new( "ATCG" )
- def test_wrap_with_1_args
- s = Seq.new( "ATCG" )
+ assert_equal( "AT\rCG", s.wrap( 2, "\r" ).to_s )
+ end
- assert_equal( "AT\nCG", s.wrap( 2 ).to_s )
- end
+ def test_wrap_dont_change_instance_var
+ s = Seq.new( "ATCG" )
- def test_wrap_with_2_args
- s = Seq.new( "ATCG" )
+ s.wrap( 2 )
- assert_equal( "AT\rCG", s.wrap( 2, "\r" ).to_s )
- end
+ assert_equal( "ATCG", s.to_s )
+ end
- def test_wrap_dont_change_instance_var
- s = Seq.new( "ATCG" )
+ # Testing Seq#wrap!
- s.wrap( 2 )
+ def test_wrap_with_0_args!
+ s = Seq.new( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACGACTACGACT" )
- assert_equal( "ATCG", s.to_s )
- end
+ s.wrap!
- # Testing Seq#wrap!
+ assert_equal( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACG\nACTACGACT", s.to_s )
+ end
- def test_wrap_with_0_args!
- s = Seq.new( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACGACTACGACT" )
+ def test_wrap_with_1_args!
+ s = Seq.new( "ATCG" )
- s.wrap!
+ s.wrap!( 2 )
- assert_equal( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACG\nACTACGACT", s.to_s )
- end
+ assert_equal( "AT\nCG", s.to_s )
+ end
- def test_wrap_with_1_args!
- s = Seq.new( "ATCG" )
+ def test_wrap_with_2_args!
+ s = Seq.new( "ATCG" )
- s.wrap!( 2 )
+ s.wrap!( 2, "\r" )
- assert_equal( "AT\nCG", s.to_s )
- end
+ assert_equal( "AT\rCG", s.to_s )
+ end
- def test_wrap_with_2_args!
- s = Seq.new( "ATCG" )
+ # Testing Seq#generate
- s.wrap!( 2, "\r" )
+ def test_generate_arg_is_a_positive_number
+ s = Seq.new
- assert_equal( "AT\rCG", s.to_s )
- end
+ assert_raise( ArgumentError ) { s.generate( 0 ) }
+ assert_raise( ArgumentError ) { s.generate( -10 ) }
+ end
- # Testing Seq#generate
+ def test_generate
+ s = Seq::AA.new
- def test_generate_arg_is_a_positive_number
- s = Seq.new
+ seq = s.generate( 40 )
- assert_raise( ArgumentError ) { s.generate( 0 ) }
- assert_raise( ArgumentError ) { s.generate( -10 ) }
- end
+ assert_equal( 40, seq.length )
+ end
- def test_generate
- s = Seq::AA.new
+ def test_generate_dont_change_instance_var
+ s = Seq::AA.new
- seq = s.generate( 40 )
+ seq = s.generate( 40 )
- assert_equal( 40, seq.length )
- end
+ assert_equal( "", s.to_s )
+ end
- def test_generate_dont_change_instance_var
- s = Seq::AA.new
+ # Testing Seq#generate!
- seq = s.generate( 40 )
+ def test_generate!
+ s = Seq::AA.new
- assert_equal( "", s.to_s )
- end
+ s.generate!( 40 )
- # Testing Seq#generate!
+ assert_equal( 40, s.length )
+ end
- def test_generate!
- s = Seq::AA.new
+ # Testing Seq::AA#residues
- s.generate!( 40 )
-
- assert_equal( 40, s.length )
- end
+ def test_Seq_AA_residues
+ s = Seq::AA.new
- # Testing Seq::AA#residues
+ assert_equal( %w{ F L S Y C W P H Q R I M T N K V A D E G }, s.residues )
+ end
- def test_Seq_AA_residues
- s = Seq::AA.new
+ # Testing Seq::AA#mol_weight
- assert_equal( %w{ F L S Y C W P H Q R I M T N K V A D E G }, s.residues )
- end
+ def test_Seq_aa_mol_weight_bad_residue
+ s = Seq::AA.new( "7" )
+ assert_raise( ArgumentError ) { s.mol_weight }
+ end
- # Testing Seq::AA#mol_weight
+ def test_Seq_aa_mol_wight_return_correct_uppercase
+ s = Seq::AA.new( "SEQ" )
+ assert_equal( 398.0, s.mol_weight )
+ end
- def test_Seq_aa_mol_weight_bad_residue
- s = Seq::AA.new( "7" )
- assert_raise( ArgumentError ) { s.mol_weight }
- end
+ def test_Seq_aa_mol_wight_return_correct_lowercase
+ s = Seq::AA.new( "seq" )
+ assert_equal( 398.0, s.mol_weight )
+ end
- def test_Seq_aa_mol_wight_return_correct_uppercase
- s = Seq::AA.new( "SEQ" )
- assert_equal( 398.0, s.mol_weight )
- end
+ # Testing Seq::NA::DNA#residues
- def test_Seq_aa_mol_wight_return_correct_lowercase
- s = Seq::AA.new( "seq" )
- assert_equal( 398.0, s.mol_weight )
- end
+ def test_Seq_NA_DNA_residues
+ s = Seq::NA::DNA.new
- # Testing Seq::NA::DNA#residues
+ assert_equal( %w{ A T C G }, s.residues )
+ end
- def test_Seq_NA_DNA_residues
- s = Seq::NA::DNA.new
+ # Testing Seq::NA::DNA#complement
- assert_equal( %w{ A T C G }, s.residues )
- end
+ def test_Seq_NA_DNA_complement_correct
+ s = Seq::NA::DNA.new( "ATCGatcg" )
+ assert_equal( "TAGCtagc", s.complement.to_s )
+ end
- # Testing Seq::NA::DNA#complement
+ # Testing Seq::NA::DNA#to_RNA
- def test_Seq_NA_DNA_complement_correct
- s = Seq::NA::DNA.new( "ATCGatcg" )
- assert_equal( "TAGCtagc", s.complement.to_s )
- end
+ def test_Seq_NA_DNA_to_RNA_returns_RNA_object
+ dna = Seq::NA::DNA.new( "ATCGatcg" )
+ rna = Seq::NA::RNA.new
- # Testing Seq::NA::DNA#to_RNA
+ new_rna = dna.to_RNA
- def test_Seq_NA_DNA_to_RNA_returns_RNA_object
- dna = Seq::NA::DNA.new( "ATCGatcg" )
- rna = Seq::NA::RNA.new
-
- new_rna = dna.to_RNA
+ assert_equal( rna.class, new_rna.class )
+ end
- assert_equal( rna.class, new_rna.class )
- end
+ def test_Seq_NA_DNA_to_RNA_is_correct
+ dna = Seq::NA::DNA.new( "ATCGatcg" )
+ rna = dna.to_RNA
- def test_Seq_NA_DNA_to_RNA_is_correct
- dna = Seq::NA::DNA.new( "ATCGatcg" )
- rna = dna.to_RNA
+ assert_equal( "AUCGaucg", rna.to_s )
+ end
- assert_equal( "AUCGaucg", rna.to_s )
- end
+ # Testing Seq::NA::RNA#residues
- # Testing Seq::NA::RNA#residues
+ def test_Seq_NA_RNA_residues
+ s = Seq::NA::RNA.new
- def test_Seq_NA_RNA_residues
- s = Seq::NA::RNA.new
+ assert_equal( %w{ A U C G }, s.residues )
+ end
- assert_equal( %w{ A U C G }, s.residues )
- end
+ # Testing Seq::NA::RNA#complement
- # Testing Seq::NA::RNA#complement
+ def test_Seq_NA_RNA_complement_correct
+ s = Seq::NA::RNA.new( "AUCGaucg" )
+ assert_equal( "UAGCuagc", s.complement.to_s )
+ end
- def test_Seq_NA_RNA_complement_correct
- s = Seq::NA::RNA.new( "AUCGaucg" )
- assert_equal( "UAGCuagc", s.complement.to_s )
- end
+ # Testing Seq::NA::RNA#to_DNA
- # Testing Seq::NA::RNA#to_DNA
+ def test_Seq_NA_RNA_to_DNA_returns_DNA_object
+ rna = Seq::NA::RNA.new( "AUCGaucg" )
+ dna = Seq::NA::DNA.new
- def test_Seq_NA_RNA_to_DNA_returns_DNA_object
- rna = Seq::NA::RNA.new( "AUCGaucg" )
- dna = Seq::NA::DNA.new
-
- new_dna = rna.to_DNA
+ new_dna = rna.to_DNA
- assert_equal( dna.class, new_dna.class )
- end
+ assert_equal( dna.class, new_dna.class )
+ end
- def test_Seq_NA_RNA_to_DNA_is_correct
- rna = Seq::NA::RNA.new( "AUCGaucg" )
- dna = rna.to_DNA
+ def test_Seq_NA_RNA_to_DNA_is_correct
+ rna = Seq::NA::RNA.new( "AUCGaucg" )
+ dna = rna.to_DNA
- assert_equal( "ATCGatcg", dna.to_s )
- end
+ assert_equal( "ATCGatcg", dna.to_s )
+ end
end