• Nenhum resultado encontrado

A tabela 7.1 mostra o desempenho obtido na prototipa¸c˜ao, comparado ao de outras solu¸c˜oes publicadas. A tabela est´a ordenada por ordem crescente de desempenho. A coluna “plataforma” pode conter os valores: software (solu¸c˜ao somente em software), FPGA (arquitetura reconfigur´avel), ASIC (chip espec´ıfico para aplica¸c˜ao), GPU (processadores gr´aficos) ou SIMD (instru¸c˜oes vetoriais em processadores de uso geral) .

TABELA 7.1: Desempenho comparado - ordem crescente de desempenho

Desemp. Desemp. Descri¸c˜ao Plataforma absoluto relativo Intel Xeon 2.6 GHz(HARPER, 2007) Software 53 MCUPS 0,001

Pentium III 500 MHz (ROGNES; SEEBERG, 2000) SIMD 150 MCUPS 0,003 The UCSC Kestrel Parallel Processor (BLAS et al.,

2005). Resultados de 1997

ASIC 400 MCUPS 0,008 8 Pentium III 600 MHz (ROGNES; SEEBERG,2000) SIMD 1,5 GCUPS 0,03 Hyperseq. V´arios m´odulos de hardware. Conside-

rando alinhamentos com espa¸cos (HARPER, 2007)

FPGA 2,8 GCUPS 0,056 Striped SmithWaterman speeds database searches

six times ... (FARRAR, 2007). Instru¸c˜oes Intel SSE2

SIMD 3 GCUPS 0,06 PheGee (SINGH et al., 2007). Grid de desktops com

10 GPUS NVIDIA GeForce

GPU 4,5 GCUPS 0,09 SWBoost: Smith-Waterman Boost (GENBOOST,

2007)

GPU 5-10 GCUPS 0,1 Cray XD1 (STRENSKI, 2005) FPGA 5-15 GCUPS 0,1 Hyper Customized Processors for ... (OLIVER; SCH-

MIDT; MASKELL,2005). Penalidade affine de espa¸cos

FPGA 7,6 GCUPS 0,152 Cell - CLC Bionformatics (BIOINFORMATICS, 2007)

. Intel SSE2

SIMD 9,3 GCUPS 0,186 Cadeias ocultas de Markov (JACOB et al.,2007) FPGA 10 GCUPS 0,2 Families of FPGA-based accelerators for ... (COURT;

HERBORDT, 2006). 2 Virtex II Pro

FPGA 13 GCUPS 0,26 Hyper Customized Processors for Bio-Sequence Da-

tabase Scanning on FPGAs (OLIVER; SCHMIDT; MAS- KELL, 2005). Penalidade linear de espa¸cos

FPGA 13,9 GCUPS 0,278

Nios mais instru¸c˜ao customizada (1.000.000 c´elulas). Desempenho estimado (LI; SHUM; TRUONG,2007)

FPGA 23,8 GCUPS 0,476 Cadeias ocultas de Markov (MADDIMSETTY, 2006) FPGA 34,4 GCUPS 0,688 Splash-2 (WOO et al., 1995). 16 placas cada com 17

Xilinx XC4010

FPGA 43 GCUPS 0,86 Prototipa¸c˜ao da proposta deste trabalho FPGA 50 GCUPS 1 A Smith-Waterman Systolic Cell (YU et al., 2003).

Virtex XCV1000E via SDRAM (m´odulo Pilchard)

FPGA 136 GCUPS 2,72 Hyperseq. V´arios m´odulos de hardware. N˜ao consi-

dera alinhamentos com espa¸cos (HARPER, 2007)

FPGA 139 GCUPS 2,78 Gene Matching Using JBits (GUCCIONE; KELLER,

2007). 4000 processadores de 2 bits. Virtex XCV1000

FPGA 750 GCUPS 15 Hookiegene (PUTTEGOWDA et al., 2003). Placa OSI-

RIS com 2 Virtex II. 7000 processadores de 2 bits

FPGA 1260 GCUPS 25,2 Bioinformatics case study from the CAPSL Labora-

tory (ZHANG; TAN; GAO,2007). M´odulo XtremeData XD1000: Stratix II via AMD HyperTransport

FPGA 2048 GCUPS 40,96

Gene Matching Using JBits (GUCCIONE; KELLER,

2007). Estimados 11000 processadores (2 bits) se usada Virtex II XC2V6000. Desempenho estimado

8 Conclus˜ao

O volume de informa¸c˜oes em bancos-de-dados biol´ogicos tem crescido mais do que os recursos computacionais dispon´ıveis, desafiando a bionform´atica a apre- sentar t´ecnicas cada vez mais eficientes de processamento destes dados. Uma das opera¸c˜oes mais importantes na bionform´atica ´e o alinhamento de seq¨uˆencias. O algoritmo de alinhamento local de Smith-Waterman ´e o que apresenta os me- lhores resultados, mas sua complexidade de tempo quadr´atica tem impedido o uso em larga escala. Algoritmos heur´ısticos, apesar de n˜ao serem exatos, tˆem freq¨uentemente sido usados nesses casos.

Neste trabalho, foi apresentada uma abordagem baseada em hardware re- configur´avel dedicado para reduzir a complexidade de tempo do algoritmo de Smith-Waterman. O paralelismo potencial ´e explorado por um arranjo sist´olico de elementos de processamento em um ´unico chip. Um gargalo de comunica¸c˜ao previsto ´e evitado, selecionando-se ainda em hardware os alinhamentos que mais interessam. O alinhamento ´otimo e outros “bons” alinhamentos - os m´aximos por coluna da matriz - s˜ao comunicados ao meio externo e podem ser reconstru´ıdos por software.

A prototipa¸c˜ao foi realizada em FPGA, usando um Altera Stratix II S60. Foi poss´ıvel implementar 636 elementos de processamento, a uma freq¨uencia m´axima de opera¸c˜ao de 78 MHz, resultando em um desempenho de aproximadamente 50 GCUPS.

Numa continua¸c˜ao deste projeto, poderia ser feita a integra¸c˜ao do hardware dedicado descrito com um microcomputador. O padr˜ao de comunica¸c˜ao de dados mais comumente usado nestes casos ´e o PCI, apesar de existirem m´odulos com FPGA e conectores de outros padr˜oes, inclusive com desempenho superior (YU et al.,2003) (ZHANG; TAN; GAO, 2007). Poderia ser criado um cluster ou um grid de microcomputadores com hardware dedicado acoplado.

Outros projetos poderiam abranger o problema da divis˜ao de um alinhamento de seq¨uˆencias, para execu¸c˜ao do algoritmo de alinhamento por partes. Devido a insuficiˆencia de recursos no chip, nem sempre ´e poss´ıvel que toda a seq¨uˆencia de consulta seja comparada de uma s´o vez. Neste caso, as seq¨uˆencias devem ser par- ticionadas, os problemas parciais solucionados e as solu¸c˜oes parciais combinadas, obtendo-se a solu¸c˜ao final. Visto a limita¸c˜ao do espa¸co em chip, o desenvolvi- mento deste mecanismo de particionamento do problema ´e importante para o uso pr´atico de solu¸c˜oes como a apresentada neste trabalho.

O objetivo de ajudar a viabilizar o uso de algoritmos exatos para alinhamento de seq¨uˆencias foi alcan¸cado, visto o ganho de desempenho observado. A acelera- ¸c˜ao em rela¸c˜ao a uma solu¸c˜ao somente em software foi cerca de 1.000. O uso de arquiteturas reconfigur´aveis confirmou ser de grande utilidade para a acelera¸c˜ao do alinhamento de seq¨uˆencias e de outros algoritmos de programa¸c˜ao dinˆamica.

Referˆencias Bibliogr´aficas

AMD. AMD (Advanced Micro Technologies), divis˜ao graphics and v´ıdeo processors (antiga ATI). 2007. Dispon´ıvel em:

<http://www.ati.amd.com/>. Acesso em: 2007.

BIOINFORMATICS, C. Cell. 2007. Dispon´ıvel em: <http://www.clccell.com>. Acesso em: 2007.

BIOLOGIA Molecular: O que ´e biologia molecular. 2006. Dispon´ıvel em:

<http://www.biomol.org/>. Acesso em: 2006.

BLAS, A. D.; DAHLE, D. M.; DIEKHANS, M.; GRATE, L.; HIRSCHBERG, J. The ucsc kestrel parallel processor. IEEE TRANSACTIONS ON

PARALLEL AND DISTRIBUTED SYSTEMS, v. 16, n. 1, 2005. BLAST: Ncbi (national center for biotechnology information) - blast (basic alignment sarch tool). 2006. Dispon´ıvel em:

<http://www.ncbi.nlm.nih.gov/BLAST/>. Acesso em: 2006.

BYUN, J.-H. A Scalable Multi-FPGA Network System for Gene

Sequencing. Disserta (Mestrado) — University of North Carolina at Charlote, USA, 2005.

CARVALHO, L. G. A. Uma Abordagem em Hardware para Algoritmos de Compara¸c˜ao de Seq¨uˆencias Baseados em Programa¸c˜ao ao

Dinˆamica. Disserta (Mestrado) — Universidade de Bras´ılia, 2003.

COMISSION, E. Prospective analysis of the relationship and synergy between medical informatics (mi) and bioinformatics (bi). White paper EC-IST, v. 35024, 2001.

CORPORATION, N. NVidia. 2007. Dispon´ıvel em:

<http://www.nvidia.com/>. Acesso em: 2007.

COURT, T. V.; HERBORDT, M. C. Families of fpga-based accelerators for approximate string matching. 2006. Dispon´ıvel em:

(EBI), E. B. I. UniProtKB/TrEMBL PROTEIN DATABASE. 2007. Dispon´ıvel em: <http://www.ebi.ac.uk/swissprot/sptrrline stats/index.html>. Acesso em: 2007.

FARRAR, M. Striped smithwaterman speeds database searches six times over other simd implementations. Bioinformatics, v. 23, n. 2, p. 156–161, 2007. Dispon´ıvel em: <http://farrar.michael.googlepages.com/Smith-waterman>. FASTA: Fasta sequence comparison at the university of virginia. 2006. Dispon´ıvel em: <http://fasta.bioch.virginia.edu/>. Acesso em: 2006.

GENBANK. GenBank Statistics: Estat´ısticas do genbank. 2006. Dispon´ıvel em: <http://www.ncbi.nlm.nih.gov/Genbank/genbankstats.html>. Acesso em: 2006.

GENBOOST. SWBoost (Smith-Waterman Boost). 2007. Dispon´ıvel em:

<http://www.genboost.com/>. Acesso em: 2007.

GOTOH. An improved algorithm for matching biological sequences. J. Mol. Biol., v. 162, p. 705–708, 1982.

GUCCIONE, S. A.; KELLER, E. Gene matching using jbits. Xilinx Inc., 2007.

HARPER, S. Accelerating Smith-Waterman Alignment with the HyperSeqTM System. [S.l.], 2007. Dispon´ıvel em: <http://www-

.adaptivegenomics.com/pdf/Accelerating Smith-Waterman Processing.pdf>. Acesso em: 2007.

HOANG, D. T. A Systolic Array for the Sequence Alignment Problem. [S.l.], 1992. Dispon´ıvel em: <citeseer.ist.psu.edu/hoang92systolic.html>.

JACOB, A.; LANCASTER, J.; BUHLER, J.; CHAMBERLAIN, R. D. Preliminary results in accelerating profile hmm search on fpgas. In: Proceedings of 6th IEEE International Workshop on High

Performance Computational Biology, ACM symposium on Applied computing. [S.l.: s.n.], 2007.

KUNG, H.; LEISERSON. Systolic arrays for vlsi sparse matrix. In:

Proceedings of the Society for Industrial and Applied Mathematics. Santa Monica, CA, USA: [s.n.], 1979. p. 256–282.

LAVENIER, D. SAMBA : Systolic Accelerator for Molecular Biological Applications. [S.l.], 1998. 22 p. p. Dispon´ıvel em:

REFERˆENCIAS BIBLIOGR ´AFICAS 101 LEONG, P.; LEONG, M.; CHEUNG, O.; TUNG, T.; KWOK, C.; WONG, M.;

LEE., K. H. Pilchard - a recongurable computing platform with memory slot interface. In: Proceedings of the IEEE Symposium on

Field-Programmable Custom Computing Machines. [S.l.: s.n.], 2001. LI, I. T.; SHUM, W.; TRUONG, K. 160-fold acceleration of the

smith-waterman algorithm using a field programmable gate array (fpga). BMC Bioinformatics, v. 8, p. 185, 2007.

LIPTON, R.; LOPRESTI, D. A systolic array for rapid string comparison. In: Chapel Hill Conference on VLSI, Chapel Hill, NC, USA. [S.l.: s.n.], 1985. p. 363–376.

MADDIMSETTY, R. P. ACCELERATION OF PROFILE-HMM SEARCH FOR PROTEIN SEQUENCES IN RECONFIGURABLE HARDWARE. Disserta (Mestrado) — Henry Edwin Sever Graduate School of Washington University, Saint Louis, Missouri, USA, 2006.

MENG, X.; CHAUDHARY, V. An adaptive data prefetching scheme for biosequence database search on reconfigurable platforms. In: Proceedings of the 2007 ACM symposium on Applied computing. [S.l.: s.n.], 2007. p. 140–141.

MYERS; W., E.; MILLER, W. Optimal alignments in linear space. Computer Applications in the Biosciences, v. 4, p. 11–17, 1988.

NEEDLEMAN S. B. E WUNSCH, C. D. A general method applicable to the search for similarities in the amino acid sequence of two proteins. p. 443–453, 1970.

OLIVER, T.; SCHMIDT, B.; MASKELL, D. Hyper customized processors for bio-sequence database scanning on fpgas. In: Proceedings of the

ACM/SIGDA 13th International Symposium on Field Programmable Gate Arrays, FPGA, Monterey, California, USA. [S.l.: s.n.], 2005.

PUTTEGOWDA, K.; WOREK, W.; PAPPAS, N.; DANDAPANI, A.;

ATHANAS, P. A run-time recongurable system for gene-sequence searching. In: Proceedings of the International VLSI Design Conference. [S.l.: s.n.], 2003.

ROGNES, T.; SEEBERG, E. Six-fold speed-up of smith-waterman sequence databases searches using parallel processing on common microprocessors. Bioinformatics, v. 16, n. 8, p. 699–706, 2000. Dispon´ıvel em:

SETUBAL, J.; MEIDANIS, J. Introduction to computational molecular biology. PWS Pub, 1991.

SETUBAL, J. C.; MEIDANIS. J. Computational Molecular Biology, 1997. SINGH, A.; CHEN, C.; LIU, W.; MITCHELL, W.; SCHMIDT, B. Phegee: Phenotype genotype exploration on a desktop gpu grid. 2007.

SINGH, R.; DETTLO, W.; CHI, V.; HO, D.; TELL m; WHITE, C.;

ALTSCHUL, S.; ERICKSON, B. BioSCAN: A dynamically reconfigurable systolic array for biosequence analysis. Dispon´ıvel em:

<citeseer.ist.psu.edu/163511.html>.

SMITH, T.; WATERMAN, M. Identification of common molecular subsequences. J. Mol. Biol, v. 147, p. 195–197, 1981.

SOLUTIONS, T. B. Decypher. 2007. Dispon´ıvel em:

<http://timelogic.com/decypher intro.html>. Acesso em: 2007.

STRENSKI, D. The cray xd1 computer and its reconfigurable architecture. 2005. Dispon´ıvel em:

<http://www.ncsa.uiuc.edu/Conferences/RSSI/2005/docs/Strenski.ppt>. TRELLES, O. On the parallelization of bioinformatic applications. 2001. VOSS, G.; SCHR¨oDER, A.; M¨uLLER-WITTIG, W.; SCHMIDT, B. Biological sequence alignment on graphics processing units. 2005. Dispon´ıvel em:

<http://www.ntu.edu.sg/home/asbschmidt/paper/BioGPU.pdf>.

WOO, S. C.; OHARA, M.; TORRIE, E.; SINGH, J. P.; GUPTA., A. The splash-2 (stanford parallel applications for shared memory) programs:

Characterization and methodological considerations. In: In Proceedings of the 22nd International Symposium on Computer Architecture. Santa Monica, CA, USA: [s.n.], 1995. p. 24–36. Dispon´ıvel em:

<ftp://www-flash.stanford.edu/pub/splash2/splash2isca95.ps.Z>.

XTREMEDATA. Xd1000 fpga coprocessor module for socket 940. 2007.

Dispon´ıvel em: <http://www.capsl.udel.edu/pub/doc/memos/memo078.pdf>. YAMAGUCHI, Y.; MARUYAMA, T.; KONAGAYA, A. High Speed

Homology Search with FPGAs. Dispon´ıvel em: <citeseer.ist.psu.edu/yamaguchi02high.html>.

YANG, B. H. W. A parallel implementation of Smith-Waterman sequence comparison algorithm. [S.l.], 2002.

REFERˆENCIAS BIBLIOGR ´AFICAS 103 YU, C.; KWONG, K.; LEE, K.; LEONG, P. A smith-waterman systolic cell. In:

13th International Conference on Field-Programmable Logic and Applications. Springer-Verlag LNCS. Lisboa, Portugal: [s.n.], 2003. p. 2778:375–384.

ZHANG, P.; TAN, G.; GAO, G. R. Implementation of the smith-waterman algorithm on a reconfigurable supercomputing platform. 2007. Dispon´ıvel em:

Anexo A - Descri¸c˜ao do

hardware em Verilog

A.1

Componente de mais alto n´ıvel da aplica¸c˜ao

‘ i n c l u d e ”p a r a m e t r o s . v ” module top

(

input c l k i , input r e s e t i ,

output max pronto o , input max proximo i , output [ ‘SCORE MAX BITS− 1 : 0 ] max o ,

output [ ‘SEQ C TAM BITS DEF − 1 : 0 ] ma x c o l o ,

output [ ‘CLK TICKS MAX BITS − 1 : 0 ] m a x c l k t i c k s o , output f i m bb d o ,

// i n f o r m a p r o g r e s s o da e n t r a d a para e x i b i c a o output [ 7 : 0 ] b b d f a l t a m s b o

) ;

// S e q u e n c i a de c o n s u l t a − d e f i n i d a em p a r a m e t r o s . v localparam SEQ C = ‘SEQ C DEF ;

localparam SEQ C TAM = ‘SEQ C TAM DEF ;

localparam SEQ C TAM BITS = ‘SEQ C TAM BITS DEF ; // S e q u e n c i a do banco de d a d o s

ANEXO A. DESCRI ¸C ˜AO DO HARDWARE EM VERILOG 105 localparam SEQ BD TAM = ‘SEQ BD TAM DEF ;

localparam SEQ BD TAM BITS = ‘SEQ BD TAM BITS DEF ;

// memoria ROM onde e s t a r a a s e q u e n c i a do banco de d a d o s // cada b y t e ( 8 b i t s ) pode c o n t e r a t e h 4 b a s e s ( 2 b i t s ) localparam ROM SIZE = ‘ROM SIZE DEF ;

localparam ROM SIZE BITS = ‘ROM SIZE BITS DEF ; /∗ ∗ A c r e s c e n t a um c i c l o de a t r a s o , p e r m i t i n d o que s i s t o l i c o i n p u t ∗ e s t e j a um c i c l o a d i a n t e do s i s t o l i c o , gerando e n t r a d a s ∗ c o r r e t a m e n t e ∗/ reg r e s e t r ;

always @(‘CLOCK EDGE PRINCIPAL c l k i ) r e s e t r <= r e s e t i ; // s i n a i s s i s t o l i c o i n p u t −> s i s t o l i c o

wire [ 1 : 0 ] bbd w ; wire fim bbd w ;

// e n t r a d a do s i s t o l i c o , b a s e s do banco de d a d o s s i s t o l i c o i n p u t

#(

. SEQ BD TAM(SEQ BD TAM) , . SEQ BD TAM BITS(SEQ BD TAM BITS ) , . ROM SIZE BITS ( ROM SIZE BITS )

) s i s t o l i c o i n p u t 1 ( . c l k i ( c l k i ) , . r e s e t i ( r e s e t i ) , . bbd o ( bbd w ) , // b a s e s para o s i s t o l i c o . f i m b b d o ( fim bbd w ) , // s i n a l i z a f i n a l d a s b a s e s . b b d f a l t a m s b o ( b b d f a l t a m s b o ) // p e x i b i c a o do p r o g r e s s o ) ; assign f i m b b d o = fim bbd w ; // s i n a i s s i s t o l i c o −> s i s t o l i c o o u t p u t wire m a x i n i c i o w ;

wire [ ‘SCORE MAX BITS− 1 : 0 ] max w ;

wire [ ‘CLK TICKS MAX BITS − 1 : 0 ] m a x c l k t i c k s w ; // a r r a n j o s i s t o l i c o de e l e m e n t o s de p r o c e s s a m e n t o

s i s t o l i c o

#( . SEQ C TAM(SEQ C TAM) , . SEQ C(SEQ C) ) s i s t o l i c o 1

. c l k i ( c l k i ) , . r e s e t i ( r e s e t r ) ,

// e n t r a d a s : b a s e s do banco de d a d o s e s i n a l f i m d a s b a s e s . b b d i ( bbd w ) , . f i m b b d i ( fim bbd w ) ,

// s a i d a : maximos de cada c o l u n a e tempo de p r o d u c a o d e s t e s . m a x i n i c i o o ( m a x i n i c i o w ) ,

. max o ( max w ) , . m a x c l k t i c k s o ( m a x c l k t i c k s w ) ) ;

// f i o s s i s t o l i c o o u t p u t −> p o r t a de e s c r i t a da RAM wire ram wen w ; wire [ SEQ C TAM BITS− 1 : 0 ] ram waddr w ;

wire [ ‘SCORE MAX BITS+‘CLK TICKS MAX BITS − 1 : 0 ] r a m d a t a i n w ; // f i o s s i s t o l i c o o u t p u t −> a p r e s e n t m a x

wire m a x g l o b a l p r o n t o w ; wire [ ‘SCORE MAX BITS− 1 : 0 ] m ax g l o b a l w ; s i s t o l i c o o u t p u t

#(

// l e SEQ C TAM maximos l o c a i s de max i . SEQ C TAM(SEQ C TAM) ,

. SEQ C TAM BITS(SEQ C TAM BITS) ) s i s t o l i c o o u t p u t 1 ( . c l k i ( c l k i ) , . r e s e t i ( r e s e t i ) , // s i n a i s v i n d o s do s i s t o l i c o . m a x i n i c i o i ( m a x i n i c i o w ) , . max i ( max w ) , . m a x c l k t i c k s i ( m a x c l k t i c k s w ) , // s i n a i s i n d o para a RAM

. ram wen o ( ram wen w ) , . ram waddr o ( ram waddr w ) , . r a m d a t a o ( r a m d a t a i n w ) , // s i n a i s i n d o para a p r e s e n t m a x . m a x g l o b a l p r o n t o o ( m a x g l o b a l p r o n t o w ) , //maximo e n t r e o s maximos de t o d a s a s c o l u n a s . m a x g l o b a l o ( m a x g l o b a l w ) ) ; // f i o s a p r e s e n t m a x −> p o r t a l e i t u r a RAM wire [ SEQ C TAM BITS− 1 : 0 ] ram raddr w ;

wire [ ‘SCORE MAX BITS+‘CLK TICKS MAX BITS − 1 : 0 ] ram data out w ; a p r e s e n t m a x

#(

. SEQ C TAM BITS(SEQ C TAM BITS ) , // l a r g u r a s a i d a m a x c o l o . RAM SIZE(SEQ C TAM) , // no . p o s i c o e s de memoria a c o n s i d e r a r

ANEXO A. DESCRI ¸C ˜AO DO HARDWARE EM VERILOG 107 . RAM SIZE BITS (SEQ C TAM BITS)

) a p r e s e n t m a x 1 ( . c l k i ( c l k i ) , . r e s e t i ( r e s e t i ) , // de s i s t o l i c o o u t p u t . m a x g l o b a l p r o n t o i ( m a x g l o b a l p r o n t o w ) , . m a x g l o b a l i ( m a x g l o b a l w ) , // para RAM

. ram addr o ( ram raddr w ) , . r a m d a t a i ( ram data out w ) , // p i n o s meio e x t e r n o

. max proximo i ( max proximo i ) , . max pronto o ( max pronto o ) ,

. max o ( max o ) , . m a x c o l o ( m a x c o l o ) , . m a x c l k t i c k s o ( m a x c l k t i c k s o ) ) ; ram ram1 ( . c l o c k ( c l k i ) , // e s c r i t a

. wren ( ram wen w ) , . w r a d d r e s s ( ram waddr w ) , . d at a ( r a m d a t a i n w ) ,

// l e i t u r a

. r d a d d r e s s ( ram raddr w ) , . q ( ram data out w )

) ; endmodule

A.2

Arranjo sist´olico de elementos de processa-

mento

module s i s t o l i c o #( // o p a ra m e tro a b a i x o eh a s e q u e n c i a de c o n s u l t a . Serah // usada para i n s t a n c i a r do e l e m e n t o s de p r o c e s s a m e n t o parameter [ 0 : SEQ C TAM∗2 −1] SEQ C = 1 ’ b0 ,

// tamanho da s e q u e n c i a de c o n s u l t a parameter SEQ C TAM = 0

) (

input c l k i , r e s e t i ,

// b a s e s do banco do d a d o s e s i n a l f i m d a s b a s e s input [ 1 : 0 ] b b d i , input f i m b b d i ,

// s i n a l i n i c i o d o s maximos e maximos l o c a i s com tempo de p r o d u c a o output reg m a x i n i c i o o ,

output [ ‘SCORE MAX BITS− 1 : 0 ] max o ,

output [ ‘CLK TICKS MAX BITS − 1 : 0 ] m a x c l k t i c k s o ) ;

/∗

∗ Cria c o n t a d o r para manter o numero d e s t a a n t i d i a g o n a l

∗ S i n a l s e r v i r a de e n t r a d a para o s i s t o l i c o e para os e l e m e n t o s ∗ de processamento , para e s t e s armazenarem em q u a l tempo

∗ armazenaram s e u s v a l o r e s maximos l o c a i s ∗/

wire c l k t i c k s r e s e t w ;

// r e l o g i o c o n t a numero d e s t a a n t i d i a g o n a l ( c i c l o s a p o s r e s e t ) reg [ ‘CLK TICKS MAX BITS − 1 : 0 ] c l k t i c k s r ;

always @(‘CLOCK EDGE PRINCIPAL c l k i ) c l k t i c k s r <= c l k t i c k s r e s e t w ? 1 ’ b0 : c l k t i c k s r +1 ’ b1 ; reg m a x i n i c i o r ;

always @(‘CLOCK EDGE PRINCIPAL c l k i ) begin

m a x i n i c i o o <= m a x i n i c i o r ; m a x i n i c i o r <= m a x i n i c i o w ; end

/∗

∗ I n s t a n c i a v e t o r de p r o c e s s a m e n t o s i s t o l i c o , ∗ de forma p a r a m e t r i z a d a , v i a g e n e r a t e −f o r

ANEXO A. DESCRI ¸C ˜AO DO HARDWARE EM VERILOG 109 ∗/ assign c l k t i c k s r e s e t w = r e s e t w [ 1 ] ; /∗ ∗ Sao c r i a d o s ” v e t o r e s ” de w i r e s para c o n e c t a r os e l e m e n t o s ∗ de p r o c e s s a m e n t o que s e r a o i n s t a n c i a d o s v i a ” g e n e r a t e f o r ”. ∗ Seguem o diagrama a b a i x o : ∗ ∗ bbd w [ 0 ] −> +−−+ −> bbd w [ 1 ] ... − > +−−+ −>bbd w [ SEQ C TAM ] ∗ v a l o r w [0]−> | 0 0 | −> v a l o r w [ 1 ] . . . − > |YY| −>v a l o r w [ SEQ C TAM ] ∗ r e s e t w [0]−> +−−+ −> r e s e t w [ 1 ] . . . − > +−−+ −>r e s e t w [ SEQ C TAM ]

∗ . . .

∗ Precisamos de SEQ C TAM+1 c o n j u n t o s de cada t i p o de f i o s ∗/

wire r e s e t w [ 0 : SEQ C TAM ] ;

// b a s e do banco de d a d o s e s i n a l de f i m d a s b a s e s

wire [ 1 : 0 ] bbd w [ 0 : SEQ C TAM ] ; wire fim bbd w [ 0 : SEQ C TAM ] ; // v a l o r e s p r o d u z i d o s para cada c e l u l a da m a t r i z

wire [ ‘SCORE MAX BITS− 1 : 0 ] v a l o r w [ 0 : SEQ C TAM ] ;

// s i n a l ” a p r e s e n t a r s e u maximo ” e maximos de cada c o l u n a wire am w [ 0 : SEQ C TAM ] ;

// maximos d a s c o l u n a s

wire [ ‘SCORE MAX BITS− 1 : 0 ] max w [ 0 : SEQ C TAM ] ; // tempos de p r o d u c a o d a q u e l e s maximos

wire [ ‘CLK TICKS MAX BITS − 1 : 0 ] m a x c l k t i c k s w [ 0 : SEQ C TAM ] ; genvar i n d e x ;

generate f o r ( i n d e x = 0 ; i n d e x < SEQ C TAM ; i n d e x = i n d e x + 1 ) begin : g e n e r a t e e p s e p s #( SEQ C [ i n d e x ∗ 2 + : 2 ] ) e p s i n s t a n c i a ( // c l o c k . c l k i ( c l k i ) , // r e s e t . r e s e t i ( r e s e t w [ i n d e x ] ) , . r e s e t o ( r e s e t w [ i n d e x +1] ) , // b a s e do banco de d a d o s . b b d i ( bbd w [ i n d e x ] ) , . bbd o ( bbd w [ i n d e x +1] ) , . f i m b b d i ( fim bbd w [ i n d e x ] ) , . f i m b b d o ( fim bbd w [ i n d e x + 1 ] ) , // v a l o r e s c a l c u l a d o s ( nao i r a o s a i r do s i s t o l i c o ) . c o l i ( v a l o r w [ i n d e x ] ) , . v a l o r o ( v a l o r w [ i n d e x +1] ) , // r e l o g i o . c l k t i c k s i ( c l k t i c k s r ) , // s i n a l c o n t r o l a a p r e s e n t a c a o d o s maximos

. am i ( am w [ i n d e x ] ) , . am o ( am w [ i n d e x +1] ) , // v a l o r e s maximos l o c a i s d a s c o l u n a s . max i ( max w [ i n d e x ] ) , . m a x c l k t i c k s i ( m a x c l k t i c k s w [ i n d e x ] ) , . max o ( max w [ i n d e x +1] ) , . m a x c l k t i c k s o ( m a x c l k t i c k s w [ i n d e x +1] ) ) ; end endgenerate // f i o s c o n e c t a d o s ao p r i m e i r o e l e m e n t o assign r e s e t w [ 0 ] = r e s e t i ; assign bbd w [ 0 ] = b b d i ; // b o r d a da m a t r i z com v a l o r 0 ( r e p r e s e n t a c a o em e x c e s s o de 2 ) assign v a l o r w [ 0 ] = 2 ’ b10 ; // s i n a l f i m da e n t r a d a

assign fim bbd w [ 0 ] = f i m b b d i ; assign am w [ 0 ] = f i m b b d i ; // f i o s c o n e c t a d o s ao u l t i m o e l e m e n t o

wire m a x i n i c i o w = fim bbd w [ SEQ C TAM ] ; // d e s f a z n o t a c a o e x c e s s o de 2

assign max o = max w [ SEQ C TAM] −2 ’ b10 ;

assign m a x c l k t i c k s o = m a x c l k t i c k s w [ SEQ C TAM ] ; endmodule

ANEXO A. DESCRI ¸C ˜AO DO HARDWARE EM VERILOG 111

A.3

Elemento de processamento

module e p s #(

parameter BASE CONSULTA = 2 ’ b00 )

(

input c l k i , input r e s e t i , output reg r e s e t o , // b a s e s do banco de d a d o s

input [ 1 : 0 ] b b d i , output reg [ 1 : 0 ] bbd o , input f i m b b d i , output reg f i m bb d o ,

// v a l o r e s da c e l u l a aa e s q u e r d a e n t r a n d o e . . . input [ ‘SCORE MAX BITS− 1 : 0 ] c o l i ,

// . . . v a l o r d e s t a c e l u l a s a i n d o

output [ ‘SCORE MAX BITS− 1 : 0 ] v a l o r o ,

// r e l o g i o g l o b a l que c o n t a tempo d e c o r r i d o input [ ‘CLK TICKS MAX BITS − 1 : 0 ] c l k t i c k s i , // s i n a l c o n s t r o l a a p r e s e n t a maximos

input am i , output reg am o ,

// i n f o r m a c o e s de maximos l o c a i s , e n t r a n d o e s a i n d o : // p o n t u a c a o e . . .

input [ ‘SCORE MAX BITS− 1 : 0 ] max i , output [ ‘SCORE MAX BITS− 1 : 0 ] max o ,

// . . . a n t i d i a g o n a l ( c o i n c i d e com tempo de p r o d u c a o ) input [ ‘CLK TICKS MAX BITS − 1 : 0 ] m a x c l k t i c k s i , output [ ‘CLK TICKS MAX BITS − 1 : 0 ] m a x c l k t i c k s o ) ;

// i n s t a n c i a sub−modulo que c a l c u l a o v a l o r de cada c e l u l a ( v a l o r o ) e p s c a l c v a l o r #(BASE CONSULTA) e p s c a l c v a l o r 1 (

. c l k i ( c l k i ) , . r e s e t i ( r e s e t i ) , . b b d i ( bbd o ) , . c o l i ( c o l i ) , . v a l o r o ( v a l o r o )

) ;

// i n s t a n c i a sub−modulo que armazena maximo e c o n t r o l e sua e x i b i c a o // o r e s e t i eh l i g a d o ao r e s e t o ( r e g i s t r a d o s r e s e t a d o s

e p s c a l c m a x e p s c a l c m a x 1 (

. c l k i ( c l k i ) , . r e s e t i ( r e s e t o ) , . v a l o r i ( v a l o r o ) , . am i ( am o ) ,

. c l k t i c k s i ( c l k t i c k s i ) , // s i n a l do r e l o g i o g l o b a l . max i ( max i ) , . max o ( max o ) ,

. m a x c l k t i c k s i ( m a x c l k t i c k s i ) , . m a x c l k t i c k s o ( m a x c l k t i c k s o ) ) ;

always @(‘CLOCK EDGE PRINCIPAL c l k i ) r e s e t o <= r e s e t i ;

/∗ O r e g i s t r a d o r b b d o eh c a r r e g a d o com o i n v e r s o b i n a r i o da b a s e ∗ de c o n s u l t a , provocando um mismatch , o que f a z o s c o r e d e c r e s c e r . ∗ Proximo ao r e s e t , i s s o impede a c a r g a de v a l o r e s m a o i r e s que ∗ z e r o nos r e g i s t r a d o r e s . Proximo ao f i n a l das b a s e s , f a z com que ∗ o r e g i s t r a d o r de maximo nao memorize v a l o r g e r a d o apos t e r m i n o ∗ da e n t r a d a ( manter maximo c o r r e t o )

∗/

always @(‘CLOCK EDGE PRINCIPAL c l k i or posedge r e s e t i ) bbd o <= ( r e s e t i | | f i m b b d o ) ? ˜BASE CONSULTA : b b d i ; always @(‘CLOCK EDGE PRINCIPAL c l k i )

f i m b b d o <= f i m b b d i ; /∗ ∗ s i n a l am i ( a p r e s e n t a r maximo ) c o n t r o l a as s a i d a s max o e ∗ m a x c l o c k t i c k s o : ∗ − qdo a t i v o , a p r e s e n t a r n e s t a s s a i d a s o maximo c a l c u l a d o ∗ por e s t e EPS ( c o l u n a )

∗ − qdo i n a t i v o , r e p a s s a r maximo l i d o em max i / m a x c l o c k t i c k s i ∗

∗ Cada EPS c o n t e r a d o i s r e g i s t r a d o r e s , 2 c i c l o s p am i ∗ a t r a v e s s a r cada EPS . Assim , o maximo de cada EPS s a i r a ∗ p e l o e l e m e n t o mais aa d i r e i t a , um apos o o u t r o .

∗/

reg am r ; // c i c l o a d i c i o n a l de a t r a s o e n t r e am i e am o always @(‘CLOCK EDGE PRINCIPAL c l k i )

begin am r <= am i ; am o <= am r ; end endmodule

ANEXO A. DESCRI ¸C ˜AO DO HARDWARE EM VERILOG 113

A.4

Elemento de processamento - subcompo-

nente de c´alculo das pontua¸c˜oes

module e p s c a l c v a l o r #( /∗ Base da s e q u e n c i a de c o n s u l t a que e s t a ∗ a s s o c i a d a a e s t e p r o c e s s a d o r : ∗ C ( 0 0 ) , G ( 0 1 ) , A( 1 0 ) ou T ( 1 1 ) ∗/

parameter BASE CONSULTA = 2 ’ b00 )

(

input c l k i , r e s e t i , input [ 1 : 0 ] b b d i ,

// v a l o r e s da c e l u l a aa e s q u e r d a e n t r a n d o input [ ‘SCORE MAX BITS− 1 : 0 ] c o l i ,

// v a l o r c a l c u l a d o para e s t a c e l u l a s a i n d o output [ ‘SCORE MAX BITS− 1 : 0 ] v a l o r o

) ;

// p e n a l i z a c o e s e s c o l h i d a s

localparam PONT MATCH = 1 ’ b1 , PONT MISMATCH = 1 ’ b1 ; localparam PONT GAP = 2 ’ b10 ;

/∗

∗ R e g i s t r a d o r e s para v a l o r e s das c e l u l a s v i z i n h a s

∗ Usados a s e g u i r no c a l c u l o c o m b i n a c i o n a l d e s t a c e l u l a ∗/

reg [ ‘SCORE MAX BITS− 1 : 0 ] l i n r , c o l r , d i a g r ; always @( negedge c l k i or posedge r e s e t i ) begin

// r e p r e s e n t a c a o em e x c e s s o de 2 i f ( r e s e t i ) begin c o l r <=2; d i a g r <=2; l i n r <=2; end e l s e begin c o l r <=c o l i ; d i a g r <=c o l r ; l i n r <=v a l o r o ; end end /∗ ∗ C a l c u l o c o m b i n a c i o n a l do v a l o r da c e l u l a da m a t r i z , ∗ segundo equacao de r e c o r r e n c i a : ∗ − c a l c u l a d i a g o n a l , l i n h a e c o l u n a com p e n a l i d a d e s ∗ − c a l c u l a maximo e n t r e e s t e s v a l o r e s ∗ − s e v a l o r f o r n e g a t i v o , e s c o l h e 0 como v a l o r f i n a l ∗/

// f i o s para l o g i c a c o m b i n a c i o n a l − v a l o r e s com p e n a l i d a d e s wire [ ‘SCORE MAX BITS− 1 : 0 ] d i a g p = ( b b d i==BASE CONSULTA) ?

d i a g r+PONT MATCH : d i a g r −PONT MISMATCH;

// L o g i c a a l t e r n a t i v a a b a i x o . Em t e s t e s , nao f o i v e r i f i c a d o ganho // w i r e [ ‘SCORE MAX BITS− 1 : 0 ] d i a g p = d i a g r+

// ( ( b b d i==BASE CONSULTA) ? PONT MATCH : −PONT MISMATCH) ; wire [ ‘SCORE MAX BITS− 1 : 0 ] l i n p = l i n r −PONT GAP;

wire [ ‘SCORE MAX BITS− 1 : 0 ] c o l p = c o l r −PONT GAP; // c a l c u l a v a l o r maximo e n t r e f i o s acima

wire [ ‘SCORE MAX BITS− 1 : 0 ] v a l o r o t m p = l i n p > c o l p ? ( l i n p > d i a g p ? l i n p : d i a g p )

: ( c o l p > d i a g p ? c o l p : d i a g p ) ;

// a l i n h a m e n t o l o c a l , maximo e n t r e v a l o r o t m p e 2 ( b a s e a d o em 2 ) assign v a l o r o = ( v a l o r o t m p >1) ? v a l o r o t m p : 2 ’ b10 ;

ANEXO A. DESCRI ¸C ˜AO DO HARDWARE EM VERILOG 115

A.5

Elemento de processamento - subcompo-

nente de c´alculo do m´aximo local

module e p s c a l c m a x (

input c l k i , r e s e t i ,

input [ ‘SCORE MAX BITS− 1 : 0 ] v a l o r i , // s i n a l c o n t r o l a a p r e s e n t a maximos input am i ,

input [ ‘SCORE MAX BITS− 1 : 0 ] max i , output reg [ ‘SCORE MAX BITS− 1 : 0 ] max o ,

input [ ‘CLK TICKS MAX BITS − 1 : 0 ] m a x c l k t i c k s i , output reg [ ‘CLK TICKS MAX BITS − 1 : 0 ] m a x c l k t i c k s o , input [ ‘CLK TICKS MAX BITS − 1 : 0 ] c l k t i c k s i

) ; /∗

∗ C a l c u l o do v a l o r maximo p r o d u z i d o por e s t e e l e m e n t o

∗ r e s e t das l o g i c a s a b a i x o eh r e s e t o ao i n v e s de r e s e t i , e v i t a n d o ∗ tomar como maximos v a l o r e s i n v a l i d o s , p r o d u z i d o s a n t e s do r e s e t ∗ c o n t a o tempo d e s d e o u l t i m o r e s e t p/ t e r o tempo de producao ∗ do maximo

∗/

reg [ ‘SCORE MAX BITS− 1 : 0 ] max r ; //maximo p r o d u z i d o

reg [ ‘CLK TICKS MAX BITS − 1 : 0 ] m a x c l k t i c k s r ; // tempo de p r o d u c a o

always @(‘CLOCK EDGE PRINCIPAL c l k i or posedge r e s e t i ) begin i f ( r e s e t i ) begin

max r <= ‘SCORE MAX BITS ’ b10 ; // 2

m a x c l k t i c k s r <= ‘CLK TICKS MAX BITS ’ b0 ; end

e l s e begin

/∗ Nao e s t a m o s em r e s e t . Entao ( o b s e r v e que m a x c l o c k t i c k s r ∗ acompanha max r ) , s e :

∗ − am i l i g a d o : ”ao mesmo tempo ” o maximo l o c a l e s t a h sendo ∗ a p r e s e n t a d o . N e s t e c a s o como o maximo j a h f o i

∗ a p r e s e n t a d o , o r e g i s t r a d o r de maximo eh r e i n i c i a d o com ∗ v a l o r o c o r r e n t e , i n i c i a n d o um novo c i c l o de maximo ∗ − ou s e v a l o r o > max r : novo maximo l o c a l , armazena−l o

∗ − senao o v a l o r do maximo permanece o mesmo ( max r <= max r ) ∗/ i f ( ( v a l o r i > max r ) | | am i ) begin max r <= v a l o r i ; m a x c l k t i c k s r <= c l k t i c k s i ; end end end /∗ ∗ O maximo de cada e l e m e n t o de p r o c e s s a m e n t o eh p a s s a d o p o e l e m e n t o ∗ aa d i r e i t a e d e s t e p os demais ( e s t i l o s h i f t −r e g i s t e r ) de forma ∗ que t o d o s os maximos ( e tempos ) de t o d o s os e l e m e n t o s cheguem ao ∗ e l e m e n t o mais aa d i r e i t a do s i s t o l i c o e e n t a o para a s a i d a

∗ max o e m a x c l o c k t i c k s o :

∗ contem o v a l o r maximo p r o d u z i d o por e s t e s i s t o l i c o ( e o tempo ∗ de producao ) ( s e am i a t i v a d o ) ou c a r r e g a v a l o r l i d o das e n t r a d a s ∗ max i e m a x c l o c k t i c k s i

∗/

always @(‘CLOCK EDGE PRINCIPAL c l k i ) begin

i f ( am i ) begin max o<=max r ; m a x c l k t i c k s o <=m a x c l k t i c k s r ; end e l s e begin max o <= max i ; m a x c l k t i c k s o <= m a x c l k t i c k s i ; end end

Anexo B - C´odigo-fonte do

software

B.1

Software de reconstru¸c˜ao e visualiza¸c˜ao de

alinhamento

#include ”sw . h ” /∗

∗ GLOBAIS ∗/

char s c [ MAX BASES+ 1 ] , sbd [ MAX BASES+ 1 ] ; //+1 para f g e t s i n t sc tam , sbd tam ; // e s p a c o para 3 a n t i d i a g o n a i s . i n d i c e [ 0 ] sempre 0 ( b o r d a da m a t r i z ) i n t ad [ 3 ] [ MAX BASES+ 1 ] ; i n t ∗ a d t 0 , ∗ a d t 1 , ∗ a d t 2 ; // e s p a c o para 3 a n t i d i a g o n a i s . i n d i c e [ 0 ] sempre 0 ( b o r d a da m a t r i z ) i n t vd [ 3 ] [ MAX BASES+ 1 ] ; i n t ∗ vd t0 , ∗ vd t1 , ∗ v d t 2 ; //+1 para ’ \ 0 ’ e p r i n t f

char s c i n v [ MAX BASES+ 1 ] , s b d i n v [ MAX BASES+ 1 ] ; i n t s c i n v t a m , s b d i n v t a m ;

i n t m a l i n i n v [ MAX BASES ALIN ] [ MAX BASES ALIN ] ; i n t m a l i n i n v v d [ MAX BASES ALIN ] [ MAX BASES ALIN ] ;

// m a t r i z com o s a l i n h a m e n t o s d a s s e q u e n c i a s na ordem normal i n t m a l i n [ MAX BASES ALIN ] [ MAX BASES ALIN ] ;

// g l o b a l por p e r f o r m a n c e em p e r c o r r e a l i n h a m e n t o i n t b c c o r t e , b b d c o r t e ; // i n d i c e s maximos o b s e r v a d o s na m a t r i z de // a l i n h a m e n t o s d a s s e q u e n c i a s i n v e r t i d a s i n t m a l i n i n v m a x b c = 0 , m a l i n i n v m a x b b d = 0 ; // m a i o r e s v a l o r e s de b b d e b c na m a t r i z i n v e r t i d a onde o c o r r e o maximo i n t maximo , maximo num dig ;

i n t maximos max bc , maximos max bbd ; /∗

∗ PROTOTIPOS ∗/

void c o r t a e i n v e r t e s e q u e n c i a s ( ) ; void c a l c u l a m a x i m o m a t r i z ( ) ;

void i m p r i m e m a l i n i n v ( ) ; void i m p r i m e m a l i n ( ) ; void l e s e q u e n c i a s ( ) ; void i m p r i m e a l i n h a m e n t o ( char ∗ a l l 1 , char ∗ a l l 2 ,

unsigned ∗ a l s c o r e , unsigned a l i i n i c i o ) ;

i n t p e r c o r r e a l i n h a m e n t o ( char a l l 1 [ 2 ∗MAX BASES ALIN ] ,

char a l l 2 [ MAX BASES ALIN ] , i n t a l s c o r e [ MAX BASES ALIN ] , i n t bbd , i n t bc , i n t a l i ) ;

i n t m a l i n i n v p a r a m a l i n ( ) ; /∗

∗ R e c o n s t r o i um a l i n h a m e n t o maximo l o c a l , dada a p o s i c a o de t e r m i n o ∗ Argumentos : a n t i d i a g o n a l onde o c o r r e u o t e r m i n o do a l i n h a m e n t o que s e ∗ d e s e j a r e c o n s t r u i r , b a s e de c o n s u l t a d e s t e a l i n h a m e n t o onde e s t a o ∗ t e r m i n o do a l i n h a m e n t o , s c o r e e s p e r a d o para a p o s i c a o , para fim de ∗ c o n f e r e n c i a . ∗ ∗ − Corta as s e q u e n c i a s na p o s i c a o i n d i c a d a e i n v e r t e −as ∗ − Gera a m a t r i z de s i m i l a r i d a d e de t o d o s os a l i n h a m e n t o s que i n i c i e m ∗ na p o s i c a o 1 , 1 . A p o s i c a o 1 , 1 ( i n i c i o d a s s e q i n v e r t i d a s ) e q u i v a l e ∗ a p o s i c a o i n d i c a d a como t e r m i n o d o s a l i n h a m e n t o s nas s e q u e n c i a s ∗ normais . ∗ − V e r i f i c a s e o s c o r e maximo e n c o n t r a d o eh o e s p e r a d o

∗ − A p a r t i r de cada ponto com v a l o r maximo na na m a t r i z i n v e r t i d a ∗ p e r c o r r e o caminho a t e o i n i c i o . Cada caminho eh um a l i n h a m e n t o , ∗ que s e d e s e j a v i s u a l i z a r . Gera a v i s u a l i z a c a o

ANEXO B. C ´ODIGO-FONTE DO SOFTWARE 119 main ( i n t a r g c , char ∗∗ a r g v ) { i f ( a r g c != 4 ) { p r i n t f ( ”\ n S o f t w a r e complementar − r e c o n s t r u c a o de a l i n h a m e n t o s ” ” i n d i c a d o s por hardware \n−−−”\ ”\ nAlinhamento l o c a l de s e q u e n c i a s p e l o a l g o r i t m o de ” ”Smith−Waterman ”\ ”\ n I n f o r m a r 3 argumentos : c o l u n a onde o c o r r e u o t e r m i n o ” ”do a l i n h a m e n t o , \ ntempo de producao d e s t a p o s i c a o e ” ” s c o r e e s p e r a d o \n\n ” ) ; e x i t ( RC ARGS ) ; } l e s e q u e n c i a s ( ) ; // sc , sc tam , sbd , s b d t a m #i f d e f DEBUG p r i n t f ( ”\n%d b a s e s na s e q u e n c i a de c o n s u l t a , %d b a s e s na ” ” s e q u e n c i a do banco de dados ” , sc tam , sbd tam ) ; #endif /∗ ∗ Le os argumentos , a b a s e de c o n s u l t a onde o c o r r e o t e r m i n o ∗ do a l i n h a m e n t o a a n t i d i a g o n a l onde o c o r r e u e s t e t e r m i n o e o ∗ s c o r e e s p e r a d o para a p o s i c a o . Deduz , a p a r t i r da a n t i d i a g o n a l ∗ e da b a s e de c o n s u l t a , a b a s e do banco de dados ∗/ b c c o r t e = a t o i ( a r g v [ 1 ] ) ; i n t s c o r e e s p e r a d o = a t o i ( a r g v [ 3 ] ) ; b b d c o r t e = a t o i ( a r g v [ 2 ] ) − b c c o r t e ; #i f d e f DEBUG p r i n t f ( ”\ n S o l i c i t a d o s a l i n h a m e n t o s o t i m o s que terminam na p o s i c a o : ” ”b a s e de c o n s u l t a %d , b a s e do banco de dados %d ”\ ” ( a n t i d i a g o n a l %d ) ” , b c c o r t e , b b d c o r t e , a t o i ( a r g v [ 1 ] ) ) ; #endif /∗ ∗ Corta as s e q u e n c i a s na p o s i c a o i n d i c a d a e i n v e r t e −as ∗ s c e s b d para s c i n v e s b d i n v ∗/ s c i n v t a m = b c c o r t e +1; s b d i n v t a m = b b d c o r t e +1; c o r t a e i n v e r t e s e q u e n c i a s ( ) ; // cada a n t i d i a g o n a l d e p e n d e d a s duas a n t e r i o r e s . // armazena t b v e t o r e s de d i r e c a o

memset ( ad [ 2 ] , 0 , MAX BASES+1 ) ;

memset ( vd [ 0 ] , 0 , MAX BASES+1 ) ; memset ( vd [ 1 ] , 0 , MAX BASES+1 ) ; memset ( vd [ 2 ] , 0 , MAX BASES+1 ) ;

a d t 0 = ad [ 0 ] ; a d t 1 = ad [ 1 ] ; a d t 2 = ad [ 2 ] ; v d t 0 = vd [ 0 ] ; v d t 1 = vd [ 1 ] ; v d t 2 = vd [ 2 ] ; /∗ ∗ C a l c u l a p r i m e i r a a n t i d i a g o n a l f o r a do l a c o ∗/ v d t 0 [ 0 ] = BIT DIAG ; // p e r m i t e o s u r g i m e n t o de 1 a l i n h a m e n t o // p r i n t f ( ”\ n ” ) ; c a l c u l a a d c o m p l e m e n t a r ( 0 , 0 , a d t 0 , a d t 1 , a d t 2 ) ; v d t 0 [ 0 ] = 0 ; // e v i t a o u t r o s a l i n h a m e n t o s que nao o p r i m e i r o r o t a c i o n a p o n t e i r o s ( a d t 0 , a d t 1 , a d t 2 ) ; r o t a c i o n a p o n t e i r o s ( vd t0 , vd t1 , v d t 2 ) ; /∗ ∗ C a l c u l a s proximas a n t i d i a g o n a i s ∗ v a r i a v e i s b c i n v i e b b d i n v i marcam i n i c i o das a n t i d i a g o n a i s ∗/ i n t b c i n v i , b b d i n v i ; // e n c o n t r a o proximo v a l o r c o r r e t o a p o s a p r i m e i r a [ 1 , 1 ] // proxima ad i n i c i a em 1 , 2 i f ( s b d i n v t a m > 1 ) { b c i n v i =0; b b d i n v i =1; } // proxima ad i n i c i a em 2 , 1 e l s e i f ( s c i n v t a m > 1 ) { b c i n v i =1; b b d i n v i =0; }

e l s e { p r i n t f ( ”\nTamanho das s e q u e n c i a s menor i g u a l a 1 ” ) ; return ; } f o r ( ; ; ) { // c a l c u l a a n t i d i a g o n a l a d t 2 ( tempo 2 ) b a s e a d o nas a d t 0 e a d t 1 i f ( ! c a l c u l a a d c o m p l e m e n t a r ( b c i n v i , b b d i n v i , a d t 0 , a d t 1 , a d t 2 ) ) break ; /∗ ∗ L o g i c a de i n c r e m e n t o dos i n d i c e s das s e q u e n c i a s de c o n s u l t a e ∗ do banco de dados onde i n i c i a a proxima a n t i d i a g o n a l a s e r ∗ c a l c u l a d a . Condicao de parada d e s t e l a c o

∗ eh u l t i m a a n t i d i a g o n a l c a l c u l a d a ∗/

ANEXO B. C ´ODIGO-FONTE DO SOFTWARE 121 // de i n i c i o . Nao p e r m i t e que s e t o r n e i g u a l s b d i n v t a m i f ( b b d i n v i < ( s b d i n v t a m −1) ) b b d i n v i ++; // s e g u n d a p a r t e , a l c a n c o u u l t i m a b a s e do banco de dados , // avanca b a s e de c o n s u l t a e l s e i f ( b c i n v i < ( s c i n v t a m −1) ) b c i n v i ++; // fim , u l t i m a a n t i d i a g o n a l f o i c a l c u l a d a e l s e break ;

// mais uma a n t i d i a g o n a l c a l c u l a d a , avanca o tempo r o t a c i o n a p o n t e i r o s ( a d t 0 , a d t 1 , a d t 2 ) ; r o t a c i o n a p o n t e i r o s ( vd t0 , vd t1 , v d t 2 ) ; } /∗ ∗ N e s t e ponto , temos a m a t r i z de s i m i l a r i d a d e e os v e t o r e s de ∗ d i r e c a o das s e q u e n c i a s i n v e r t i d a s , i n i c i a n d o no ponto

∗ i n d i c a d o p e l o s argumentos do programa . Supondo s e r um ponto ∗ de a l i n h a m e n t o maximo l o c a l , e s p e r a −s e que n e s t a m a t r i z ∗ i n v e r t i d a s u r j a o mesmo v a l o r maximo que na m a t r i z normal . ∗ Os t e r m i n o s de a l i n h a m e n t o que t i v e r e m os v a l o r e s maximos na ∗ m a t r i z i n v e r t i d a sao os i n i c i o s de a l i n h a m e n t o o t i m o s na ∗ m a t r i z das s e q u e n c i a s na ordem normal

∗ Supondo que o a l i n h a m e n t o i n i d i c a d o eh um a l i n h a m e n t o maximo ∗ l o c a l , o maximo da m a t r i z i n v e r t i d a d e v e s e r o mesmo do maximo ∗ da m a t r i z normal . O c o d i g o a b a i x o v e r i f i c a e s t a c o n di c a o ,

∗ s i n a l i z a n d o s e v a l o r e s d i f e r e n t e s foram i n d i c a d o s . Se os v a l o r e s ∗ d i f e r i r e m eh p o s s i v e l que nao s e j a um a l i n h a m e n t o maximo l o c a l . ∗ N e s t e caso , o mesmo pode nao s e r o b s e r v a d o quando as s e q u e n c i a s ∗ forem i n v e r t i d a s

∗/

c a l c u l a m a x i m o m a t r i z ( ) ; //maximo , maximos max bbd , maximos max bc maximo num dig = c a l c u l a d i g i t o s ( maximo ) ;

#i f d e f DEBUG

// imprime o s a l i n h a m e n t o s i n v e r t i d o s que i n i c i a m p t o de maximo i m p r i m e m a l i n i n v ( ) ; #endif i f ( maximo == s c o r e e s p e r a d o ) p r i n t f ( ”\ n S c o r e maximo d e s t a r e g i a o de s e m e l h a n c a c o n f e r e ” ”com e s p e r a d o : %d ” , maximo ) ; e l s e

p r i n t f ( ”\ n S c o r e maximo d e s t a r e g i a o de s e m e l h a n c a d i f e r e ” ”do e s p e r a d o . Encontrado : %d Esperado : %d ” ,

maximo , s c o r e e s p e r a d o ) ; /∗

∗ Para cada t e r m i n o de a l i n h a m e n t o otimo da m a t r i z i n v e r t i d a ,

∗ temos o i n i c i o de um a l i h a m e n t o otimo na m a t r i z com as s e q u e n c i a s ∗ na ordem normal . Aqui i n i c i a c o n s t r u c a o dos a l i n h a m e n t o s normais ∗/

i n t a l i n n u m = m a l i n i n v p a r a m a l i n ( ) ;

p r i n t f ( ”\ n V i s u a l i z a c a o dos a l i n h a m e n t o s na m a t r i z de s i m i l a r i d a d e : ” ”\n %d a l i n h a m e n t o%s ” , alin num , ( a l i n n u m !=1? ”s ” : ” ” ) ) ; i m p r i m e m a l i n ( ) ;

i f ( maximo != s c o r e e s p e r a d o ) return RC SCORE DIF ;

return RC OK ; }

/∗

∗ C a l c u l a a n t i d i a g o n a l que i n i c i a na p o s i c a o b c i n v i e b b d i n v i ∗

∗ Os v e t o r e s de d i r e c a o em vd sao 3 b i t s BIT DIAG BIT LIN e BIT COL ∗ nao mutuamente e x c l u s i v o s , uma c e l u l a pode t e r v i n d o de d o i s

∗ v a l o r e s s e ambos t i v e r e m o mesmo v a l o r apos o c a l c u l o da p e n a l i d a d e ∗/

i n t

c a l c u l a a d c o m p l e m e n t a r ( i n t b c i n v i , i n t b b d i n v i ) {

/∗

∗ Se ocorrerem duas ad s u c e s s i v a s sem s c o r e s e != 0 ( e vd != 0) ∗ e n t a o o a l i n h a m e n t o ao c e r t o terminou ∗/ s t a t i c i n t n u m a d z e r a d a s s u c e s s i v a s = 0 ; // i n d i c a em c e l u l a s d i f e r e n t e s de z e r o n e s t e ad i n t f l a g a d z e r a d a = TRUE; // s c o r e maximo da a n t i d i a g o n a l e b a s e de c o n s u l t a d e s t e i n t ad max = 0 , ad max bc = 0 ; /∗ ∗ P e r c o r r e as p o s i c o e s d e s t a a n t i d i a g o n a l ,

ANEXO B. C ´ODIGO-FONTE DO SOFTWARE 123

∗ incrementando a b a s e de c o n s u l t a e d e c r e m e n t a do banco de d a d o s ∗ P r o v a v e l m e n t e l o g i c a ( ) && ( ) a b a i x o eh redundante , c o n d i c o e s ∗ viram TRUE ao mesmo tempo

∗/ f o r ( ; ( b c i n v i <s c i n v t a m ) && ( b b d i n v i >=0); b c i n v i ++, b b d i n v i −− ) { // d e i x a i n t o c a d a a d t 2 [ 0 ] , b o r d a da m a t r i z i n t b c i n v i m a i s 1 = b c i n v i +1; /∗ C a l c u l a v a l o r e s p e n a l i z a d o s ∗/ // d i a g o n a l −> c o l u n a a n t e r i o r , 2 tempos a t r a s i n t d i a g p = a d t 0 [ b c i n v i m a i s 1 −1] + ( ( s c i n v [ b c i n v i ]== s b d i n v [ b b d i n v i ] ) ? PONT MATCH: −(PONT MISMATCH ) ) ;

// c o l u n a −> c o l u n a a n t e r i o r , 1 tempo a t r a s

i n t c o l p = a d t 1 [ b c i n v i m a i s 1 −1] − PONT GAP; // l i n h a −> mesma coluna , 1 tempo a t r a s

i n t l i n p = a d t 1 [ b c i n v i m a i s 1 ] − PONT GAP; /∗ Computa maximo ∗/ i f ( d i a g p > c o l p ) { // c o l nao eh o maior i f ( d i a g p > l i n p ) { // d i a g maior a d t 2 [ b c i n v i m a i s 1 ]= d i a g p ; v d t 2 [ b c i n v i m a i s 1 ]=BIT DIAG ; } e l s e i f ( l i n p > d i a g p ) { // l i n maior a d t 2 [ b c i n v i m a i s 1 ]= l i n p ; v d t 2 [ b c i n v i m a i s 1 ]=BIT LIN ; } e l s e /∗ l i n e d i a g i g u a i s ∗/ { a d t 2 [ b c i n v i m a i s 1 ]= l i n p ;

v d t 2 [ b c i n v i m a i s 1 ]=BIT LIN | BIT DIAG ; } } e l s e i f ( c o l p > d i a g p ) { // d i a g nao eh o maior i f ( c o l p > l i n p ) { // c o l maior a d t 2 [ b c i n v i m a i s 1 ]= c o l p ; v d t 2 [ b c i n v i m a i s 1 ]=BIT COL ; } e l s e i f ( l i n p > c o l p ) { // l i n maior a d t 2 [ b c i n v i m a i s 1 ]= l i n p ; v d t 2 [ b c i n v i m a i s 1 ]=BIT LIN ;

}

e l s e /∗ c o l e l i n i g u a i s ∗/ { a d t 2 [ b c i n v i m a i s 1 ]= l i n p ;

v d t 2 [ b c i n v i m a i s 1 ]=BIT LIN | BIT COL ; } } e l s e { // c o l == d i a g i f ( l i n p > c o l p ) { // l i n maior a d t 2 [ b c i n v i m a i s 1 ]= l i n p ; v d t 2 [ b c i n v i m a i s 1 ]=BIT LIN ; } e l s e i f ( c o l p > l i n p ) { // c o l e d i a g m a i o r e s a d t 2 [ b c i n v i m a i s 1 ]= c o l p ;

v d t 2 [ b c i n v i m a i s 1 ]=BIT COL | BIT DIAG ; }

e l s e /∗ l i n , c o l e d i a g i g u a i s ∗/ { a d t 2 [ b c i n v i m a i s 1 ]= l i n p ;

v d t 2 [ b c i n v i m a i s 1 ]=BIT DIAG | BIT COL | BIT LIN ; }

} /∗

∗ A l o g i c a a b a i x o impede que surjam novos a l i n h a m e n t o s d u r a n t e a ∗ e x e c u c a o do a l g o r i t m o , c o n t i n u a n d o somente os que i n i c i a m −s e ∗ no c a n t o s u p e r i o r e s q u e r d o da m a t r i z ( p r i m e i r a c e l u l a ) .

∗ I s t o p o r q u e o o b j e t i v o eh r e c o n s t r u i r o a l i n h a m e n t o i n d i c a d o ∗ por hardware , que i n i c i a −s e na p r i m e i r a c e l u l a

∗/ // s e n e g a t i v o e n t a o 0 ( a l i n h a m e n t o l o c a l ) , i f ( a d t 2 [ b c i n v i m a i s 1 ] < 0 ) { a d t 2 [ b c i n v i m a i s 1 ] = 0 ; v d t 2 [ b c i n v i m a i s 1 ] = 0 ; } e l s e { // senao c h e c a r origem da c e l u l a // T e s t a a s t r e s o r i g e n s p o s s i v e i s da c e l u l a , // s e vem da c e l u l a d i a g o n a l mas vd d a q u e l a z e r a d o , // ou s e j a , nao p e r t e n c i a a a l i n h a m e n t o , z e r a BIT DIAG // d e s t e vd , i mp e di n do n o v o s a l i n h a m e n t o s

i f ( ( v d t 2 [ b c i n v i m a i s 1 ] & BIT DIAG ) && ( v d t 0 [ b c i n v i m a i s 1 −1]==0) )

v d t 2 [ b c i n v i m a i s 1 ]= v d t 2 [ b c i n v i m a i s 1 ] & (˜BIT DIAG ) ; i f ( ( v d t 2 [ b c i n v i m a i s 1 ] & BIT COL) &&

ANEXO B. C ´ODIGO-FONTE DO SOFTWARE 125

v d t 2 [ b c i n v i m a i s 1 ]= v d t 2 [ b c i n v i m a i s 1 ] & (˜BIT COL ) ; i f ( ( v d t 2 [ b c i n v i m a i s 1 ] & BIT LIN ) &&

( v d t 1 [ b c i n v i m a i s 1 ] ==0) )

v d t 2 [ b c i n v i m a i s 1 ]= v d t 2 [ b c i n v i m a i s 1 ] & (˜ BIT LIN ) ; // Se p a s s o u p e l a s c h e c a g e n s , e n t a o e s t a ad tem // p e l o menos 1 c e l u l a != 0 . S i n a l i z a i s s o i f ( v d t 2 [ b c i n v i m a i s 1 ] ) { f l a g a d z e r a d a=FALSE ; // i n c l u i na m a t r i z de a l i n h a m e n t o s , z e r o −b a s e d m a l i n i n v [ b b d i n v i ] [ b c i n v i ] = a d t 2 [ b c i n v i m a i s 1 ] ; m a l i n i n v v d [ b b d i n v i ] [ b c i n v i ] = v d t 2 [ b c i n v i m a i s 1 ] ; // c a l c u l a o s m a i o r e s i n d i c e s da m a t r i z i n v e r t i d a i f ( b c i n v i > m a l i n i n v m a x b c ) m a l i n i n v m a x b c = b c i n v i ; i f ( b b d i n v i > m a l i n i n v m a x b b d ) m a l i n i n v m a x b b d = b b d i n v i ; } } #i f d e f DEBUG // p r i n t f ( ”%d ” , a d t 2 [ b c i n v i m a i s 1 ] ) ; #endif } #i f d e f DEBUG // p r i n t f ( ”\ n ” ) ; #endif i f ( f l a g a d z e r a d a ) { //Na s e g u n d a a n t i d i a g o n a l s u c e s s i v a z e r a d a , r e t o r n a FALSE p o i s //nenhum o u t r o a l i n h a m e n t o pode s u r g i r a p a r t i r d a q u i , i f ( ++n u m a d z e r a d a s s u c e s s i v a s == 2 ) return FALSE ; } e l s e n u m a d z e r a d a s s u c e s s i v a s = 0 ; return TRUE; } /∗ ∗ P e r c o r r e os a l i n h a m e n t o s o t i m o s t e r m i n a d o s n e s t e maximo ( b b d i n v i , ∗ b c i n v i ) , f a z e n d o 2 t a r e f a s : ∗ − montando a l l 1 , a l l 2 e a l s c o r e , v e t o r e s para e x i b i c a o do

∗ Ao t e r m i n o do p e r c o r r i m e n t o de cada a l i n h a m e n t o , e s t e eh i m p r e s o ∗ − p r e e n c h e n d o m a t r i z m a l i n com os a l i n h a m e n t o s em ordem normal . ∗ ∗ Retorna o numero de a l i n h a m e n t o s e n c o n t r a d o s e r e c o n s t r u i d o s

Documentos relacionados