Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- finp = file.open(file,"r")
- fout = file.open(file2,"w")
- header = finp.gets
- headerext = ("\t" + "mR_Int_Score_Count" + "\t" + "mR_Int_Score_TotalEnergy" + "\t" + "mR_Int_Score_Total_miRsvr")
- fout.write(header.delete("\n") + headerext + "\n")
- while line = finp.gets #dla kazdej linii z pliku finp
- line =~ /^.*?\t(.*?)\t.*?\t.*?\t.*?\t(.*?)\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t(.*?)\t(.*?)\t.*?\t.*?\n/
- mirna = $1 #określ wartości w kluczowych kolumnach
- transcript = $2
- energy = $3.to_i
- mirsvr = $4.to_i
- totenergy = totenergy + energy #zacznij sumować te wartości
- totmirsvr = totmisvr + mirsvr
- count = count+1
- while refline = finp.gets #poszukaj podobnej linii (o takich samych wartościach w 2. i 6. kolumnie)
- refline =~ /^.*?\t(.*?)\t.*?\t.*?\t.*?\t(.*?)\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\n/
- refmirna = $1
- reftranscript = $2
- if ((refmirna == mirna) and (reftranscript == transcript)) #jezeli linie sobie odpowiadaja, to kontynuuj sumowanie wartosci
- totenergy = totenergy + energy
- totmirsvr = totmisvr + mirsvr
- count = count +1
- end
- finp.rewind #przewind do początku
- while refline = finp.gets #zapisz wszystkie podobne linie z nowymi kolumnami (count, totenergy, totmirsvr)
- refline =~ /^.*?\t(.*?)\t.*?\t.*?\t.*?\t(.*?)\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\n/
- refmirna = $1
- reftranscript = $2
- if ((refmirna == mirna) and (reftranscript == transcript)) #jezeli linie sobie odpowiadaja, to zapisz rozszerzoną linię w nowym pliku
- extline = refline.delete("\n") + "\t" + count + "\t" + totenergy + "\t" + totmirsvr + "\n"
- fout.write(extline)
- end
- end
- end
- finp.close
- fout.close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement