Module: Ms::Fasta::Header

Extended by:
Header
Included in:
Ms::Fasta, Header
Defined in:
lib/ms/fasta/header.rb

Instance Method Summary collapse

Instance Method Details

#filetype(file_or_io) ⇒ Object

scans for a header and returns the results of header_to_filetype



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ms/fasta/header.rb', line 6

def filetype(file_or_io)
  ft = nil
  io = 
    if file_or_io.is_a?(String)
      File.open(file_or_io)
    else
      init_pos = file_or_io.pos
      file_or_io.rewind
      file_or_io
    end
  io.each_line do |line|
    if line =~ /^>/
      ft = header_to_filetype(line[1..-1])
      break
    end
  end

  if file_or_io.is_a?(String)
    io.close
  else
    io.pos = init_pos
  end
  ft
end

#header_to_filetype(line) ⇒ Object

takes the header line (no leading >) and returns the kind of file



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ms/fasta/header.rb', line 32

def header_to_filetype(line)
  if line =~ /^sp|tr\|/
    :uniprot
  elsif line =~ /^IPI\:/
    :ipi
  elsif line =~ /^gi\|/
    :ncbi
  else
    nil
  end
end

#id_regexp(kind) ⇒ Object

kind is :uniprot, :ipi, :ncbi or a String (the header) gives the regular expression for parsing the header (no leading >)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ms/fasta/header.rb', line 46

def id_regexp(kind)
  sym = 
    if kind.is_a?(String)
      header_to_filetype(kind)
    else ; kind
    end
  case sym
  when :uniprot
    /^[st][pr]\|(.*?)\|/o
  when :ipi
    /^IPI:(.*?)\|/o
  when :ncbi
    /^gi\|(.*?)\|/o
  else
    nil
  end
end