Advertisement
mjktfw

Untitled

Oct 19th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.79 KB | None | 0 0
  1. finp = file.open(file,"r")
  2. fout = file.open(file2,"w")
  3.  
  4. header = finp.gets
  5. headerext = ("\t" + "mR_Int_Score_Count" + "\t" + "mR_Int_Score_TotalEnergy" + "\t" + "mR_Int_Score_Total_miRsvr")
  6. fout.write(header.delete("\n") + headerext + "\n")
  7.  
  8. while line = finp.gets  #dla kazdej linii z pliku finp
  9.    
  10.     line =~ /^.*?\t(.*?)\t.*?\t.*?\t.*?\t(.*?)\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t(.*?)\t(.*?)\t.*?\t.*?\n/
  11.    
  12.     mirna = $1          #określ wartości w kluczowych kolumnach
  13.     transcript = $2
  14.     energy = $3.to_i
  15.     mirsvr = $4.to_i
  16.    
  17.     totenergy = totenergy + energy  #zacznij sumować te wartości
  18.     totmirsvr = totmisvr + mirsvr
  19.     count = count+1
  20.        
  21.     while refline = finp.gets #poszukaj podobnej linii (o takich samych wartościach w 2. i 6. kolumnie)
  22.        
  23.         refline =~ /^.*?\t(.*?)\t.*?\t.*?\t.*?\t(.*?)\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\n/
  24.        
  25.         refmirna = $1
  26.         reftranscript = $2
  27.        
  28.         if ((refmirna == mirna) and (reftranscript == transcript))  #jezeli linie sobie odpowiadaja, to kontynuuj sumowanie wartosci
  29.        
  30.             totenergy = totenergy + energy
  31.             totmirsvr = totmisvr + mirsvr
  32.             count = count +1
  33.        
  34.         end
  35.        
  36.     finp.rewind     #przewind do początku
  37.    
  38.     while refline = finp.gets   #zapisz wszystkie podobne linie z nowymi kolumnami (count, totenergy, totmirsvr)
  39.        
  40.         refline =~ /^.*?\t(.*?)\t.*?\t.*?\t.*?\t(.*?)\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\n/
  41.        
  42.         refmirna = $1
  43.         reftranscript = $2
  44.        
  45.         if ((refmirna == mirna) and (reftranscript == transcript))  #jezeli linie sobie odpowiadaja, to zapisz rozszerzoną linię w nowym pliku
  46.        
  47.             extline = refline.delete("\n") + "\t" + count + "\t" + totenergy + "\t" + totmirsvr + "\n"
  48.        
  49.             fout.write(extline)
  50.        
  51.         end
  52.  
  53.     end
  54.    
  55. end
  56.  
  57. finp.close
  58. fout.close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement