Skip to content

Commit

Permalink
Merge pull request #543 from ncats/NAshorthand
Browse files Browse the repository at this point in the history
fixing sitesshorthand bug, unused import cleanup
  • Loading branch information
NikoAnderson authored Aug 27, 2024
2 parents c7a3282 + 96f76ee commit 5e2e72a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/app/core/config/config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export interface Config {
useApprovalAPI?: boolean;
dummyWhoami?: Auth;
enableStructureFeatures?: boolean;
StructureFeaturePriority?: Array<string>;
structureEditSearch?: boolean;
}

Expand Down
4 changes: 3 additions & 1 deletion src/app/core/substance-form/links/link-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export class LinkFormComponent implements OnInit, OnDestroy {

getStructure() {
if (this.privateLink && this.privateLink.linkage){
this.smiles = this.vocabulary[this.privateLink.linkage];
if(this.vocabulary) {
this.smiles = this.vocabulary[this.privateLink.linkage];
}
if (this.smiles && this.smiles.fragmentStructure) {
this.structure = this.cvService.getStructureUrlFragment(this.smiles.fragmentStructure);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple
featuresOnly = false;
hideFeaturesTable = false;
structureEditSearch = true;
StructureFeaturePriority = [
'Category Score',
'Sum Of Scores',
'AI Limit (US)',
'Potency Category',
'Potency Score',
'type',
'Type',
'TYPE'
];
@ViewChild(StructureEditorComponent) structureEditorComponent!: StructureEditorComponent;

constructor(
Expand Down Expand Up @@ -76,6 +86,13 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple
this.configService.configData.structureEditSearch !== null)) {
this.structureEditSearch = this.configService.configData.structureEditSearch;
}

if (this.configService.configData &&
(this.configService.configData.StructureFeaturePriority !== undefined &&
this.configService.configData.StructureFeaturePriority !== null)) {
this.StructureFeaturePriority = this.configService.configData.StructureFeaturePriority;
}

if(this.activatedRoute.snapshot.routeConfig.path === 'structure-features') {
this.featuresOnly = true;
}
Expand Down Expand Up @@ -185,15 +202,27 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple
}
}

featureSort(a: any, b: any): number {
const indexA = this.StructureFeaturePriority.indexOf(a.key);
const indexB = this.StructureFeaturePriority.indexOf(b.key);


if (indexA !== -1 && indexB !== -1) {
return indexA - indexB;
} else if (indexA !== -1) {
return -1; // a comes first
} else if (indexB !== -1) {
return 1; // b comes first
} else {
return a.key.localeCompare(b.key);
}
}

processStructurePostResponse(structurePostResponse?: InterpretStructureResponse): void {
if (structurePostResponse && structurePostResponse.structure) {
let customSort = (array: any[]): any[] => {
return array.sort((a, b) => {
if (a.key === 'Category Score') return -1;
if (b.key === 'Category Score') return 1;
if (a.key === 'Sum Of Scores') return a.key === 'Category Score' ? 1 : -1;
if (b.key === 'Sum Of Scores') return b.key === 'Category Score' ? -1 : 1;
return a.key.localeCompare(b.key);
return this.featureSort(a, b);
});
};

Expand All @@ -219,6 +248,9 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple
if(key === 'sumOfScores'){
label = 'Sum Of Scores';
}
if (key.toLowerCase() === 'type') {
label = 'Type';
}
temp.push({'key': label,'value': structurePostResponse.featureList[type][0][key] });
});
}
Expand Down
23 changes: 12 additions & 11 deletions src/app/core/substance-form/substance-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ export class SubstanceFormService implements OnDestroy {
});
}

//TODO - recalculate sitesShorthand instead of deleting / determine when backend uses sitesShorthand over sites array
if (this.privateSubstance.protein && this.privateSubstance.protein.disulfideLinks
&& this.privateSubstance.protein.disulfideLinks.length > 0) {
for (let i = this.privateSubstance.protein.disulfideLinks.length -1; i >= 0; i--) {
Expand All @@ -1436,20 +1437,20 @@ export class SubstanceFormService implements OnDestroy {
this.privateSubstance.protein.disulfideLinks.splice(i, 1);
}
}
}

if (this.privateSubstance.nucleicAcid) {
if (this.privateSubstance.nucleicAcid.linkages && this.privateSubstance.nucleicAcid.linkages.length > 0) {
for (let i = this.privateSubstance.nucleicAcid.linkages.length-1; i >= 0; i--) {
if (this.privateSubstance.nucleicAcid.linkages[i].sitesShorthand) {
delete this.privateSubstance.nucleicAcid.linkages[i].sitesShorthand;
}
if (this.privateSubstance.nucleicAcid) {
if (this.privateSubstance.nucleicAcid.linkages && this.privateSubstance.nucleicAcid.linkages.length > 0) {
for (let i = this.privateSubstance.nucleicAcid.linkages.length -1; i >= 0; i--) {
if (this.privateSubstance.nucleicAcid.linkages[i].sitesShorthand) {
delete this.privateSubstance.nucleicAcid.linkages[i].sitesShorthand;
}
}
if (this.privateSubstance.nucleicAcid.sugars && this.privateSubstance.nucleicAcid.sugars.length > 0) {
for (let i = this.privateSubstance.nucleicAcid.sugars.length-1; i >= 0; i--) {
if (this.privateSubstance.nucleicAcid.sugars[i].sitesShorthand) {
delete this.privateSubstance.nucleicAcid.sugars[i].sitesShorthand;
}
}
if (this.privateSubstance.nucleicAcid.sugars && this.privateSubstance.nucleicAcid.sugars.length > 0) {
for (let i = this.privateSubstance.nucleicAcid.sugars.length -1; i >= 0; i--) {
if (this.privateSubstance.nucleicAcid.sugars[i].sitesShorthand) {
delete this.privateSubstance.nucleicAcid.sugars[i].sitesShorthand;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@ import { Subscription } from 'rxjs';
import { OverlayContainer } from '@angular/cdk/overlay';
import { MatDialog } from '@angular/material/dialog';
import { Environment } from 'src/environments/environment.model';
import { ConfigService, LoadedComponents } from '@gsrs-core/config';
import { ConfigService } from '@gsrs-core/config';
import { UtilsService } from '@gsrs-core/utils';
import { StructureImageModalComponent, StructureService } from '@gsrs-core/structure';
import { SubstanceFormService } from '../../substance-form/substance-form.service';
import { StructureImageModalComponent } from '@gsrs-core/structure';
import { SubstanceFormSsg4mProcessService } from '../ssg4m-process/substance-form-ssg4m-process.service';
import { SubstanceDetail, SpecifiedSubstanceG4mProcess, SubstanceAmount } from '@gsrs-core/substance/substance.model';
import { SubstanceSsg4mService } from '../substance-ssg4m-form.service';
import * as htmlToImage from 'html-to-image';
import domToImage from 'dom-to-image';
import jsPDF from 'jspdf';
import * as moment from 'moment';

@Component({
selector: 'app-ssg4m-scheme-view',
Expand Down

0 comments on commit 5e2e72a

Please sign in to comment.