Skip to content

Commit

Permalink
avoid holding huge xml file on memory
Browse files Browse the repository at this point in the history
  • Loading branch information
inutano committed Feb 7, 2014
1 parent b870776 commit a9828b7
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions sra_metadata_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
module SRAMetadataParser
class Submission
def initialize(id, xml)
@nkgr = Nokogiri::XML(open(xml))
@submission = @nkgr.css("SUBMISSION").select{|n| n.attr("accession") == id }.first
@submission = Nokogiri::XML(open(xml)).css("SUBMISSION").select{|n| n.attr("accession") == id }.first
raise NameError, "submission id not found" unless @submission
end

Expand Down Expand Up @@ -45,8 +44,7 @@ def all

class Study
def initialize(id, xml)
@nkgr = Nokogiri::XML(open(xml))
@study = @nkgr.css("STUDY").select{|n| n.attr("accession") == id }.first
@study = Nokogiri::XML(open(xml)).css("STUDY").select{|n| n.attr("accession") == id }.first
raise NameError, "study id not found" unless @study
end

Expand Down Expand Up @@ -116,8 +114,7 @@ def all

class Experiment
def initialize(id, xml)
@nkgr = Nokogiri::XML(open(xml))
@exp = @nkgr.css("EXPERIMENT").select{|n| n.attr("accession") == id }.first
@exp = Nokogiri::XML(open(xml)).css("EXPERIMENT").select{|n| n.attr("accession") == id }.first
raise NameError, "experiment id not found" unless @exp
end

Expand Down Expand Up @@ -307,8 +304,7 @@ def all

class Sample
def initialize(id, xml)
@nkgr = Nokogiri::XML(open(xml))
@sample = @nkgr.css("SAMPLE").select{|n| n.attr("accession") == id }.first
@sample = Nokogiri::XML(open(xml)).css("SAMPLE").select{|n| n.attr("accession") == id }.first
raise NameError, "sample id not found" unless @sample
end

Expand Down Expand Up @@ -388,8 +384,7 @@ def all

class Run
def initialize(id, xml)
@nkgr = Nokogiri::XML(open(xml))
@run = @nkgr.css("RUN").select{|n| n.attr("accession").to_s == id }.first
@run = Nokogiri::XML(open(xml)).css("RUN").select{|n| n.attr("accession").to_s == id }.first
raise NameError, "run id not found" unless @run
end

Expand Down

0 comments on commit a9828b7

Please sign in to comment.