static Int4 NumberOfHetChains(MoleculeGraphPtr mgp, MoleculeGraphPtr bp) { ValNodePtr vnp; Int4 mtype, molecule_id, nhet = 0; CharPtr mname; while (mgp != NULL) { vnp = ValNodeFindNext(mgp->descr, NULL, BiomolDescr_molecule_type); if (vnp) mtype = vnp->data.intvalue; switch(mtype) { case 6: if (vnp = ValNodeFindNext(mgp->descr, NULL, BiomolDescr_name)) mname = vnp->data.ptrvalue; molecule_id = atoi(mname); if (isBiopoly(molecule_id, bp)) { nhet++; } break; } mgp = mgp->next; } return nhet; }
/*---------------- replace original seq_id by local_id --------------*/ void AssignLocaIdToBiostruc(SeqIdPtr sip, Char *PDBName, Char Chain,BiostrucPtr bsp) { BiostrucDescrPtr pbsdrThis = NULL; MoleculeGraphPtr pmgThis = NULL; BiomolDescrPtr pbmdrThis = NULL; Char ThisPDBName[Local_max], *ThisChain; StringCpy(ThisPDBName, PDBNAME_DEFAULT); pbsdrThis = ValNodeFindNext(bsp->descr, NULL, BiostrucDescr_name); if(pbsdrThis) StringNCpy(ThisPDBName, pbsdrThis ->data.ptrvalue, 4); /*if(StringCmp(PDBName, ThisPDBName) != 0) { printf("Something is wrong!\n"); return; } */ pmgThis = bsp->chemical_graph->molecule_graphs; while(pmgThis) { /* loop over molecule_graphs to match chain */ pbmdrThis = ValNodeFindNext(pmgThis->descr, NULL, BiomolDescr_name); if(pbmdrThis){ ThisChain = StringSave((CharPtr)pbmdrThis->data.ptrvalue); } else ThisChain = StringSave(STRING_UNK_MOL); if(Chain == *ThisChain) { pmgThis->seq_id = sip; return; } pmgThis = pmgThis->next; } }
static Int4 NumberOfBioChains(MoleculeGraphPtr mgp) { ValNodePtr vnp; Int4 mtype, nbp = 0; while (mgp != NULL) { vnp = ValNodeFindNext(mgp->descr, NULL, BiomolDescr_molecule_type); if (vnp) mtype = vnp->data.intvalue; switch(mtype) { case 1: case 2: case 3: nbp++; break; } mgp = mgp->next; } return nbp; }
static MoleculeGraphPtr MakeHetGraphPtr(MoleculeGraphPtr mgp, MoleculeGraphPtr bp) { MoleculeGraphPtr newhet, het = NULL, currenthet; ValNodePtr vnp; Int4 mtype, molecule_id; CharPtr mname; while (mgp != NULL) { vnp = ValNodeFindNext(mgp->descr, NULL, BiomolDescr_molecule_type); if (vnp) mtype = vnp->data.intvalue; switch(mtype) { case 6: vnp = ValNodeFindNext(mgp->descr, NULL, BiomolDescr_name); if (vnp) mname = vnp->data.ptrvalue; molecule_id = atoi(mname); if (isBiopoly(molecule_id, bp)) { newhet = MoleculeGraphNew(); newhet->id = mgp->id; newhet->descr = mgp->descr; newhet->seq_id = mgp->seq_id; newhet->residue_sequence = mgp->residue_sequence; newhet->inter_residue_bonds = mgp->inter_residue_bonds; if (het == NULL) { het = newhet; } else { currenthet->next = newhet; } currenthet = newhet; } break; } mgp = mgp->next; } return het; }
void LIBCALL AlignKinHeader(PDNMS pdnmsThis, FILE *pFile, Boolean master) { Int4 depyear, depday; PMSD pmsdThis = NULL; BiostrucSourcePtr pbssThis = NULL; ValNodePtr pvnThis = NULL; BiostrucHistoryPtr pbshThis = NULL; CharPtr pcAuthors = NULL; if (!pdnmsThis) return; pmsdThis = (PMSD) pdnmsThis->data.ptrvalue; pvnThis = ValNodeFindNext(pmsdThis->pbsBS->descr,NULL,BiostrucDescr_history); if (pvnThis) { pbshThis = (BiostrucHistoryPtr) pvnThis->data.ptrvalue; pbssThis = pbshThis->data_source; } if (!pmsdThis->pcPDBName) pmsdThis->pcPDBName = StringSave("1UNK"); fprintf(pFile,"Alignment Summary\n\n"); if (master) fprintf(pFile,"Master:\n%s\n\n", pmsdThis->pcChemName); else fprintf(pFile,"Slave:\n%s\n\n", pmsdThis->pcChemName); fflush(pFile); fprintf(pFile,"MMDB Accession:\n%ld\n\n", (long) pmsdThis->iMMDBid); fprintf(pFile,"PDB Accession:\n%s\n\n", pmsdThis->pcPDBName); fflush(pFile); if (pbssThis) { depyear = pbssThis->database_entry_date->data[1]; depday = pbssThis->database_entry_date->data[3]; fprintf(pFile,"PDB Deposition:\n%2d-%3s-%02d\n\n", (int) depday, NCBI_months[pbssThis->database_entry_date->data[2]-1], (int) depyear%100); } fprintf(pFile,"Class:\n%s\n\n", pmsdThis->pcPdbClass); fflush(pFile); fprintf(pFile,"Source:\n%s\n\n", pmsdThis->pcPdbSource); fflush(pFile); pcAuthors = AuthorListPDB(pmsdThis->pbsBS) ; if (pcAuthors) { fprintf(pFile,"Authors:\n%s\n\n", pcAuthors); fflush(pFile); MemFree(pcAuthors); } return; }
static MoleculeGraphPtr MakeBioGraphPtr(MoleculeGraphPtr mgp) { MoleculeGraphPtr newbp, bp = NULL, currentbp; ValNodePtr vnp; Int4 mtype; while (mgp != NULL) { vnp = ValNodeFindNext(mgp->descr, NULL, BiomolDescr_molecule_type); if (vnp) mtype = vnp->data.intvalue; switch(mtype) { case 1: case 2: case 3: newbp = MoleculeGraphNew(); newbp->id = mgp->id; newbp->descr = mgp->descr; newbp->seq_id = mgp->seq_id; newbp->residue_sequence = mgp->residue_sequence; newbp->inter_residue_bonds = mgp->inter_residue_bonds; if (bp == NULL) { bp = newbp; } else { currentbp->next = newbp; } currentbp = newbp; break; } mgp = mgp->next; } return bp; }
SeqEntryPtr LIBCALL MakeBioseqs(BiostrucPtr bsp, BiostrucResidueGraphSetPtr stdDictionary) { ValNodePtr vnp, seq_set, hetval, pvnThePoints; BiostrucHistoryPtr bhp; BiostrucSourcePtr bssp; BiostrucGraphPtr bsgp; BiostrucModelPtr bsmp; BiostrucFeatureSetPtr bsfsp; BiostrucFeaturePtr bsfp; ChemGraphPntrsPtr cgpp; ResiduePtr rs; ResidueGraphPtr rgp; ResiduePntrsPtr rpp; ResidueIntervalPntrPtr ripp; ResidueExplicitPntrsPtr rpp1=NULL, rpp2=NULL; MoleculeGraphPtr bp, het, currenthet, currentbp, mgp; InterResidueBondPtr currentabp, abp; DbtagPtr dtp; SeqEntryPtr pdb_entry; BioseqSetPtr biossp; BioseqPtr bioseqs[MAXNUM], current_bioseq; Int4 DomainNum, molId1, resId1, atmId1, molId2, resId2, atmId2; Int4 nbp, nhet, num_chain, index = 0, chnidx, bpchnidx, bpresidx, hetidx, rescount, bioseq_idx; Int4 ssresidx1, ssresidx2, ssmolidx1, ssmolidx2; CharPtr feature_name, rname; Boolean interchain, bonds, found1, found2; SeqAnnotPtr sap = NULL; SeqIdPtr sip; if (!bsp) { return NULL; } vnp = ValNodeFindNext(bsp->descr, NULL, BiostrucDescr_history); if (vnp) { bhp = (BiostrucHistoryPtr) vnp->data.ptrvalue; bssp = bhp->data_source; } bsgp = bsp->chemical_graph; bsmp = bsp->model; nbp = NumberOfBioChains(bsgp->molecule_graphs); bp = MakeBioGraphPtr(bsgp->molecule_graphs); nhet = NumberOfHetChains(bsgp->molecule_graphs, bp); het = MakeHetGraphPtr(bsgp->molecule_graphs, bp); pdb_entry = CreateSeqEntry(bssp, bsgp, bsmp, bsp->descr, nbp); if (IS_Bioseq(pdb_entry)) { vnp = ValNodeFindNext(pdb_entry, NULL, 1); bioseqs[index] = (BioseqPtr) vnp->data.ptrvalue; } else { vnp = ValNodeFindNext(pdb_entry, NULL, 2); biossp = (BioseqSetPtr) vnp->data.ptrvalue; seq_set = biossp->seq_set; for (num_chain = 0; num_chain < nbp, seq_set; seq_set = seq_set->next, num_chain++, index++) bioseqs[index] = (BioseqPtr) seq_set->data.ptrvalue; } dtp = (DbtagPtr)bssp->database_entry_id->data.ptrvalue; for (index = 0, currentbp = bp; index < nbp, currentbp != NULL; currentbp = currentbp->next, index++) { current_bioseq = bioseqs[index]; if (currentbp->seq_id->choice == '\f') { current_bioseq->id = MakePDBId(bssp, currentbp, dtp); sip = ValNodeNew(NULL); sip->choice = SEQID_GI; sip->data.intvalue = currentbp->seq_id->data.intvalue; current_bioseq->id->next = sip; } else if (currentbp->seq_id->choice == SEQID_LOCAL) current_bioseq->id = MakeLocalID(-99999, currentbp, dtp); current_bioseq->descr = MakeBioseqDescr(currentbp, current_bioseq->descr); current_bioseq->mol = MakeBioseqMol(currentbp); current_bioseq->length = CountNumOfResidues(currentbp); if (current_bioseq->mol == Seq_mol_aa) current_bioseq->seq_data_type = Seq_code_iupacaa; else current_bioseq->seq_data_type = Seq_code_iupacna; current_bioseq->seq_data = AddSeqData(currentbp, current_bioseq->mol, current_bioseq->length, bsgp, stdDictionary); current_bioseq->annot = AddNstdSeqAnnot(currentbp, current_bioseq->id, bsgp); } /* Add information about Secondary Structure and Domains */ for (bsfsp = bsp->features, DomainNum = 0; bsfsp; bsfsp = bsfsp->next) { if (vnp = ValNodeFindNext(bsfsp->descr, NULL, BiostrucFeatureSetDescr_name)) feature_name = vnp->data.ptrvalue; if ((!StringICmp("NCBI assigned secondary structure", feature_name)) || (!StringICmp("NCBI Domains", feature_name))) { for (bsfp = bsfsp->features; bsfp; bsfp = bsfp->next) { cgpp = (ChemGraphPntrsPtr)bsfp->Location_location->data.ptrvalue; rpp = (ResiduePntrsPtr)cgpp->data.ptrvalue; ripp = (ResidueIntervalPntrPtr)rpp->data.ptrvalue; chnidx = findChnidx(ripp->molecule_id, nbp, bp); current_bioseq = bioseqs[chnidx-1]; if (!StringICmp("NCBI Domains", feature_name)) DomainNum++; if (current_bioseq->annot) current_bioseq->annot = AddSecDomToSeqAnnot(bsfp, feature_name, current_bioseq->annot, current_bioseq->id, DomainNum); else current_bioseq->annot = AddSecDomToSeqAnnot(bsfp, feature_name, NULL, current_bioseq->id, DomainNum); } } } for (index = 0, currenthet = het; index < nhet, currenthet; currenthet = currenthet->next, index++) { hetval = MakeHetValNode(currenthet, stdDictionary, bsgp->residue_graphs); bioseq_idx = 0; interchain = FALSE; for (abp = bsgp->inter_molecule_bonds, bonds = FALSE, rescount = 0; abp; abp = abp->next) { molId1 = abp->atom_id_1->molecule_id; molId2 = abp->atom_id_2->molecule_id; resId1 = abp->atom_id_1->residue_id; resId2 = abp->atom_id_2->residue_id; atmId1 = abp->atom_id_1->atom_id; atmId2 = abp->atom_id_2->atom_id; if (isBiopoly(molId1, bp) && isHet(molId2, het)) { bpchnidx = molId1 - 1; bpresidx = resId1 - 1; hetidx = getHetIdx(molId2, het); bonds = TRUE; } else if (isBiopoly(molId2, bp) && isHet(molId1, het)) { bpchnidx = molId2 - 1; bpresidx = resId2 - 1; hetidx = getHetIdx(molId1, het); bonds = TRUE; } if (bonds) { if (hetidx == index) { if (!rescount) pvnThePoints = NULL; ValNodeAddInt(&pvnThePoints, 0, bpresidx); rescount++; if (bioseq_idx >= 0) { if (bioseq_idx != bpchnidx) interchain = TRUE; } bioseq_idx = bpchnidx; } } } if (rescount) { if (!interchain) { current_bioseq = bioseqs[bioseq_idx]; if (current_bioseq->annot) current_bioseq->annot = AddHetToSeqAnnot(current_bioseq->annot, current_bioseq->id, hetval, pvnThePoints, rescount); else current_bioseq->annot = AddHetToSeqAnnot(NULL, current_bioseq->id, hetval, pvnThePoints, rescount); } if (interchain) { if (IS_Bioseq(pdb_entry)) sap = ((BioseqPtr)(pdb_entry->data.ptrvalue))->annot; else sap = ((BioseqSetPtr)(pdb_entry->data.ptrvalue))->annot; if (sap == NULL) { sap = SeqAnnotNew(); sap->type = 1; if (IS_Bioseq(pdb_entry)) ((BioseqPtr)(pdb_entry->data.ptrvalue))->annot = sap; else ((BioseqSetPtr)(pdb_entry->data.ptrvalue))->annot = sap; } sap = AddHetToSeqAnnot(sap, bioseqs[bioseq_idx]->id, hetval, pvnThePoints, rescount); } } else { current_bioseq = bioseqs[bioseq_idx]; vnp = current_bioseq->descr; if (vnp != NULL) { while (vnp->next != NULL) vnp = vnp->next; vnp->next = hetval; } else current_bioseq->descr = hetval; } } mgp = bsgp->molecule_graphs; abp = bsgp->inter_molecule_bonds; while(1) { if (mgp != NULL) { currentabp = mgp->inter_residue_bonds; mgp = mgp->next; } while (currentabp != NULL) { molId1 = currentabp->atom_id_1->molecule_id; molId2 = currentabp->atom_id_2->molecule_id; resId1 = currentabp->atom_id_1->residue_id; resId2 = currentabp->atom_id_2->residue_id; atmId1 = currentabp->atom_id_1->atom_id; atmId2 = currentabp->atom_id_2->atom_id; interchain = FALSE; found1 = FALSE; found2 = FALSE; if ((getAtomElementIdx(molId1, resId1, atmId1, bsgp, stdDictionary)==16) && (getAtomElementIdx(molId2, resId2, atmId2, bsgp, stdDictionary)==16)) { /* Found possible disulfide bonds. */ if (isBiopoly(molId1, bp) && isBiopoly(molId2, bp)) { currentbp = bp; for (index=0; index<findChnidx(molId1, nbp, bp)-1; index++) currentbp = currentbp->next; rs = currentbp->residue_sequence; while (rs) { if (rs->id == resId1) { rgp = getResGraph(rs->residue_graph, bsgp, stdDictionary); break; } rs = rs->next; } if (vnp = ValNodeFindNext(rgp->descr, NULL, BiomolDescr_name)) rname = vnp->data.ptrvalue; if (!StringICmp(rname, "CYS")) found1 = TRUE; currentbp = bp; for (index = 0; index < findChnidx(molId2, nbp, bp)-1; index++) currentbp = currentbp->next; rs = currentbp->residue_sequence; while (rs) { if (rs->id == resId2) { rgp = getResGraph(rs->residue_graph, bsgp, stdDictionary); break; } rs = rs->next; } if (vnp = ValNodeFindNext(rgp->descr, NULL, BiomolDescr_name)) rname = vnp->data.ptrvalue; if (!StringICmp(rname, "CYS")) found2 = TRUE; if (found1 && found2) { ssresidx1 = resId1 - 1; ssresidx2 = resId2 - 1; ssmolidx1 = molId1 - 1; ssmolidx2 = molId2 - 1; chnidx = findChnidx(molId1, nbp, bp); if (ssmolidx1 == ssmolidx2) { current_bioseq = bioseqs[chnidx - 1]; if (current_bioseq->annot) current_bioseq->annot = AddDisulToSeqAnnot(current_bioseq->annot, ssresidx1, ssresidx2, current_bioseq->id, current_bioseq->id); else current_bioseq->annot = AddDisulToSeqAnnot(NULL, ssresidx1, ssresidx2, current_bioseq->id, current_bioseq->id); } else { if (IS_Bioseq(pdb_entry)) sap = ((BioseqPtr)(pdb_entry->data.ptrvalue))->annot; else sap = ((BioseqSetPtr)(pdb_entry->data.ptrvalue))->annot; if (sap == NULL) { sap = SeqAnnotNew(); sap->type = 1; if (IS_Bioseq(pdb_entry)) ((BioseqPtr)(pdb_entry->data.ptrvalue))->annot = sap; else ((BioseqSetPtr)(pdb_entry->data.ptrvalue))->annot = sap; } sap = AddDisulToSeqAnnot(sap, ssresidx1, ssresidx2, bioseqs[ssmolidx1]->id, bioseqs[ssmolidx2]->id); } } } } currentabp = currentabp->next; } if ((currentabp == NULL) && (mgp == NULL) && (abp == NULL)) break; else if((currentabp == NULL) && (mgp == NULL) && (abp != NULL)) { currentabp = abp; abp = NULL; } } return pdb_entry; }
Boolean CopyBiomolecule(PMSD pmsdTo, PDNMM pdnmmThisMolecule ) { PDNMM pdnmmHeadTo = NULL, pdnmmLastTo = NULL, pdnmmParentTo = NULL, pdnmmHereTo; PMMD pmmdTo = NULL, pmmdHereTo = NULL,pmmdChain=NULL; PMLD pmldTo = NULL; PDNML pdnmlTo = NULL; Boolean addedChain = FALSE; SeqIdPtr sip; PDBSeqIdPtr psp; ValNodePtr vnp = NULL; CharPtr chnid = NULL; /* ErrPostEx(SEV_WARNING,0,0,"Copy chain %s To structure %ld", NextUniqueChainName(pmsdTo), pmsdTo-iMMDBid); */ pdnmmHeadTo = pmsdTo->pdnmmHead; pmmdTo = (PMMD)(pdnmmHeadTo->data.ptrvalue); /*For trades generated structures, give every chain a chain name*/ /* Copy the molecule pdnmmThisMolecule in its entirety to pmsdTo */ /* Grab the last molecule in the TO list. This is where new chains will be appended */ pdnmmLastTo = pdnmmHeadTo; while(pdnmmLastTo) { pmmdChain=(PMMD)pdnmmLastTo->data.ptrvalue; /*pmmdChain->pcMolName = NextUniqueChainName(pmsdTo);*/ /* printf("pmmdchain->pcMolname here is a%da\n",pmmdChain->pcMolName[0]); */ /* change the original PDB id codes to be unique from RAND to RNDx for multi-chain Cn3D lookups*/ sip = pmmdChain->pSeqId; if (sip != NULL) if (sip->choice == SEQID_PDB) { psp = sip->data.ptrvalue; if (!StringCmp(psp->mol,"RAND")) { /* printf("RAND CASE ALTERING IN CHEMICAL GRAPH\n"); */ if (pmmdChain->pcMolName[0]==(Uint1) '\0'){ pmmdChain->pcMolName[0]= (Uint1) 'A'; /* printf("changed to a\n"); */ } psp->mol[0] = '\0'; StringCpy(psp->mol,"RND"); psp->mol[3]= (Uint1) *(pmmdChain->pcMolName); psp->mol[4] = '\0'; psp->chain = (Uint1) *(pmmdChain->pcMolName); psp->rel = DateCurr(); /* must also change the chain code in the ASN.1 stub */ if (vnp = ValNodeFindNext(pmmdChain->pMolDescr, NULL, BiomolDescr_name)) chnid = vnp->data.ptrvalue; chnid[0] = (Uint1) pmmdChain->pcMolName[0]; } } if(!pdnmmLastTo->next) { break; } pdnmmLastTo = pdnmmLastTo->next; } /* printf("Original Changes Phase Done \n"); */ /* Add chain to modelstruc */ if(CopyNewChain(pdnmmThisMolecule, pdnmmLastTo,pmsdTo)) { addedChain = TRUE; pdnmmLastTo = pdnmmLastTo->next; } if(addedChain) { ErrPostEx(SEV_WARNING,0,0,"Created new chain"); } /* this message appears in ribosome processing bug as last warning before it goes off endless loop*/ /*88888888888888888888888888888888888888888*/ /* free-err double free-ing perhaps? - or a dictionary bug modelstruc loaders wipe out ppAsnOrder if the are too large in memory...? still true? if so this fixes the freeing so it is pointer safe */ if(addedChain) { /* Usage of ppAsnOrder appears to be optional. For purposes of speed, it is freed instead of updated */ pdnmlTo = pmsdTo->pdnmlModels; if (pdnmlTo) { pmldTo = (PMLD)(pdnmlTo->data.ptrvalue); if (pmldTo) if(pmldTo->ppAsnOrder) { PTRVectorFree(pmldTo->ppAsnOrder,0); pmldTo->ppAsnOrder = NULL; } } } return TRUE; }