Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. program SW
  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. integer :: max_i = 0
  28. integer :: max_j = 0
  29.  
  30.  
  31. !TEMPO
  32. real*4 :: tempo
  33.  
  34. tempo = SECNDS(0.0)
  35. !Preenchendo a F
  36. ! i =1
  37. do i =1, n+1
  38. F(i,1) = 0
  39. end do
  40. ! j = 1
  41. do j = 1, m+1
  42. F(1,j) = 0
  43. end do
  44. ! Todo o resto da F
  45. do i=2, n+1
  46. do j=2, m+1
  47. if (gene1(j-1:j-1) == gene2(i-1:i-1)) then
  48. escolha1 = F(i-1,j-1) + match
  49. else
  50. escolha1 = F(i-1,j-1) + mismatch
  51. end if
  52. escolha2 = F(i-1,j) + gap
  53. escolha3 = F(i,j-1) + gap
  54. F(i,j) = max(escolha1, escolha2, escolha3, 0)
  55. end do
  56. end do
  57.  
  58. escolha1 = 0
  59.  
  60. do max_i=2, n+1
  61. do max_j=2, m+1
  62. if (F(max_i, max_j) > escolha1) then
  63. escolha1 = F(max_i, max_j)
  64.  
  65. i = max_i
  66. j = max_j
  67. end if
  68. end do
  69. end do
  70.  
  71. backt = 0
  72.  
  73. do while ((i >= 1 .AND. j >= 1) .AND. .NOT.(i == j .AND. j == 1))
  74. if (gene1(j-1:j-1) == gene2(i-1:i-1)) then
  75. escolha1 = F(i-1,j-1) + match
  76. else
  77. escolha1 = F(i-1,j-1) + mismatch
  78. end if
  79. escolha2 = F(i-1,j) + gap
  80. escolha3 = F(i,j-1) + gap
  81.  
  82. if (max(escolha1, escolha2, escolha3) == escolha1) then
  83. if (gene1(j-1:j-1) == gene2(i-1:i-1)) then
  84. backt = backt + match
  85. else
  86. backt = backt + mismatch
  87. end if
  88.  
  89. i = i-1
  90. j = j-1
  91. else if (max(escolha1, escolha2, escolha3) == escolha2) then
  92. backt = backt + gap
  93.  
  94. i = i-1
  95. else
  96. backt = backt + gap
  97.  
  98. j = j-1
  99. end if
  100. end do
  101.  
  102. !Arquivo para ser lido porque a formatação do fortran é mt ruim
  103.  
  104. tempo = SECNDS(tempo)
  105.  
  106. !print
  107. print *,"O backtrack eh: ", backt
  108. print *,"O tempo eh: ", tempo
  109.  
  110.  
  111. end program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement