-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.rb
73 lines (67 loc) · 2.55 KB
/
report.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'csv'
records = []
puts Benchmark.measure {
Occurrence.where(species_aligned: true).distinct.pluck(:taxon_class).each do |taxon_class|
species = Occurrence.where(taxon_class: taxon_class).where(species_aligned: true).distinct.pluck(:species_path)
seqs = species.map {|p| Species.new(Configuration.genbank_root.join(p)).unaligned_fasta_sequence_counts }.flatten
stats = DescriptiveStatistics::Stats.new(seqs.sort)
species_max = species.map {|p| Species.new(Configuration.genbank_root.join(p)) }.max { |a,b|
a.unaligned_fasta_sequence_counts.sum <=> b.unaligned_fasta_sequence_counts.sum
}
records << [
"taxon_class",
taxon_class,
species.count,
stats.mean,
stats.mode,
stats.median,
species_max.name,
species_max.unaligned_fasta_sequence_counts.sum
]
end
}
puts Benchmark.measure {
Occurrence.where(species_aligned: true).distinct.pluck(:taxon_phylum).each do |taxon_phylum|
species = Occurrence.where(taxon_phylum: taxon_phylum).where(species_aligned: true).distinct.pluck(:species_path)
seqs = species.map {|p| Species.new(Configuration.genbank_root.join(p)).unaligned_fasta_sequence_counts }.flatten
stats = DescriptiveStatistics::Stats.new(seqs.sort)
species_max = species.map {|p| Species.new(Configuration.genbank_root.join(p)) }.max { |a,b|
a.unaligned_fasta_sequence_counts.sum <=> b.unaligned_fasta_sequence_counts.sum
}
records << [
"taxon_phylum",
taxon_phylum,
species.count,
stats.mean,
stats.mode,
stats.median,
species_max.name,
species_max.unaligned_fasta_sequence_counts.sum
]
end
}
puts Benchmark.measure {
Occurrence.where(species_aligned: true).distinct.pluck(:taxon_kingdom).each do |taxon_kingdom|
species = Occurrence.where(taxon_kingdom: taxon_kingdom).where(species_aligned: true).distinct.pluck(:species_path)
seqs = species.map {|p| Species.new(Configuration.genbank_root.join(p)).unaligned_fasta_sequence_counts }.flatten
stats = DescriptiveStatistics::Stats.new(seqs.sort)
species_max = species.map {|p| Species.new(Configuration.genbank_root.join(p)) }.max { |a,b|
a.unaligned_fasta_sequence_counts.sum <=> b.unaligned_fasta_sequence_counts.sum
}
records << [
"taxon_kingdom",
taxon_kingdom,
species.count,
stats.mean,
stats.mode,
stats.median,
species_max.name,
species_max.unaligned_fasta_sequence_counts.sum
]
end
}
CSV.open("report.csv", "wb") do |csv|
records.each do |record|
csv << record
end
end