Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def mean_std_dev(arr,n)
- sum=0
- mean = arr.inject{|sum,x| sum + x } / n.to_f
- total=0
- [mean, Math.sqrt(arr.inject{|total,x| total + ((mean-x)*(mean-x)) } / n.to_f) ]
- end
- def percentile_depths(arr,n,pct)
- samples_in_percentile = (n * pct).floor
- (arr.sort.reverse.slice(0,samples_in_percentile)).min
- end
- def depth_percentages(arr,n)
- more_than_n = 0
- arr.each do |depth|
- more_than_n = more_than_n + 1 if depth >= n
- end
- more_than_n.to_f / arr.size
- end
- prev=nil
- File.open("depths.tsv") do |file|
- file.each do |line|
- #puts line.slice(0,100)
- next if line =~ /^#.*/
- fields = line.chomp.split("\t")
- next if [ fields[0], fields[1] ] == prev
- depths = []
- 8.upto(fields.size-1) do |i|
- depths << ((fields[i].split(/:/))[1]).to_i
- end
- depth_mean = mean_std_dev(depths,depths.size)
- puts "#{fields[0]} #{fields[1]} #{fields[2]} #{depth_mean[0]} #{depth_mean[1]} " +
- percentile_depths(depths,depths.size,0.99).inspect + " " +
- percentile_depths(depths,depths.size,0.95).inspect + " " +
- depth_percentages(depths,20).inspect + " " +
- depth_percentages(depths,1).inspect
- prev = [fields[0], fields[1]]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement