Class: InterMine::PathQuery::Query
- Inherits:
-
Object
- Object
- InterMine::PathQuery::Query
- Defined in:
- lib/intermine/bio.rb
Overview
Biologically specific Extensions to the Query class.
These methods provide mechanisms for accessing results in Biologically appropriate formats, being at present GFF3, FASTA, and UCSC-BED.
The methods provided here can be used to both return the data as a string, and to iterate over the data in logical chunks, approriate to the format in question.
:include:contact_header.rdoc
Instance Method Summary collapse
-
#bed(ucscCompatible = true) ⇒ Object
Return the results from this query as BED.
-
#fasta ⇒ Object
Return the results from this query as FASTA.
-
#gff3 ⇒ Object
Return the results from this query as GFF3.
Instance Method Details
#bed(ucscCompatible = true) ⇒ Object
Return the results from this query as BED
If a block is given, each line of the BED results will be yielded in turn, and the header will be returned, otherwise the content of the BED results will be returned as one string.
If the optional parameter is set to false, then the “chr” prefix on the chromosome id will be omitted.
header = query.bed do |line|
process line
end
puts query.bed(false)
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/intermine/bio.rb', line 141 def bed(ucscCompatible=true) if block_given? header = "" results_reader.each_bed(ucscCompatible) do |bed| if bed =~ /^\s*(#|track)/ header << bed else yield bed end end return header else buffer = "" results_reader.each_bed(ucscCompatible) do |bed| buffer.concat(bed) end return buffer end end |
#fasta ⇒ Object
Return the results from this query as FASTA
If a block is given, each FASTA record will be yielded in turn, and the query will be returned, otherwise the content of the FASTA results will be returned as one string.
query.fasta do |record|
process record
end
puts query.fasta
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/intermine/bio.rb', line 103 def fasta # :yields: record if block_given? buffer = nil results_reader.each_fasta do |line| if line.start_with? ">" yield buffer unless buffer.nil? buffer = line else raise BioError, "Incorrect fasta - no header line" if buffer.nil? buffer << line end end yield buffer unless buffer.nil? return self else buffer = "" results_reader.each_fasta do |line| buffer.concat(line) end return buffer end end |
#gff3 ⇒ Object
Return the results from this query as GFF3
If a block is given, each line of the GFF3 will be yielded in turn, omitting any header lines, which are returned at the end of the iteration, otherwise the content of the GFF3 results will be returned as one string.
header = query.gff3 do |line|
process line
end
puts query.gff3
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/intermine/bio.rb', line 71 def gff3 if block_given? header = "" results_reader.each_gff3 do |gff3| if gff3.start_with? "#" header << gff3 else yield gff3 end end return header else buffer = "" results_reader.each_gff3 do |gff3| buffer.concat(gff3) end return buffer end end |