Class: NpSearch::Validators
- Inherits:
-
Object
- Object
- NpSearch::Validators
- Defined in:
- lib/npsearch/arg_validator.rb
Instance Method Summary collapse
-
#motif_type(motif) ⇒ Object
Guesses the type of the data in the supplied motif.
-
#output_dir(output_dir) ⇒ Object
Checks for the presence of the output directory; if not found, it asks the user whether they want to create the output directory.
-
#signalp_dir ⇒ Object
Ensures that the Signal P Script is present.
-
#sp_column(_input_file) ⇒ Object
Ensures that the critical columns in the tabular results produced by the Signal P script are conserved.
-
#sp_results(signalp_output_file) ⇒ Object
Ensure that the right version of the Signal P script is used (via ‘sp_version’ Method).
-
#sp_version(input_file) ⇒ Object
Ensures that the supported version of the Signal P Script has been linked to NpSearch.
Instance Method Details
#motif_type(motif) ⇒ Object
Guesses the type of the data in the supplied motif. It ignores all
non-word characters (e.g. '|' that is used for regex). It has a 90%
threshold.
254 255 256 257 258 259 260 261 262 |
# File 'lib/npsearch/arg_validator.rb', line 254 def motif_type(motif) motif_seq = Bio::Sequence.new(motif.gsub(/\W/, '')) type = motif_seq.guess(0.9) return unless type.to_s != 'Bio::Sequence::AA' fail IOError('Critical Error: There seems to be an error in' \ ' processing the motif. Please ensure that the motif' \ ' contains amino acid residues that you wish to search' \ ' for.') end |
#output_dir(output_dir) ⇒ Object
Checks for the presence of the output directory; if not found, it asks
the user whether they want to create the output directory.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/npsearch/arg_validator.rb', line 111 def output_dir(output_dir) unless File.directory? output_dir # If output_dir doesn't exist fail IOError, "\n\nThe output directory deoes not exist\n\n" end rescue IOError puts # a blank line puts 'The output directory does not exist.' puts # a blank line puts "The directory '#{output_dir}' will be created in this location." puts 'Do you to continue? [y/n]' print '> ' inp = $stdin.gets.chomp until inp.downcase == 'n' || inp.downcase == 'y' || inp == '' puts # a blank line puts "The input: '#{inp}' is not recognised - 'y' or 'n' are the" \ ' only recognisable inputs.' puts 'Please try again.' puts "The directory '#{output_dir}' will be created in this" \ ' location.' puts 'Do you to continue? [y/n]' print '> ' inp = $stdin.gets.chomp end if inp.downcase == 'y' || inp == '' FileUtils.mkdir_p "#{output_dir}" puts 'Created output directory...' elsif inp.downcase == 'n' raise ArgumentError('Critical Error: An output directory is' \ ' required; please create an output directory' \ ' and then try again.') end end |
#signalp_dir ⇒ Object
Ensures that the Signal P Script is present. If not found in the home
directory, it asks the user for its location.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/npsearch/arg_validator.rb', line 146 def signalp_dir signalp_dir = "#{Dir.home}/SignalPeptide" if File.exist? "#{signalp_dir}/signalp" signalp_directory = signalp_dir else begin fail IOError('The Signal P Script directory cannot be found at' \ " the following location: '#{signalp_dir}/'.") rescue IOError puts # a blank line puts 'Error: The Signal P Script directory cannot be found at the' \ " following location: '#{signalp_dir}/'." puts # a blank line puts 'Please enter the full path or a relative path to the Signal' \ ' P Script directory (i.e. to the folder containing the' \ ' Signal P script). Refer to the online tutorial for more help' print '> ' inp = $stdin.gets.chomp until (File.exist? "#{signalp_dir}/signalp") || (File.exist? "#{inp}/signalp") puts # a blank line puts 'The Signal P directory cannot be found at the following' \ " location: '#{inp}'" puts 'Please enter the full path or a relative path to the Signal' \ ' Peptide directory again.' print '> ' inp = $stdin.gets.chomp end signalp_directory = inp puts # a blank line puts "The Signal P directory has been found at '#{signalp_directory}'" FileUtils.ln_s "#{signalp_directory}", "#{Dir.home}/SignalPeptide", force: true puts # a blank line end end signalp_directory end |
#sp_column(_input_file) ⇒ Object
Ensures that the critical columns in the tabular results produced by the
Signal P script are conserved. Run from the 'sp_results' method.
200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/npsearch/arg_validator.rb', line 200 def sp_column(_input_file) File.open('signalp_out.txt', 'r') do |file_stream| secondline = file_stream.readlines[1] row = secondline.gsub(/\s+/m, ' ').chomp.split(' ') if row[1] != 'name' && row[4] != 'Ymax' && row[5] != 'pos' && row[9] != 'D' return true else return false end end end |
#sp_results(signalp_output_file) ⇒ Object
Ensure that the right version of the Signal P script is used (via
'sp_version' Method). If the wrong signal p script has been linked to
NpSearch, check whether the critical columns in the tabular results
produced by the Signal P Script are conserved (via 'sp_column'
Method).
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/npsearch/arg_validator.rb', line 218 def sp_results(signalp_output_file) return if sp_version(signalp_output_file) # i.e. if Signal P is the wrong version if sp_column(signalp_output_file) # If wrong version but correct columns puts # a blank line puts 'Warning: The wrong version of signalp has been linked.' \ ' However, the signal peptide output file still seems to' \ ' be in the right format.' else puts # a blank line puts 'Warning: The wrong version of the signal p has been linked' \ ' and the signal peptide output is in an unrecognised format.' puts 'Continuing may give you meaningless results.' end puts # a blank line puts 'Do you still want to continue? [y/n]' print '> ' inp = $stdin.gets.chomp until inp.downcase == 'n' || inp.downcase == 'y' puts # a blank line puts "The input: '#{inp}' is not recognised - 'y' or 'n' are the" \ ' only recognisable inputs.' puts 'Please try again.' end if inp.downcase == 'y' puts 'Continuing.' elsif inp.downcase == 'n' fail IOError('Critical Error: NpSearch only supports SignalP 4.1' \ ' (downloadable form CBS) Please ensure the version' \ ' of the signal p script is downloaded.') end end |
#sp_version(input_file) ⇒ Object
Ensures that the supported version of the Signal P Script has been linked
to NpSearch. Run from the 'sp_results' method.
187 188 189 190 191 192 193 194 195 196 |
# File 'lib/npsearch/arg_validator.rb', line 187 def sp_version(input_file) File.open(input_file, 'r') do |file_stream| first_line = file_stream.readline if first_line.match(/# SignalP-4.1/) return true else return false end end end |