Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.48 KB | None | 0 0
  1. #make an array [["chrN", start, expression]]
  2. def profile_array(array, lines)
  3.     lines.each do |line|
  4.         line = line.split()
  5.         chr = line[0]
  6.         start = line[1].to_i
  7.         expression = line[4].to_i
  8.         array.push([chr, start, expression])
  9.     end
  10.     return array
  11. end
  12.  
  13. #make an array of peaks segments[["chrN", start of segment, end of segment]]
  14. def array_of_peaks(arr, lines)
  15.     lines.each do |line|
  16.         chr = line.split(":")[0]
  17.         start = (line.split(":")[1].split("..")[0]).to_i
  18.         fin = (line.split(":")[1].split("..")[1].split(",")[0]).to_i
  19.         arr.push([chr, start, fin])
  20.     end
  21.     return arr
  22. end
  23.    
  24. #take lines that correspond to certain chr
  25. def choose_chr(profile, profile_chr)
  26.     profile.each do |el|
  27.         if el[0] == "chr1"
  28.             profile_chr.push(el)
  29.         end
  30.     end
  31.     return profile_chr
  32. end
  33.  
  34. #make an array with array[index] = 0 if index doesn't lie in segment
  35. #start and fin - places where chr "starts" and "ends" respectively
  36. #for chr1 start = 564473, end = 249214301
  37. def make_chr_array(profile_chr, start, fin)
  38.     indexed_profile = Array.new(start - 1) {0}
  39.     for index in start...fin
  40.         profile_chr.each do |el|
  41.             if index == el[1]
  42.                 indexed_profile.push(el[2])
  43.             else
  44.                 indexed_profile.push(0)
  45.             end
  46.         end
  47.     end
  48.     return indexed_profile
  49. end
  50.        
  51.  
  52. file = File.open('file', 'r')
  53. lines = file.readlines()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement