Explorar el Código

determine type of sequence for alignment

Alexander Rose hace 4 años
padre
commit
f8ce9cbb65

+ 10 - 13
src/mol-model/sequence/alignment/alignment.ts

@@ -9,7 +9,7 @@ import { SubstitutionMatrix, SubstitutionMatrices, SubstitutionMatrixData } from
 const DefaultAlignmentOptions = {
     gapPenalty: -11,
     gapExtensionPenalty: -1,
-    substMatrix: 'blosum62' as SubstitutionMatrix
+    substMatrix: 'default' as SubstitutionMatrix | 'default'
 };
 export type AlignmentOptions = typeof DefaultAlignmentOptions;
 
@@ -22,7 +22,7 @@ export function align(seqA: ArrayLike<string>, seqB: ArrayLike<string>, options:
 
 class Alignment {
     readonly gapPenalty: number; readonly gapExtensionPenalty: number
-    readonly substMatrix: SubstitutionMatrixData
+    readonly substMatrix: SubstitutionMatrixData | undefined
 
     readonly n: number; readonly m: number
     readonly S: number[][] = []; readonly V: number[][] = []; readonly H: number[][] = []
@@ -30,7 +30,7 @@ class Alignment {
     constructor (readonly seqA: ArrayLike<string>, readonly seqB: ArrayLike<string>, options: AlignmentOptions) {
         this.gapPenalty = options.gapPenalty;
         this.gapExtensionPenalty = options.gapExtensionPenalty;
-        this.substMatrix = SubstitutionMatrices[options.substMatrix];
+        this.substMatrix = options.substMatrix === 'default' ? undefined : SubstitutionMatrices[options.substMatrix];
 
         this.n = this.seqA.length;
         this.m = this.seqB.length;
@@ -61,22 +61,19 @@ class Alignment {
     }
 
     private makeScoreFn () {
-        const seq1 = this.seqA;
-        const seq2 = this.seqB;
-
-        const substMatrix = this.substMatrix;
+        const { seqA, seqB, substMatrix } = this;
 
         if (substMatrix) {
             return function score (i: number, j: number) {
-                const c1 = seq1[i];
-                const c2 = seq2[j];
-                return substMatrix[c1]?.[c2] ?? -4;
+                const cA = seqA[i];
+                const cB = seqB[j];
+                return substMatrix[cA]?.[cB] ?? -4;
             };
         } else {
             return function scoreNoSubstMat (i: number, j: number) {
-                const c1 = seq1[i];
-                const c2 = seq2[j];
-                return c1 === c2 ? 5 : -3;
+                const cA = seqA[i];
+                const cB = seqB[j];
+                return cA === cB ? 5 : -3;
             };
         }
     }

+ 8 - 2
src/mol-model/structure/structure/util/superposition.ts

@@ -9,6 +9,7 @@ import { MinimizeRmsd } from '../../../../mol-math/linear-algebra/3d/minimize-rm
 import StructureElement from '../element';
 import { OrderedSet } from '../../../../mol-data/int';
 import { AlignSequences } from '../../../sequence/alignment/sequence';
+import StructureProperties from '../properties';
 
 export function superpose(xs: StructureElement.Loci[]): MinimizeRmsd.Result[] {
     const ret: MinimizeRmsd.Result[] = [];
@@ -31,16 +32,21 @@ export function superpose(xs: StructureElement.Loci[]): MinimizeRmsd.Result[] {
 }
 
 type AlignAndSuperposeResult = MinimizeRmsd.Result & { alignmentScore: number };
+const reProtein = /(polypeptide|cyclic-pseudo-peptide)/i;
 
 export function alignAndSuperpose(xs: StructureElement.Loci[]): AlignAndSuperposeResult[] {
     const ret: AlignAndSuperposeResult[] = [];
     if (xs.length <= 0) return ret;
 
+    const l = StructureElement.Loci.getFirstLocation(xs[0])!;
+    const subtype = StructureProperties.entity.subtype(l);
+    const substMatrix = subtype.match(reProtein) ? 'blosum62' : 'default';
+
     for (let i = 1; i < xs.length; i++) {
         const { a, b, score } = AlignSequences.compute({
             a: xs[0].elements[0],
-            b: xs[i].elements[0]
-        });
+            b: xs[i].elements[0],
+        }, { substMatrix });
 
         const lociA = StructureElement.Loci(xs[0].structure, [a]);
         const lociB = StructureElement.Loci(xs[i].structure, [b]);

+ 1 - 1
src/mol-plugin-ui/structure/superposition.tsx

@@ -233,7 +233,7 @@ export class SuperpositionControls extends PurePluginUIComponent<{}, Superpositi
 
             const stats = StructureElement.Stats.ofLoci(selection);
             const counts = structureElementStatsLabel(stats, { countsOnly: true });
-            const chain = elementLabel(stats.firstElementLoc, { reverse: true, granularity: 'chain' }).split('|');
+            const chain = elementLabel(l, { reverse: true, granularity: 'chain' }).split('|');
             const label = `${counts} | ${chain[0]} | ${chain[chain.length - 1]}`;
             entries.push({ loci: selection, label, cell });
         });