Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. program NW
  2. implicit none
  3.  
  4. !Os dois genes a serem analizados:
  5. character (LEN=1000), parameter :: gene1 = "ACG" !LINHA |
  6. character (LEN=1000), parameter :: gene2 = "GC" !COLUNA _
  7. integer, parameter :: m = len_trim(gene1)
  8. integer, parameter :: n = len_trim(gene2)
  9.  
  10. !A matriz a ser trabalhada
  11. real, dimension(n+1,m+1) :: F !F = 4x10
  12.  
  13. !pontuações
  14. integer, parameter :: gap = -4
  15. integer, parameter :: match = 5
  16. integer, parameter :: mismatch = -3
  17.  
  18. !backtrack ou seila o nome
  19. integer :: backt
  20.  
  21. !Variaveis auxiliares
  22. integer :: i = 1
  23. integer :: j = 1
  24. integer :: escolha1
  25. integer :: escolha2
  26. integer :: escolha3
  27.  
  28. !TEMPO
  29. real*4 :: tempo
  30.  
  31. tempo = SECNDS(0.0)
  32.  
  33. !Preenchendo a F
  34. ! i =1
  35. do i =1, n+1
  36. F(i,1) = (i-1)*gap
  37. end do
  38. ! j = 1
  39. do j = 1, m+1
  40. F(1,j) = (j-1)*gap
  41. end do
  42. ! Todo o resto da F
  43. do i=2, n+1
  44. do j=2, m+1
  45. if (gene1(j-1:j-1) == gene2(i-1:i-1)) then
  46. escolha1 = F(i-1,j-1) + match
  47. else
  48. escolha1 = F(i-1,j-1) + mismatch
  49. end if
  50. escolha2 = F(i-1,j) + gap
  51. escolha3 = F(i,j-1) + gap
  52. F(i,j) = max(escolha1, escolha2, escolha3)
  53. end do
  54. end do
  55.  
  56. i = i-1
  57. j = j-1
  58.  
  59. backt = 0
  60.  
  61. do while ((i >= 1 .AND. j >= 1) .AND. .NOT.(i == j .AND. j == 1))
  62. if (gene1(j-1:j-1) == gene2(i-1:i-1)) then
  63. escolha1 = F(i-1,j-1) + match
  64. else
  65. escolha1 = F(i-1,j-1) + mismatch
  66. end if
  67. escolha2 = F(i-1,j) + gap
  68. escolha3 = F(i,j-1) + gap
  69.  
  70. if (max(escolha1, escolha2, escolha3) == escolha1) then
  71. if (gene1(j-1:j-1) == gene2(i-1:i-1)) then
  72. backt = backt + match
  73. else
  74. backt = backt + mismatch
  75. end if
  76.  
  77. i = i-1
  78. j = j-1
  79. else if (max(escolha1, escolha2, escolha3) == escolha2) then
  80. backt = backt + gap
  81.  
  82. i = i-1
  83. else
  84. backt = backt + gap
  85.  
  86. j = j-1
  87. end if
  88. end do
  89.  
  90. !Arquivo para ser lido porque a formatação do fortran é mt ruim
  91.  
  92. tempo = SECNDS(tempo)
  93.  
  94. !print
  95. print *,"O backtrack eh: ", backt
  96. print *,"O tempo eh: ", tempo
  97.  
  98.  
  99. end program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement