@@ -130,60 +130,11 @@ const PairwiseOverlapMatrix: React.FC<PairwiseOverlapProps> = ({ fastaNames, fol
130130 return positionData ;
131131 } , [ ] ) ;
132132
133- // Load alignment data for selected alignments
134- const loadAlignmentData = useCallback ( async ( ) => {
135- if ( selectedAlignments . length === 0 ) {
136- setAlignmentData ( [ ] ) ;
137- setOverlapMatrix ( [ ] ) ;
138- setTotalPositions ( 0 ) ;
139- return ;
140- }
141-
142- setLoading ( true ) ;
143- try {
144- const loadPromises = selectedAlignments . map ( async ( name ) => {
145- const response = await fetch ( `${ folder } /${ name } .fasta` ) ;
146- if ( ! response . ok ) {
147- throw new Error ( `Failed to load ${ name } .fasta` ) ;
148- }
149- const text = await response . text ( ) ;
150- const sequences = parseFasta ( text ) ;
151- const positionData = calculatePositionData ( sequences ) ;
152-
153- return {
154- name,
155- sequences,
156- positionData
157- } ;
158- } ) ;
159-
160- const loadedData = await Promise . all ( loadPromises ) ;
161- setAlignmentData ( loadedData ) ;
162- calculateOverlapMatrix ( loadedData ) ;
163- } catch ( error ) {
164- console . error ( 'Error loading alignment data:' , error ) ;
165- } finally {
166- setLoading ( false ) ;
167- }
168- } , [ selectedAlignments , folder , calculatePositionData , calculateOverlapMatrix ] ) ;
169-
170- // Check if two amino acids are similar based on matching groups
171- const areSimilar = useCallback ( ( aa1 : string , aa2 : string ) : boolean => {
172- if ( aa1 === aa2 ) return true ;
173-
174- for ( const group of Object . values ( matchingGroups ) ) {
175- if ( group . includes ( aa1 ) && group . includes ( aa2 ) ) {
176- return true ;
177- }
178- }
179- return false ;
180- } , [ ] ) ;
181-
182133 // Calculate pairwise overlap matrix based on amino acid conservation
183134 const calculateOverlapMatrix = useCallback ( ( data : AlignmentData [ ] ) => {
184135 const n = data . length ;
185136 const matrix : number [ ] [ ] = Array ( n ) . fill ( null ) . map ( ( ) => Array ( n ) . fill ( 0 ) ) ;
186-
137+
187138 // Find the maximum position across all alignments
188139 const maxPos = Math . max ( ...data . map ( d =>
189140 d . positionData . length > 0 ? Math . max ( ...d . positionData . map ( p => p . position ) ) : 0
@@ -201,24 +152,24 @@ const PairwiseOverlapMatrix: React.FC<PairwiseOverlapProps> = ({ fastaNames, fol
201152 } else {
202153 // Off-diagonal: count positions where both alignments have similar conserved amino acids
203154 let sharedPositions = 0 ;
204-
155+
205156 // Create position maps for quick lookup
206157 const posMapI = new Map < number , PositionData > ( ) ;
207158 const posMapJ = new Map < number , PositionData > ( ) ;
208-
159+
209160 data [ i ] . positionData . forEach ( pos => posMapI . set ( pos . position , pos ) ) ;
210161 data [ j ] . positionData . forEach ( pos => posMapJ . set ( pos . position , pos ) ) ;
211-
162+
212163 // Check all positions that exist in both alignments
213164 for ( let pos = 0 ; pos <= maxPos ; pos ++ ) {
214165 const posDataI = posMapI . get ( pos ) ;
215166 const posDataJ = posMapJ . get ( pos ) ;
216-
167+
217168 if ( posDataI && posDataJ ) {
218169 // Both alignments have data at this position
219170 const meetsThresholdI = posDataI . conservationFrequency >= conservationThreshold ;
220171 const meetsThresholdJ = posDataJ . conservationFrequency >= conservationThreshold ;
221-
172+
222173 if ( meetsThresholdI && meetsThresholdJ ) {
223174 // Check if the most conserved amino acids are similar
224175 if ( areSimilar ( posDataI . mostConservedAA , posDataJ . mostConservedAA ) ) {
@@ -227,7 +178,7 @@ const PairwiseOverlapMatrix: React.FC<PairwiseOverlapProps> = ({ fastaNames, fol
227178 }
228179 }
229180 }
230-
181+
231182 matrix [ i ] [ j ] = sharedPositions ;
232183 }
233184 }
@@ -236,6 +187,56 @@ const PairwiseOverlapMatrix: React.FC<PairwiseOverlapProps> = ({ fastaNames, fol
236187 setOverlapMatrix ( matrix ) ;
237188 } , [ conservationThreshold , areSimilar ] ) ;
238189
190+ // Load alignment data for selected alignments
191+ const loadAlignmentData = useCallback ( async ( ) => {
192+ if ( selectedAlignments . length === 0 ) {
193+ setAlignmentData ( [ ] ) ;
194+ setOverlapMatrix ( [ ] ) ;
195+ setTotalPositions ( 0 ) ;
196+ return ;
197+ }
198+
199+ setLoading ( true ) ;
200+ try {
201+ const loadPromises = selectedAlignments . map ( async ( name ) => {
202+ const response = await fetch ( `${ folder } /${ name } .fasta` ) ;
203+ if ( ! response . ok ) {
204+ throw new Error ( `Failed to load ${ name } .fasta` ) ;
205+ }
206+ const text = await response . text ( ) ;
207+ const sequences = parseFasta ( text ) ;
208+ const positionData = calculatePositionData ( sequences ) ;
209+
210+ return {
211+ name,
212+ sequences,
213+ positionData
214+ } ;
215+ } ) ;
216+
217+ const loadedData = await Promise . all ( loadPromises ) ;
218+ setAlignmentData ( loadedData ) ;
219+ calculateOverlapMatrix ( loadedData ) ;
220+ } catch ( error ) {
221+ console . error ( 'Error loading alignment data:' , error ) ;
222+ } finally {
223+ setLoading ( false ) ;
224+ }
225+ } , [ selectedAlignments , folder , calculatePositionData , calculateOverlapMatrix ] ) ;
226+
227+ // Check if two amino acids are similar based on matching groups
228+ const areSimilar = useCallback ( ( aa1 : string , aa2 : string ) : boolean => {
229+ if ( aa1 === aa2 ) return true ;
230+
231+ for ( const group of Object . values ( matchingGroups ) ) {
232+ if ( group . includes ( aa1 ) && group . includes ( aa2 ) ) {
233+ return true ;
234+ }
235+ }
236+ return false ;
237+ } , [ ] ) ;
238+
239+
239240 // Load data when selected alignments or threshold changes
240241 useEffect ( ( ) => {
241242 loadAlignmentData ( ) ;
0 commit comments