1 /* @source ajdmx **************************************************************
2 **
3 ** AJAX library code for some of the DOMAINATRIX EMBASSY applications.
4 ** For use with the Scophit and Scopalign objects. The code is disparate
5 ** including low-level functions and algorithms. The functionality will
6 ** eventually be subsumed by other AJAX and NUCLEUS libraries.
7 **
8 ** @author Copyright (C) 2004 Ranjeeva Ranasinghe (rranasin@hgmp.mrc.ac.uk)
9 ** @author Copyright (C) 2004 Jon Ison (jison@hgmp.mrc.ac.uk)
10 ** @version $Revision: 1.40 $
11 ** @modified $Date: 2012/07/02 16:47:42 $ by $Author: rice $
12 ** @@
13 **
14 ** This library is free software; you can redistribute it and/or
15 ** modify it under the terms of the GNU Lesser General Public
16 ** License as published by the Free Software Foundation; either
17 ** version 2.1 of the License, or (at your option) any later version.
18 **
19 ** This library is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ** Lesser General Public License for more details.
23 **
24 ** You should have received a copy of the GNU Lesser General Public
25 ** License along with this library; if not, write to the Free Software
26 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 ** MA 02110-1301, USA.
28 **
29 ******************************************************************************/
30
31 /* ========================================================================= */
32 /* ============================= include files ============================= */
33 /* ========================================================================= */
34
35 #include "ajlib.h"
36
37 #include "ajdmx.h"
38 #include "ajarr.h"
39 #include "ajmath.h"
40 #include "ajfileio.h"
41 #include "ajseqwrite.h"
42
43 #include <math.h>
44
45
46
47
48 /* ========================================================================= */
49 /* =============================== constants =============================== */
50 /* ========================================================================= */
51
52
53
54
55 /* ========================================================================= */
56 /* =========================== global variables ============================ */
57 /* ========================================================================= */
58
59
60
61
62 /* ========================================================================= */
63 /* ============================= private data ============================== */
64 /* ========================================================================= */
65
66
67
68
69 /* ========================================================================= */
70 /* =========================== private constants =========================== */
71 /* ========================================================================= */
72
73
74
75
76 /* ========================================================================= */
77 /* =========================== private variables =========================== */
78 /* ========================================================================= */
79
80
81
82
83 static AjPStr dmxGStrline = NULL; /* Line of text */
84 static AjPStr dmxGStrtype = NULL;
85 static AjPStr dmxGStrclass = NULL;
86 static AjPStr dmxGStrfold = NULL;
87 static AjPStr dmxGStrsuper = NULL;
88 static AjPStr dmxGStrfamily = NULL;
89 static AjPStr dmxGStrarch = NULL;
90 static AjPStr dmxGStrtopo = NULL;
91 static AjPStr dmxGStrpostsim = NULL; /* Post-similar line */
92 static AjPStr dmxGStrposttmp = NULL; /* Temp. storage for post-similar line */
93
94 static AjPStr dmxGStrposisim = NULL; /* Positions line */
95 static AjPStr dmxGStrpositmp = NULL; /* Temp. storage for Positions line */
96 static AjPStr dmxGStrseq1 = NULL;
97 static AjPStr dmxGStrcodetmp = NULL; /* Id code of sequence */
98
99
100
101
102 /* ========================================================================= */
103 /* =========================== private functions =========================== */
104 /* ========================================================================= */
105
106
107
108
109 static void dmxTraceScophit(const AjPScophit scophit, const char *title);
110
111
112
113
114 /* ========================================================================= */
115 /* ======================= All functions by section ======================== */
116 /* ========================================================================= */
117
118
119
120
121 /* @section Constructors ******************************************************
122 **
123 ** All constructors return a pointer to a new instance. It is the
124 ** responsibility of the user to first destroy any previous instance. The
125 ** target pointer does not need to be initialised to NULL, but it is good
126 ** programming practice to do so anyway.
127 **
128 ******************************************************************************/
129
130
131
132
133 /* @func ajDmxScophitNew ******************************************************
134 **
135 ** Constructor for an AJAX SCOP Hit object.
136 **
137 ** @return [AjPScophit] AJAX SCOP Hit object
138 **
139 ** @release 2.9.0
140 ** @@
141 ******************************************************************************/
142
ajDmxScophitNew(void)143 AjPScophit ajDmxScophitNew(void)
144 {
145 AjPScophit scophit = NULL;
146
147 AJNEW0(scophit);
148
149 scophit->Class = ajStrNew();
150 scophit->Architecture = ajStrNew();
151 scophit->Topology = ajStrNew();
152 scophit->Fold = ajStrNew();
153 scophit->Superfamily = ajStrNew();
154 scophit->Family = ajStrNew();
155 scophit->Seq = ajStrNew();
156 scophit->Acc = ajStrNew();
157 scophit->Spr = ajStrNew();
158 scophit->Dom = ajStrNew();
159 scophit->Typeobj = ajStrNew();
160 scophit->Typesbj = ajStrNew();
161 scophit->Model = ajStrNew();
162 scophit->Alg = ajStrNew();
163 scophit->Group = ajStrNew();
164 scophit->Start = 0U;
165 scophit->End = 0U;
166 scophit->Rank = 0U;
167 scophit->Score = 0.0F;
168 scophit->Sunid_Family = 0U;
169 scophit->Eval = 0.0F;
170 scophit->Pval = 0.0F;
171 scophit->Target = ajFalse;
172 scophit->Target2 = ajFalse;
173 scophit->Priority = ajFalse;
174
175 return scophit;
176 }
177
178
179
180
181 /* @func ajDmxScopalgNew ******************************************************
182 **
183 ** Constructor for an AJAX SCOP Alignment object.
184 ** This is normally called by the ajDmxScopalgRead function.
185 ** Fore-knowledge of the number of sequences is required.
186 **
187 ** @param [r] n [ajuint] Number of sequences
188 **
189 ** @return [AjPScopalg] AJAX SCOP Alignment object
190 **
191 ** @release 2.9.0
192 ** @@
193 ******************************************************************************/
194
ajDmxScopalgNew(ajuint n)195 AjPScopalg ajDmxScopalgNew(ajuint n)
196 {
197 ajuint i = 0U;
198
199 AjPScopalg scopalg = NULL;
200
201 AJNEW0(scopalg);
202
203 scopalg->Class = ajStrNew();
204 scopalg->Architecture = ajStrNew();
205 scopalg->Topology = ajStrNew();
206 scopalg->Fold = ajStrNew();
207 scopalg->Superfamily = ajStrNew();
208 scopalg->Family = ajStrNew();
209 scopalg->Architecture = ajStrNew();
210 scopalg->Topology = ajStrNew();
211 scopalg->Post_similar = ajStrNew();
212 scopalg->Positions = ajStrNew();
213 scopalg->Width = 0;
214 scopalg->Number = n;
215
216 if(n)
217 {
218 AJCNEW0(scopalg->Codes, n);
219
220 for(i = 0U; i < n; i++)
221 scopalg->Codes[i] = ajStrNew();
222
223 AJCNEW0(scopalg->Seqs, n);
224
225 for(i = 0U; i < n; i++)
226 scopalg->Seqs[i] = ajStrNew();
227 }
228
229 return scopalg;
230 }
231
232
233
234
235 /* @func ajDmxScopalgRead *****************************************************
236 **
237 ** Read an AJAX SCOP Alignment object from an AJAX File.
238 **
239 ** @param [u] inf [AjPFile] Input AJAX File
240 ** @param [w] Pscopalg [AjPScopalg*] AJAX SCOP Alignment address
241 **
242 ** @return [AjBool] True if the file contained any data, even an empty
243 ** alignment. False if the file did not contain a 'TY' record, which is
244 ** taken to indicate a domain alignment file.
245 **
246 ** @release 2.9.0
247 ** @@
248 ******************************************************************************/
249
ajDmxScopalgRead(AjPFile inf,AjPScopalg * Pscopalg)250 AjBool ajDmxScopalgRead(AjPFile inf, AjPScopalg *Pscopalg)
251 {
252 AjBool ok = ajFalse; /* True if the file contained 'TY' record. */
253
254 AjBool done_1st_blk = ajFalse; /* Flag for whether we've read first
255 block of sequences */
256
257 ajuint i = 0U; /* Loop counter */
258 ajuint j = 0U; /* Loop counter */
259
260 ajint cnt = 0; /* Temp. counter of sequence */
261 ajuint nseq = 0U; /* No. of sequences in alignment */
262 ajint Sunid = 0; /* SCOP Sunid for family */
263 ajint ntok = 0; /*
264 * No. string tokens in sequence line from alignment.
265 * Sequence start and end may or may not be present,
266 * therefore ntok is either 2 or 4:
267 * (2) (ACC SEQ ) or
268 * (4) (ACC start SEQ end)
269 */
270
271 AjPList list_seqs = NULL; /* List of sequences */
272 AjPList list_codes = NULL; /* List of codes */
273 AjPStr *arr_seqs = NULL; /* Array of sequences */
274 AjPStr seq = NULL;
275 AjPStr code = NULL; /* Id code of sequence */
276
277 /* Check args */
278 if(!inf)
279 return ajFalse;
280
281 if(!Pscopalg)
282 return ajFalse;
283
284 /* Allocate strings */
285 /* Only initialise strings if this is called for the first time */
286 if(!dmxGStrline)
287 {
288 dmxGStrtype = ajStrNew();
289 dmxGStrclass = ajStrNew();
290 dmxGStrfold = ajStrNew();
291 dmxGStrsuper = ajStrNew();
292 dmxGStrfamily = ajStrNew();
293 dmxGStrarch = ajStrNew();
294 dmxGStrtopo = ajStrNew();
295 dmxGStrline = ajStrNew();
296 dmxGStrpostsim = ajStrNew();
297 dmxGStrposttmp = ajStrNew();
298 dmxGStrposisim = ajStrNew();
299 dmxGStrpositmp = ajStrNew();
300 dmxGStrcodetmp = ajStrNew();
301 dmxGStrseq1 = ajStrNew();
302 }
303
304 /* Create new lists */
305 list_seqs = ajListstrNew();
306 list_codes = ajListstrNew();
307
308 /* Read the rest of the file */
309 while(ajReadlineTrim(inf, &dmxGStrline))
310 {
311 if(ajStrPrefixC(dmxGStrline, "# TY"))
312 {
313 ok = ajTrue;
314 ajStrAssignC(&dmxGStrtype, ajStrGetPtr(dmxGStrline) + 5);
315 ajStrRemoveWhiteExcess(&dmxGStrtype);
316 }
317 else if(ajStrPrefixC(dmxGStrline, "# SI"))
318 {
319 ajFmtScanS(dmxGStrline, "%*s %*s %d", &Sunid);
320 }
321 else if(ajStrPrefixC(dmxGStrline, "# CL"))
322 {
323 ajStrAssignC(&dmxGStrclass, ajStrGetPtr(dmxGStrline) + 5);
324 ajStrRemoveWhiteExcess(&dmxGStrclass);
325 }
326 else if(ajStrPrefixC(dmxGStrline, "# FO"))
327 {
328 ajStrAssignC(&dmxGStrfold, ajStrGetPtr(dmxGStrline) + 5);
329
330 while((ajReadlineTrim(inf, &dmxGStrline)))
331 {
332 if(ajStrPrefixC(dmxGStrline, "# XX"))
333 break;
334
335 ajStrAppendC(&dmxGStrfold, ajStrGetPtr(dmxGStrline) + 5);
336 }
337
338 ajStrRemoveWhiteExcess(&dmxGStrfold);
339 }
340 else if(ajStrPrefixC(dmxGStrline, "# SF"))
341 {
342 ajStrAssignC(&dmxGStrsuper, ajStrGetPtr(dmxGStrline) + 5);
343
344 while((ajReadlineTrim(inf, &dmxGStrline)))
345 {
346 if(ajStrPrefixC(dmxGStrline, "# XX"))
347 break;
348
349 ajStrAppendC(&dmxGStrsuper, ajStrGetPtr(dmxGStrline) + 5);
350 }
351
352 ajStrRemoveWhiteExcess(&dmxGStrsuper);
353 }
354 else if(ajStrPrefixC(dmxGStrline, "# FA"))
355 {
356 ajStrAssignC(&dmxGStrfamily, ajStrGetPtr(dmxGStrline) + 5);
357
358 while((ajReadlineTrim(inf, &dmxGStrline)))
359 {
360 if(ajStrPrefixC(dmxGStrline, "# XX"))
361 break;
362
363 ajStrAppendC(&dmxGStrfamily, ajStrGetPtr(dmxGStrline) + 5);
364 }
365
366 ajStrRemoveWhiteExcess(&dmxGStrfamily);
367 }
368 else if(ajStrPrefixC(dmxGStrline, "# AR"))
369 {
370 ajStrAssignC(&dmxGStrarch, ajStrGetPtr(dmxGStrline) + 5);
371
372 while((ajReadlineTrim(inf, &dmxGStrline)))
373 {
374 if(ajStrPrefixC(dmxGStrline, "# XX"))
375 break;
376
377 ajStrAppendC(&dmxGStrarch, ajStrGetPtr(dmxGStrline) + 5);
378 }
379
380 ajStrRemoveWhiteExcess(&dmxGStrarch);
381 }
382 else if(ajStrPrefixC(dmxGStrline, "# TP"))
383 {
384 ajStrAssignC(&dmxGStrtopo, ajStrGetPtr(dmxGStrline) + 5);
385
386 while((ajReadlineTrim(inf, &dmxGStrline)))
387 {
388 if(ajStrPrefixC(dmxGStrline, "# XX"))
389 break;
390
391 ajStrAppendC(&dmxGStrtopo, ajStrGetPtr(dmxGStrline) + 5);
392 }
393
394 ajStrRemoveWhiteExcess(&dmxGStrtopo);
395 }
396 else if(ajStrPrefixC(dmxGStrline, "# XX"))
397 continue;
398 else if (ajStrPrefixC(dmxGStrline, "# Post_similar"))
399 {
400 /* Parse post_similar line */
401 ajFmtScanS(dmxGStrline, "%*s %*s %S", &dmxGStrposttmp);
402
403 if(done_1st_blk == ajTrue)
404 ajStrAppendS(&dmxGStrpostsim, dmxGStrposttmp);
405 else
406 ajStrAssignS(&dmxGStrpostsim, dmxGStrposttmp);
407
408 continue;
409 }
410 else if (ajStrPrefixC(dmxGStrline, "# Positions"))
411 {
412 /* Parse Positions line */
413 ajFmtScanS(dmxGStrline, "%*s %*s %S", &dmxGStrpositmp);
414
415 if(done_1st_blk == ajTrue)
416 ajStrAppendS(&dmxGStrposisim, dmxGStrpositmp);
417 else
418 ajStrAssignS(&dmxGStrposisim, dmxGStrpositmp);
419
420 continue;
421 }
422 /* Ignore any other line beginning with '#' which are
423 taken to be comments, e.g. 'Number' lines */
424 else if((ajStrPrefixC(dmxGStrline ,"#")))
425 continue;
426 /* ajFileReadLine will have trimmed the tailing \n */
427 else if(ajStrGetCharPos(dmxGStrline, 1) == '\0')
428 {
429 /*
430 ** The first blank line therefore the first block of sequences
431 ** has been done
432 */
433
434 if(!ok)
435 {
436 ajWarn("ajDmxScopalgRead but file was not identified as "
437 "being a domain alignment file");
438 return ajFalse;
439 }
440
441 done_1st_blk = ajTrue;
442 j++;
443
444 if(j == 1)
445 ajListstrToarray(list_seqs, &arr_seqs);
446
447 cnt = 0;
448 continue;
449 }
450 else
451 {
452 /* Line of sequence */
453 if(!ok)
454 {
455 ajWarn("ajDmxScopalgRead but file was not identified as "
456 "being a domain alignment file");
457 return ajFalse;
458 }
459
460 /* Parse a line of sequence */
461 if(done_1st_blk == ajTrue)
462 {
463 /* already read in the first block of sequences */
464 if(ntok == 4)
465 ajFmtScanS(dmxGStrline, "%*s %*s %S", &dmxGStrseq1);
466 else if(ntok == 2)
467 ajFmtScanS(dmxGStrline, "%*s %S", &dmxGStrseq1);
468 else
469 ajFatal("ajDmxScopalgRead could not parse alignment");
470
471 ajStrAppendS(&arr_seqs[cnt], dmxGStrseq1);
472 cnt++;
473 continue;
474 }
475 else
476 {
477 /* It is a sequence line from the first block */
478 nseq++;
479 seq = ajStrNew();
480 code = ajStrNew();
481
482 if(((ntok = ajStrParseCountC(dmxGStrline, " ")) == 4))
483 ajFmtScanS(dmxGStrline, "%S %*s %S", &code, &seq);
484 else if(ntok == 2)
485 ajFmtScanS(dmxGStrline, "%S %S", &code, &seq);
486 else
487 ajFatal("ajDmxScopalgRead could not parse alignment");
488
489 /* Push strings onto lists */
490 ajListstrPushAppend(list_seqs, seq);
491 ajListstrPushAppend(list_codes, code);
492 continue;
493 }
494 }
495 }
496
497 if(!ok)
498 {
499 ajWarn("ajDmxScopalgRead but file was not identified as being "
500 "a domain alignment file");
501
502 return ajFalse;
503 }
504
505 /*
506 ** Cope for cases where alignment is in one block only,
507 ** i.e. there were no empty lines:
508 **
509 ** XX
510 ** # Number 10 20 30 40 50
511 ** d1bsna1 1 QDLDEARAMEAKRKAEEHISSSHGDVDYAQASAELAKAIAQLRVIELTKK 50
512 ** d1e79h1 1 DMLDLGAAKANLEKAQSELLGAADEATRAEIQIRIEANEALVKAL----- 43
513 ** # Post_similar 111111111111111111111111111111111111111111111-----
514 */
515 if(!done_1st_blk && nseq)
516 ajListstrToarray(list_seqs, &arr_seqs);
517
518 ajStrDel(&dmxGStrseq1);
519
520 if(!nseq)
521 ajWarn("No sequences in alignment !\n");
522
523 /* Allocate memory for Scopalg structure */
524 *Pscopalg = ajDmxScopalgNew(nseq);
525
526 /* Assign domain records */
527 if(ajStrMatchC(dmxGStrtype, "SCOP"))
528 (*Pscopalg)->Type = ajEDomainTypeSCOP;
529 else if(ajStrMatchC(dmxGStrtype, "CATH"))
530 (*Pscopalg)->Type = ajEDomainTypeCATH;
531
532 ajStrAssignS(&(*Pscopalg)->Class, dmxGStrclass);
533 ajStrAssignS(&(*Pscopalg)->Architecture, dmxGStrarch);
534 ajStrAssignS(&(*Pscopalg)->Topology, dmxGStrtopo);
535 ajStrAssignS(&(*Pscopalg)->Fold, dmxGStrfold);
536 ajStrAssignS(&(*Pscopalg)->Superfamily, dmxGStrsuper);
537 ajStrAssignS(&(*Pscopalg)->Family, dmxGStrfamily);
538 (*Pscopalg)->Sunid_Family = Sunid;
539
540 if(nseq)
541 {
542 /* Assign sequences and free memory */
543 for(i = 0U; i < nseq; i++)
544 {
545 ajStrAssignS(&(*Pscopalg)->Seqs[i], arr_seqs[i]);
546 ajStrDel(&arr_seqs[i]);
547 }
548 AJFREE(arr_seqs);
549
550 /* Assign width */
551 (*Pscopalg)->Width = ajStrGetLen((*Pscopalg)->Seqs[0]);
552
553 for(i = 0U; ajListstrPop(list_codes, &dmxGStrcodetmp); i++)
554 {
555 ajStrAssignS(&(*Pscopalg)->Codes[i], dmxGStrcodetmp);
556 ajStrDel(&dmxGStrcodetmp);
557 }
558
559 /* Assign Post_similar line */
560 ajStrAssignS(&(*Pscopalg)->Post_similar, dmxGStrpostsim);
561
562 /* Assign Positions line */
563 ajStrAssignS(&(*Pscopalg)->Positions, dmxGStrposisim);
564 }
565 else
566 ajWarn("ajDmxScopalgRead called but no sequences found.");
567
568 ajListstrFree(&list_seqs);
569 ajListstrFree(&list_codes);
570
571 return ajTrue;
572 }
573
574
575
576
577 /* @section Structure Destructors *********************************************
578 **
579 ** All destructor functions receive the address of the instance to be
580 ** deleted. The original pointer is set to NULL so is ready for re-use.
581 **
582 ******************************************************************************/
583
584
585
586
587 /* @func ajDmxScophitDel ******************************************************
588 **
589 ** Destructor for an AJAX SCOP Hit object.
590 **
591 ** @param [w] Pscophit [AjPScophit*] AJAX Scophit address
592 **
593 ** @return [void]
594 **
595 ** @release 2.9.0
596 ** @@
597 ******************************************************************************/
598
ajDmxScophitDel(AjPScophit * Pscophit)599 void ajDmxScophitDel(AjPScophit *Pscophit)
600 {
601 AjPScophit scophit = NULL;
602
603 if(!Pscophit || !*Pscophit)
604 return;
605
606 scophit = *Pscophit;
607
608 ajStrDel(&scophit->Class);
609 ajStrDel(&scophit->Architecture);
610 ajStrDel(&scophit->Topology);
611 ajStrDel(&scophit->Fold);
612 ajStrDel(&scophit->Superfamily);
613 ajStrDel(&scophit->Family);
614 ajStrDel(&scophit->Seq);
615 ajStrDel(&scophit->Acc);
616 ajStrDel(&scophit->Spr);
617 ajStrDel(&scophit->Dom);
618 ajStrDel(&scophit->Typeobj);
619 ajStrDel(&scophit->Typesbj);
620 ajStrDel(&scophit->Model);
621 ajStrDel(&scophit->Alg);
622 ajStrDel(&scophit->Group);
623
624 AJFREE(scophit);
625
626 *Pscophit = NULL;
627
628 return;
629 }
630
631
632
633
634 /* @func ajDmxScophitDelWrap **************************************************
635 **
636 ** Wrapper to destructor for an AJAX SCOP Hit object for use with generic
637 ** functions.
638 **
639 ** @param [d] Pitem [void**] AJAX SCOP Hit address
640 ** @see ajListPurge
641 **
642 ** @return [void]
643 **
644 ** @release 2.9.0
645 ** @@
646 ******************************************************************************/
647
ajDmxScophitDelWrap(void ** Pitem)648 void ajDmxScophitDelWrap(void **Pitem)
649 {
650 ajDmxScophitDel((AjPScophit *) Pitem);
651
652 return;
653 }
654
655
656
657
658 /* @func ajDmxScopalgDel ******************************************************
659 **
660 ** Destructor for an AJAX SCOP Alignment object.
661 **
662 ** @param [d] Pscopalg [AjPScopalg*] AJAX SCOP Alignment address
663 **
664 ** @return [void]
665 **
666 ** @release 2.9.0
667 ** @@
668 ******************************************************************************/
669
ajDmxScopalgDel(AjPScopalg * Pscopalg)670 void ajDmxScopalgDel(AjPScopalg *Pscopalg)
671 {
672 ajuint i = 0U;
673
674 AjPScopalg scopalg = NULL;
675
676 if(!Pscopalg || !*Pscopalg)
677 return;
678
679 scopalg = *Pscopalg;
680
681 ajStrDel(&scopalg->Class);
682 ajStrDel(&scopalg->Architecture);
683 ajStrDel(&scopalg->Topology);
684 ajStrDel(&scopalg->Fold);
685 ajStrDel(&scopalg->Superfamily);
686 ajStrDel(&scopalg->Family);
687 ajStrDel(&scopalg->Architecture);
688 ajStrDel(&scopalg->Topology);
689 ajStrDel(&scopalg->Post_similar);
690 ajStrDel(&scopalg->Positions);
691
692 for(i = 0U; i < scopalg->Number; i++)
693 {
694 ajStrDel(&scopalg->Codes[i]);
695 ajStrDel(&scopalg->Seqs[i]);
696 }
697
698 AJFREE(scopalg->Codes);
699 AJFREE(scopalg->Seqs);
700
701 AJFREE(scopalg);
702
703 *Pscopalg = NULL;
704
705 return;
706 }
707
708
709
710
711 /* @section Assignments *******************************************************
712 **
713 ** These functions overwrite the instance provided as the first argument
714 ** A NULL value is always acceptable so these functions are often used to
715 ** create a new instance by assignment.
716 **
717 ******************************************************************************/
718
719
720
721
722 /* @func ajDmxScophitListCopy *************************************************
723 **
724 ** Read an AJAX List of AJAX SCOP Hit objects and return a pointer to a
725 ** duplicate of the AJAX List.
726 **
727 ** @param [r] scophits [const AjPList] AJAX List of AJAX SCOP Hit objects
728 **
729 ** @return [AjPList] True on success (list was duplicated ok)
730 **
731 ** @release 2.9.0
732 ** @@
733 **
734 ** Should modify this eventually to fit "standard" method for assignment
735 ** functions, i.e. pass in the pointer as the first argument
736 **
737 ******************************************************************************/
738
ajDmxScophitListCopy(const AjPList scophits)739 AjPList ajDmxScophitListCopy(const AjPList scophits)
740 {
741 AjPList list = NULL;
742 AjIList iter = NULL;
743
744 AjPScophit oldscophit = NULL;
745 AjPScophit newscophit = NULL;
746
747 /* Check arg's */
748 if(!scophits)
749 {
750 ajWarn("Bad arg's passed to ajDmxScophitListCopy\n");
751 return NULL;
752 }
753
754 /* Allocate the new list */
755 list = ajListNew();
756
757 /* Initialise the iterator */
758 iter = ajListIterNewread(scophits);
759
760 /* Iterate through the list of Scophit objects */
761 while((oldscophit = (AjPScophit)ajListIterGet(iter)))
762 {
763 newscophit = ajDmxScophitNew();
764
765 ajDmxScophitCopy(&newscophit, oldscophit);
766
767 /* Push scophit onto list */
768 ajListPushAppend(list, newscophit);
769 }
770
771 ajListIterDel(&iter);
772
773 return list;
774 }
775
776
777
778
779 /* @func ajDmxScophitCopy *****************************************************
780 **
781 ** Copies the contents from one AJAX SCOP Hit object to another.
782 **
783 ** @param [w] Pto [AjPScophit*] AJAX SCOP Hit address
784 ** @param [r] from [const AjPScophit] AJAX SCOP Hit
785 **
786 ** @return [AjBool] True if copy was successful.
787 **
788 ** @release 2.9.0
789 ** @@
790 ******************************************************************************/
791
ajDmxScophitCopy(AjPScophit * Pto,const AjPScophit from)792 AjBool ajDmxScophitCopy(AjPScophit *Pto, const AjPScophit from)
793 {
794 if(!Pto || !*Pto)
795 return ajFalse;
796
797 if(!from)
798 return ajFalse;
799
800 (*Pto)->Type = from->Type;
801 ajStrAssignS(&(*Pto)->Class, from->Class);
802 ajStrAssignS(&(*Pto)->Architecture, from->Architecture);
803 ajStrAssignS(&(*Pto)->Topology, from->Topology);
804 ajStrAssignS(&(*Pto)->Fold, from->Fold);
805 ajStrAssignS(&(*Pto)->Superfamily, from->Superfamily);
806 ajStrAssignS(&(*Pto)->Family, from->Family);
807 ajStrAssignS(&(*Pto)->Seq, from->Seq);
808 ajStrAssignS(&(*Pto)->Acc, from->Acc);
809 ajStrAssignS(&(*Pto)->Spr, from->Spr);
810 ajStrAssignS(&(*Pto)->Dom, from->Dom);
811 ajStrAssignS(&(*Pto)->Typeobj, from->Typeobj);
812 ajStrAssignS(&(*Pto)->Typesbj, from->Typesbj);
813 ajStrAssignS(&(*Pto)->Model, from->Model);
814 ajStrAssignS(&(*Pto)->Alg, from->Alg);
815 ajStrAssignS(&(*Pto)->Group, from->Group);
816 (*Pto)->Start = from->Start;
817 (*Pto)->End = from->End;
818 (*Pto)->Rank = from->Rank;
819 (*Pto)->Score = from->Score;
820 (*Pto)->Eval = from->Eval;
821 (*Pto)->Pval = from->Pval;
822 (*Pto)->Target = from->Target;
823 (*Pto)->Target2 = from->Target2;
824 (*Pto)->Priority = from->Priority;
825 (*Pto)->Sunid_Family = from->Sunid_Family;
826
827 return ajTrue;
828 }
829
830
831
832
833 /* @section Modifiers *********************************************************
834 **
835 ** These functions use the contents of an instance and update them.
836 **
837 ******************************************************************************/
838
839
840
841
842 /* @func ajDmxScophitTargetLowPriority ****************************************
843 **
844 ** Sets the Target element of an AJAX SCOP Hit object to ajTrue if its
845 ** Priority is low.
846 **
847 ** @param [u] Pscophit [AjPScophit*] AJAX SCOP Hit address
848 **
849 ** @return [AjBool] True on success. False otherwise.
850 **
851 ** @release 2.9.0
852 ** @@
853 ******************************************************************************/
854
ajDmxScophitTargetLowPriority(AjPScophit * Pscophit)855 AjBool ajDmxScophitTargetLowPriority(AjPScophit *Pscophit)
856 {
857 if(!Pscophit || !*Pscophit)
858 {
859 ajWarn("Bad arg's passed to ajDmxScophitTargetLowPriority\n");
860 return ajFalse;
861 }
862
863 if((*Pscophit)->Priority == ajFalse)
864 (*Pscophit)->Target = ajTrue;
865
866 return ajTrue;
867 }
868
869
870
871
872 /* @func ajDmxScophitTarget2 **************************************************
873 **
874 ** Sets the Target2 element of an AJAX SCOP Hit object to ajTrue.
875 **
876 ** @param [u] Pscophit [AjPScophit*] AJAX SCOP Hit address
877 **
878 ** @return [AjBool] True on success. False otherwise.
879 **
880 ** @release 2.9.0
881 ** @@
882 ******************************************************************************/
883
ajDmxScophitTarget2(AjPScophit * Pscophit)884 AjBool ajDmxScophitTarget2(AjPScophit *Pscophit)
885 {
886 if(!Pscophit || !*Pscophit)
887 {
888 ajWarn("Bad arg's passed to ajDmxScophitTarget2\n");
889 return ajFalse;
890 }
891
892 (*Pscophit)->Target2 = ajTrue;
893
894 return ajTrue;
895 }
896
897
898
899
900 /* @func ajDmxScophitTarget ***************************************************
901 **
902 ** Sets the Target element of an AJAX SCOP Hit object to ajTrue.
903 **
904 ** @param [u] Pscophit [AjPScophit*] AJAX SCOP Hit address
905 **
906 ** @return [AjBool] True on success. False otherwise.
907 **
908 ** @release 2.9.0
909 ** @@
910 ******************************************************************************/
911
ajDmxScophitTarget(AjPScophit * Pscophit)912 AjBool ajDmxScophitTarget(AjPScophit *Pscophit)
913 {
914 if(!Pscophit || !*Pscophit)
915 {
916 ajWarn("Bad arg's passed to ajDmxScophitTarget\n");
917 return ajFalse;
918 }
919
920 (*Pscophit)->Target = ajTrue;
921
922 return ajTrue;
923 }
924
925
926
927
928 /* @section Operators *********************************************************
929 **
930 ** These functions use the contents of an instance but do not make any
931 ** changes.
932 **
933 ******************************************************************************/
934
935
936
937
938 /* @func ajDmxScophitCheckTarget **********************************************
939 **
940 ** Checks to see if the Target element of an AJAX SCOP Hit object equals
941 ** ajTrue.
942 **
943 ** @param [r] scophit [const AjPScophit] AJAX SCOP Hit
944 **
945 ** @return [AjBool] Returns ajTrue if the Target element of the AAX SCOP Hit
946 ** object equals ajTrue, returns ajFalse otherwise.
947 **
948 ** @release 2.9.0
949 ** @@
950 ******************************************************************************/
951
ajDmxScophitCheckTarget(const AjPScophit scophit)952 AjBool ajDmxScophitCheckTarget(const AjPScophit scophit)
953 {
954 return scophit->Target;
955 }
956
957
958
959
960 /* @section Casts *************************************************************
961 **
962 ** These functions examine the contents of an instance and return some
963 ** derived information. Some of them provide access to the internal
964 ** components of an instance. They are provided for programming convenience
965 ** but should be used with caution.
966 **
967 ******************************************************************************/
968
969
970
971
972 /* @section Reporters *********************************************************
973 **
974 ** These functions return the contents of an instance but do not make any
975 ** changes.
976 **
977 ******************************************************************************/
978
979
980
981
982 /* @func ajDmxScophitCompScore ************************************************
983 **
984 ** Function to compare AJAX SCOP Hit objects by score member.
985 ** Usually called by ajListSort.
986 **
987 ** @param [r] item1 [const void*] AJAX SCOP Hit address 1
988 ** @param [r] item2 [const void*] AJAX SCOP Hit address 2
989 ** @see ajListSort
990 **
991 ** @return [ajint] 1 if score1 < score2, 0 if score1 == score2, else -1.
992 **
993 ** @release 2.9.0
994 ** @@
995 ******************************************************************************/
996
ajDmxScophitCompScore(const void * item1,const void * item2)997 ajint ajDmxScophitCompScore(const void *item1, const void *item2)
998 {
999 AjPScophit scophit1 = *(AjOScophit *const *) item1;
1000 AjPScophit scophit2 = *(AjOScophit *const *) item2;
1001
1002 if(scophit1->Score < scophit2->Score)
1003 return -1;
1004 else if(E_FPEQ(scophit1->Score, scophit2->Score, U_FEPS))
1005 return 0;
1006
1007 return 1;
1008 }
1009
1010
1011
1012
1013 /* @func ajDmxScophitCompPval *************************************************
1014 **
1015 ** Function to compare AJAX SCOP Hit objects by Pval member.
1016 ** Usually called by ajListSort.
1017 **
1018 ** @param [r] item1 [const void*] AJAX SCOP Hit address 1
1019 ** @param [r] item2 [const void*] AJAX SCOP Hit address 2
1020 ** @see ajListSort
1021 **
1022 ** @return [ajint] 1 if Pval1 > Pval2, 0 if Pval1 == Pval2, else -1.
1023 **
1024 ** @release 2.9.0
1025 ** @@
1026 ******************************************************************************/
1027
ajDmxScophitCompPval(const void * item1,const void * item2)1028 ajint ajDmxScophitCompPval(const void *item1, const void *item2)
1029 {
1030 AjPScophit scophit1 = *(AjOScophit *const *) item1;
1031 AjPScophit scophit2 = *(AjOScophit *const *) item2;
1032
1033 if(scophit1->Pval < scophit2->Pval)
1034 return -1;
1035 else if(E_FPEQ(scophit1->Pval, scophit2->Pval, U_FEPS))
1036 return 0;
1037
1038 return 1;
1039 }
1040
1041
1042
1043
1044 /* @func ajDmxScophitCompAcc **************************************************
1045 **
1046 ** Function to compare AJAX SCOP Hit objects by Acc member.
1047 ** Usually called by ajListSort.
1048 **
1049 ** @param [r] item1 [const void*] AJAX SCOP Hit address 1
1050 ** @param [r] item2 [const void*] AJAX SCOP Hit address 2
1051 ** @see ajListSort
1052 **
1053 ** @return [ajint] -1 if Acc1 should sort before Acc2,
1054 ** +1 if the Acc2 should sort first.
1055 ** 0 if they are identical in length and content.
1056 **
1057 ** @release 2.9.0
1058 ** @@
1059 ******************************************************************************/
1060
ajDmxScophitCompAcc(const void * item1,const void * item2)1061 ajint ajDmxScophitCompAcc(const void *item1, const void *item2)
1062 {
1063 AjPScophit scophit1 = *(AjOScophit *const *) item1;
1064 AjPScophit scophit2 = *(AjOScophit *const *) item2;
1065
1066 dmxTraceScophit(scophit1, "CompAcc scophit1");
1067 dmxTraceScophit(scophit2, "CompAcc scophit2");
1068
1069 return ajStrCmpS(scophit1->Acc, scophit2->Acc);
1070 }
1071
1072
1073
1074
1075 /* @func ajDmxScophitCompSunid ************************************************
1076 **
1077 ** Function to compare AJAX SCOP Hit objects by Sunid_Family member.
1078 ** Usually called by ajListSort.
1079 **
1080 ** @param [r] item1 [const void*] AJAX SCOP Hit address 1
1081 ** @param [r] item2 [const void*] AJAX SCOP Hit address 2
1082 ** @see ajListSort
1083 **
1084 ** @return [ajint] -1 if Sunid_Family1 < Sunid_Family2, +1 if the
1085 ** Sunid_Family2 should sort first. 0 if they are identical.
1086 **
1087 ** @release 2.9.0
1088 ** @@
1089 ******************************************************************************/
1090
ajDmxScophitCompSunid(const void * item1,const void * item2)1091 ajint ajDmxScophitCompSunid(const void *item1, const void *item2)
1092 {
1093 AjPScophit scophit1 = *(AjOScophit *const *) item1;
1094 AjPScophit scophit2 = *(AjOScophit *const *) item2;
1095
1096 if(scophit1->Sunid_Family < scophit2->Sunid_Family)
1097 return -1;
1098 else if(scophit1->Sunid_Family == scophit2->Sunid_Family)
1099 return 0;
1100
1101 return 1;
1102 }
1103
1104
1105
1106
1107 /* @func ajDmxScophitCompSpr **************************************************
1108 **
1109 ** Function to compare AJAX SCOP Hit objects by Spr member.
1110 ** Usually called by ajListSort.
1111 **
1112 ** @param [r] item1 [const void*] AJAX SCOP Hit address 1
1113 ** @param [r] item2 [const void*] AJAX SCOP Hit address 2
1114 ** @see ajListSort
1115 **
1116 ** @return [ajint] -1 if Spr1 should sort before Spr2,
1117 ** +1 if the Spr2 should sort first.
1118 ** 0 if they are identical in length and content.
1119 **
1120 ** @release 2.9.0
1121 ** @@
1122 ******************************************************************************/
1123
ajDmxScophitCompSpr(const void * item1,const void * item2)1124 ajint ajDmxScophitCompSpr(const void *item1, const void *item2)
1125 {
1126 AjPScophit scophit1 = *(AjOScophit *const *) item1;
1127 AjPScophit scophit2 = *(AjOScophit *const *) item2;
1128
1129 return ajStrCmpS(scophit1->Spr, scophit2->Spr);
1130 }
1131
1132
1133
1134
1135 /* @func ajDmxScophitCompEnd **************************************************
1136 **
1137 ** Function to compare AJAX SCOP Hit objects by End member.
1138 ** Usually called by ajListSort.
1139 **
1140 ** @param [r] item1 [const void*] AJAX SCOP Hit address 1
1141 ** @param [r] item2 [const void*] AJAX SCOP Hit address 2
1142 ** @see ajListSort
1143 **
1144 ** @return [ajint] -1 if End1 should sort before End2, +1 if the End2
1145 ** should sort first. 0 if they are identical.
1146 **
1147 ** @release 2.9.0
1148 ** @@
1149 ******************************************************************************/
1150
ajDmxScophitCompEnd(const void * item1,const void * item2)1151 ajint ajDmxScophitCompEnd(const void *item1, const void *item2)
1152 {
1153 AjPScophit scophit1 = *(AjOScophit *const *) item1;
1154 AjPScophit scophit2 = *(AjOScophit *const *) item2;
1155
1156 dmxTraceScophit(scophit1, "CompEnd scophit1");
1157 dmxTraceScophit(scophit2, "CompEnd scophit2");
1158
1159 if(scophit1->End < scophit2->End)
1160 return -1;
1161 else if(scophit1->End == scophit2->End)
1162 return 0;
1163
1164 return 1;
1165 }
1166
1167
1168
1169
1170 /* @func ajDmxScophitCompStart ************************************************
1171 **
1172 ** Function to compare AJAX SCOP Hit objects by Start member.
1173 ** Usually called by ajListSort.
1174 **
1175 ** @param [r] item1 [const void*] AJAX SCOP Hit address 1
1176 ** @param [r] item2 [const void*] AJAX SCOP Hit address 2
1177 ** @see ajListSort
1178 **
1179 ** @return [ajint] -1 if Start1 should sort before Start2, +1 if the Start2
1180 ** should sort first. 0 if they are identical.
1181 **
1182 ** @release 2.9.0
1183 ** @@
1184 ******************************************************************************/
1185
ajDmxScophitCompStart(const void * item1,const void * item2)1186 ajint ajDmxScophitCompStart(const void *item1, const void *item2)
1187 {
1188 AjPScophit scophit1 = *(AjOScophit *const *) item1;
1189 AjPScophit scophit2 = *(AjOScophit *const *) item2;
1190
1191 dmxTraceScophit(scophit1, "CompStart scophit1");
1192 dmxTraceScophit(scophit2, "CompStart scophit2");
1193
1194 if(scophit1->Start < scophit2->Start)
1195 return -1;
1196 else if(scophit1->Start == scophit2->Start)
1197 return 0;
1198
1199 return 1;
1200 }
1201
1202
1203
1204
1205 /* @func ajDmxScophitCompFam **************************************************
1206 **
1207 ** Function to compare AJAX SCOP Hit objects by Family member.
1208 ** Usually called by ajListSort.
1209 **
1210 ** @param [r] item1 [const void*] AJAX SCOP Hit address 1
1211 ** @param [r] item2 [const void*] AJAX SCOP Hit address 2
1212 ** @see ajListSort
1213 **
1214 ** @return [ajint] -1 if Family1 should sort before Family2, +1 if the
1215 ** Family2 should sort first. 0 if they are identical.
1216 **
1217 ** @release 2.9.0
1218 ** @@
1219 ******************************************************************************/
1220
ajDmxScophitCompFam(const void * item1,const void * item2)1221 ajint ajDmxScophitCompFam(const void *item1, const void *item2)
1222 {
1223 AjPScophit scophit1 = *(AjOScophit *const *) item1;
1224 AjPScophit scophit2 = *(AjOScophit *const *) item2;
1225
1226 return ajStrCmpS(scophit1->Family, scophit2->Family);
1227 }
1228
1229
1230
1231
1232 /* @func ajDmxScophitCompSfam *************************************************
1233 **
1234 ** Function to compare AJAX SCOP Hit objects by Superfamily member.
1235 ** Usually called by ajListSort.
1236 **
1237 ** @param [r] item1 [const void*] AJAX SCOP Hit address 1
1238 ** @param [r] item2 [const void*] AJAX SCOP Hit address 2
1239 ** @see ajListSort
1240 **
1241 ** @return [ajint] -1 if Superfamily1 should sort before Superfamily2, +1 if
1242 ** the Superfamily2 should sort first. 0 if they are identical.
1243 **
1244 ** @release 2.9.0
1245 ** @@
1246 ******************************************************************************/
1247
ajDmxScophitCompSfam(const void * item1,const void * item2)1248 ajint ajDmxScophitCompSfam(const void *item1, const void *item2)
1249 {
1250 AjPScophit scophit1 = *(AjOScophit *const *) item1;
1251 AjPScophit scophit2 = *(AjOScophit *const *) item2;
1252
1253 return ajStrCmpS(scophit1->Superfamily, scophit2->Superfamily);
1254 }
1255
1256
1257
1258
1259 /* @func ajDmxScophitCompClass ************************************************
1260 **
1261 ** Function to compare AJAX SCOP Hit objects by Class member.
1262 ** Usually called by ajListSort.
1263 **
1264 ** @param [r] item1 [const void*] AJAX SCOP Hit address 1
1265 ** @param [r] item2 [const void*] AJAX SCOP Hit address 2
1266 ** @see ajListSort
1267 **
1268 ** @return [ajint] -1 if Class1 should sort before Class2, +1 if the Class2
1269 ** should sort first. 0 if they are identical.
1270 **
1271 ** @release 3.0.0
1272 ** @@
1273 ******************************************************************************/
1274
ajDmxScophitCompClass(const void * item1,const void * item2)1275 ajint ajDmxScophitCompClass(const void *item1, const void *item2)
1276 {
1277 AjPScophit scophit1 = *(AjOScophit *const *) item1;
1278 AjPScophit scophit2 = *(AjOScophit *const *) item2;
1279
1280 return ajStrCmpS(scophit1->Class, scophit2->Class);
1281 }
1282
1283
1284
1285
1286 /* @func ajDmxScophitCompFold *************************************************
1287 **
1288 ** Function to compare AJAX SCOP Hit objects by Fold member.
1289 ** Usually called by ajListSort.
1290 **
1291 ** @param [r] item1 [const void*] AJAX SCOP Hit address 1
1292 ** @param [r] item2 [const void*] AJAX SCOP Hit address 2
1293 ** @see ajListSort
1294 **
1295 ** @return [ajint] -1 if Fold1 should sort before Fold2, +1 if the Fold2
1296 ** should sort first. 0 if they are identical.
1297 **
1298 ** @release 2.9.0
1299 ** @@
1300 ******************************************************************************/
1301
ajDmxScophitCompFold(const void * item1,const void * item2)1302 ajint ajDmxScophitCompFold(const void *item1, const void *item2)
1303 {
1304 AjPScophit scophit1 = *(AjOScophit *const *) item1;
1305 AjPScophit scophit2 = *(AjOScophit *const *) item2;
1306
1307 return ajStrCmpS(scophit1->Fold, scophit2->Fold);
1308 }
1309
1310
1311
1312
1313 /* ======================================================================= */
1314 /* ========================== Input & Output ============================= */
1315 /* ======================================================================= */
1316
1317
1318
1319
1320 /* @func ajDmxScopalgGetseqs **************************************************
1321 **
1322 ** Read an AJAX SCOP Alignment object and write an array of AJAX Strong objects
1323 ** containing the sequences without gaps.
1324 **
1325 ** @param [r] scopalg [const AjPScopalg] AJAX SCOP Alignment
1326 ** @param [w] array [AjPStr**] Array of AJAX String objects
1327 **
1328 ** @return [ajuint] Number of sequences read
1329 **
1330 ** @release 2.9.0
1331 ** @@
1332 ******************************************************************************/
1333
ajDmxScopalgGetseqs(const AjPScopalg scopalg,AjPStr ** array)1334 ajuint ajDmxScopalgGetseqs(const AjPScopalg scopalg, AjPStr **array)
1335 {
1336 ajuint i = 0U;
1337
1338 if(!scopalg || !array)
1339 {
1340 ajWarn("Null args passed to ajDmxScopalgGetseqs");
1341 return 0;
1342 }
1343
1344 *array = (AjPStr *) AJCALLOC0(scopalg->Number, sizeof (AjPStr));
1345
1346 for(i = 0U; i < scopalg->Number; ++i)
1347 {
1348 (*array)[i] = ajStrNew();
1349
1350 ajStrAssignS(&((*array)[i]), scopalg->Seqs[i]);
1351
1352 ajStrRemoveGap(&((*array)[i]));
1353
1354 }
1355
1356 return scopalg->Number;
1357 }
1358
1359
1360
1361
1362 /* @func ajDmxScophitsWrite ***************************************************
1363 **
1364 ** Write contents of an AJAX List of AJAX SCOP Hit objects to an AJAX File in
1365 ** EMBL-like format.
1366 ** Text for Class, Architecture, Topology, Fold, Superfamily and Family
1367 ** is only written if the text is available.
1368 **
1369 ** @param [w] outf [AjPFile] Output file stream
1370 ** @param [r] scophits [const AjPList] AJAX List of AJAX SCOP Hit objects
1371 **
1372 ** @return [AjBool] True on success
1373 **
1374 ** @release 2.9.0
1375 ** @@
1376 ******************************************************************************/
1377
ajDmxScophitsWrite(AjPFile outf,const AjPList scophits)1378 AjBool ajDmxScophitsWrite(AjPFile outf, const AjPList scophits)
1379 {
1380 AjIList iter = NULL;
1381
1382 AjPScophit scophit = NULL;
1383
1384 AjPSeqout outseq = NULL;
1385
1386 iter = ajListIterNewread(scophits);
1387
1388 while((scophit = (AjPScophit) ajListIterGet(iter)))
1389 {
1390 if(!scophit)
1391 return ajFalse;
1392
1393 if(scophit->Type == ajEDomainTypeSCOP)
1394 ajFmtPrintF(outf, "TY SCOP\nXX\n");
1395 else if(scophit->Type == ajEDomainTypeCATH)
1396 ajFmtPrintF(outf, "TY CATH\nXX\n");
1397
1398 if(MAJSTRGETLEN(scophit->Dom))
1399 {
1400 ajFmtPrintF(outf, "%-5s%S\n", "DO", scophit->Dom);
1401 ajFmtPrintF(outf, "XX\n");
1402 }
1403
1404 if(MAJSTRGETLEN(scophit->Class))
1405 {
1406 ajFmtPrintF(outf, "CL %S\n", scophit->Class);
1407 ajFmtPrintF(outf, "XX\n");
1408 }
1409
1410 if(MAJSTRGETLEN(scophit->Architecture))
1411 {
1412 ajFmtPrintF(outf, "AR %S\n", scophit->Architecture);
1413 ajFmtPrintF(outf, "XX\n");
1414 }
1415
1416 if(MAJSTRGETLEN(scophit->Topology))
1417 {
1418 ajFmtPrintF(outf, "TP %S\n", scophit->Topology);
1419 ajFmtPrintF(outf, "XX\n");
1420 }
1421
1422 if(MAJSTRGETLEN(scophit->Fold))
1423 {
1424 ajFmtPrintSplit(outf, scophit->Fold, "FO ", 75, " \t\n\r");
1425 ajFmtPrintF(outf, "XX\n");
1426
1427 #if AJFALSE
1428 ajFmtPrintSplit(outf, scophit->Fold, "XX\nFO ", 75,
1429 " \t\n\r");
1430 ajFmtPrintF(outf, "XX\n");
1431 #endif /* AJFALSE */
1432 }
1433
1434 if(MAJSTRGETLEN(scophit->Superfamily))
1435 {
1436 ajFmtPrintSplit(outf, scophit->Superfamily, "SF ", 75,
1437 " \t\n\r");
1438 ajFmtPrintF(outf, "XX\n");
1439
1440 #if AJFALSE
1441 ajFmtPrintSplit(outf, scophit->Superfamily, "XX\nSF ", 75,
1442 " \t\n\r");
1443 ajFmtPrintF(outf, "XX\n");
1444 #endif /* AJFALSE */
1445 }
1446
1447 if(MAJSTRGETLEN(scophit->Family))
1448 {
1449 ajFmtPrintSplit(outf, scophit->Family,"FA ", 75, " \t\n\r");
1450 ajFmtPrintF(outf, "XX\n");
1451
1452 #if AJFALSE
1453 ajFmtPrintSplit(outf, scophit->Family, "XX\nFA ", 75,
1454 " \t\n\r");
1455 ajFmtPrintF(outf, "XX\n");
1456 #endif
1457 }
1458
1459 if(MAJSTRGETLEN(scophit->Family))
1460 {
1461 ajFmtPrintF(outf, "XX\nSI %d\n", scophit->Sunid_Family);
1462 ajFmtPrintF(outf, "XX\n");
1463 }
1464
1465 #if AJFALSE
1466 if(MAJSTRGETLEN(scophit->Typeobj))
1467 ajFmtPrintF(outf, "%-5s%S\n", "TY", scophit->Typeobj);
1468 #endif /* AJFALSE */
1469 ajFmtPrintF(outf, "XX\n");
1470 ajFmtPrintF(outf, "%-5s%.5f\n", "SC", scophit->Score);
1471 ajFmtPrintF(outf, "XX\n");
1472
1473 ajFmtPrintF(outf, "%-5s%.3e\n", "PV", scophit->Pval);
1474 ajFmtPrintF(outf, "XX\n");
1475
1476 ajFmtPrintF(outf, "%-5s%.3e\n", "EV", scophit->Eval);
1477 ajFmtPrintF(outf, "XX\n");
1478
1479 if(MAJSTRGETLEN(scophit->Group))
1480 {
1481 ajFmtPrintF(outf, "%-5s%S\n", "GP", scophit->Group);
1482 ajFmtPrintF(outf, "XX\n");
1483 }
1484
1485 ajFmtPrintF(outf, "%-5s%S\n", "AC", scophit->Acc);
1486 ajFmtPrintF(outf, "XX\n");
1487
1488 if(MAJSTRGETLEN(scophit->Spr))
1489 {
1490 ajFmtPrintF(outf, "%-5s%S\n", "SP", scophit->Spr);
1491 ajFmtPrintF(outf, "XX\n");
1492 }
1493
1494 ajFmtPrintF(outf, "%-5s%d START; %d END;\n", "RA",
1495 scophit->Start, scophit->End);
1496 ajFmtPrintF(outf, "XX\n");
1497 outseq = ajSeqoutNewFile(outf);
1498 ajSeqoutDumpSwisslike(outseq, scophit->Seq, "SQ");
1499 ajSeqoutDel(&outseq);
1500 ajFmtPrintF(outf, "XX\n");
1501
1502 ajFmtPrintF(outf, "//\n");
1503 }
1504
1505 ajListIterDel(&iter);
1506
1507 return ajTrue;
1508 }
1509
1510
1511
1512
1513 /* @func ajDmxScophitsWriteFasta **********************************************
1514 **
1515 ** Write contents of an AJAX List of AJAX SCOP Hit objects to an AJAX File
1516 ** in DHF format.
1517 ** Text for Class, Archhitecture, Topology, Fold, Superfamily and Family
1518 ** is only written if the text is available.
1519 **
1520 ** @param [w] outf [AjPFile] AJAX Output File stream
1521 ** @param [r] scophits [const AjPList] AJAX List of AJAX SCOP Hit objects
1522 **
1523 ** @return [AjBool] True on success
1524 **
1525 ** @release 3.0.0
1526 ** @@
1527 ******************************************************************************/
1528
ajDmxScophitsWriteFasta(AjPFile outf,const AjPList scophits)1529 AjBool ajDmxScophitsWriteFasta(AjPFile outf, const AjPList scophits)
1530 {
1531
1532 AjIList iter = NULL;
1533
1534 AjPScophit scophit = NULL;
1535
1536 iter = ajListIterNewread(scophits);
1537
1538 while((scophit = (AjPScophit) ajListIterGet(iter)))
1539 {
1540 if(!scophit)
1541 return ajFalse;
1542
1543 ajFmtPrintF(outf, "> ");
1544
1545 if(MAJSTRGETLEN(scophit->Acc))
1546 ajFmtPrintF(outf, "%S^", scophit->Acc);
1547 else
1548 ajFmtPrintF(outf, ".^");
1549
1550 if(MAJSTRGETLEN(scophit->Spr))
1551 ajFmtPrintF(outf, "%S^", scophit->Spr);
1552 else
1553 ajFmtPrintF(outf, ".^");
1554
1555 ajFmtPrintF(outf, "%d^%d^", scophit->Start, scophit->End);
1556
1557 if((scophit->Type == ajEDomainTypeSCOP))
1558 ajFmtPrintF(outf, "SCOP^");
1559 else if ((scophit->Type == ajEDomainTypeCATH))
1560 ajFmtPrintF(outf, "CATH^");
1561 else
1562 ajFmtPrintF(outf, ".^");
1563
1564 if(MAJSTRGETLEN(scophit->Dom))
1565 ajFmtPrintF(outf, "%S^", scophit->Dom);
1566 else
1567 ajFmtPrintF(outf, ".^");
1568
1569 ajFmtPrintF(outf,"%d^", scophit->Sunid_Family);
1570
1571 if(MAJSTRGETLEN(scophit->Class))
1572 ajFmtPrintF(outf,"%S^",scophit->Class);
1573 else
1574 ajFmtPrintF(outf, ".^");
1575
1576 if(MAJSTRGETLEN(scophit->Architecture))
1577 ajFmtPrintF(outf,"%S^",scophit->Architecture);
1578 else
1579 ajFmtPrintF(outf, ".^");
1580
1581 if(MAJSTRGETLEN(scophit->Topology))
1582 ajFmtPrintF(outf,"%S^",scophit->Topology);
1583 else
1584 ajFmtPrintF(outf, ".^");
1585
1586 if(MAJSTRGETLEN(scophit->Fold))
1587 ajFmtPrintF(outf,"%S^",scophit->Fold);
1588 else
1589 ajFmtPrintF(outf, ".^");
1590
1591 if(MAJSTRGETLEN(scophit->Superfamily))
1592 ajFmtPrintF(outf,"%S^",scophit->Superfamily);
1593 else
1594 ajFmtPrintF(outf, ".^");
1595
1596 if(MAJSTRGETLEN(scophit->Family))
1597 ajFmtPrintF(outf,"%S^",scophit->Family);
1598 else
1599 ajFmtPrintF(outf, ".^");
1600
1601 if(MAJSTRGETLEN(scophit->Model))
1602 ajFmtPrintF(outf, "%S^", scophit->Model);
1603 else
1604 ajFmtPrintF(outf, ".^");
1605
1606 ajFmtPrintF(outf, "%.2f^", scophit->Score);
1607
1608 ajFmtPrintF(outf, "%.3e^", scophit->Pval);
1609
1610 ajFmtPrintF(outf, "%.3e", scophit->Eval);
1611
1612 ajFmtPrintF(outf, "\n");
1613 ajFmtPrintF(outf, "%S\n", scophit->Seq);
1614
1615 }
1616
1617 ajListIterDel(&iter);
1618
1619 return ajTrue;
1620 }
1621
1622
1623
1624
1625 /* @func ajDmxScophitReadFasta ************************************************
1626 **
1627 ** Read an AJAX SCOP Hit object from a file in extended FASTA format
1628 ** (see documentation for the DOMAINATRIX "seqsearch" application).
1629 **
1630 ** @param [u] inf [AjPFile] AJAX Input file stream
1631 **
1632 ** @return [AjPScophit] AJAX SCOP Hit object, or NULL if the file was not in
1633 ** extended FASTA (DHF) format (indicated by a token count of the the lines
1634 ** beginning with '>').
1635 **
1636 ** @release 3.0.0
1637 ** @@
1638 ******************************************************************************/
1639
ajDmxScophitReadFasta(AjPFile inf)1640 AjPScophit ajDmxScophitReadFasta(AjPFile inf)
1641 {
1642 AjPScophit scophit = NULL; /* Current hit */
1643 AjBool donefirst = ajFalse; /* First '>' line has been read */
1644 ajint ntok = 0; /* No. tokens in a line */
1645 const AjPStr token = NULL;
1646 AjPStr line = NULL; /* Line of text */
1647 AjPStr subline = NULL;
1648 AjPStr type = NULL;
1649
1650 /* Allocate strings */
1651 line = ajStrNew();
1652 subline = ajStrNew();
1653 type = ajStrNew();
1654
1655 while((ajReadlineTrim(inf, &line)))
1656 {
1657 if(ajStrPrefixC(line, ">"))
1658 {
1659 /* Process the last hit */
1660 if(donefirst)
1661 {
1662 ajStrRemoveWhite(&scophit->Seq);
1663 ajStrDel(&line);
1664 ajStrDel(&subline);
1665 ajStrDel(&type);
1666
1667 return scophit;
1668 }
1669 else
1670 scophit = ajDmxScophitNew();
1671
1672 /* Check line has correct no. of tokens and allocate Hit */
1673 ajStrAssignSubS(&subline, line, 1, -1);
1674
1675 if( (ntok=ajStrParseCountC(subline, "^")) != 17)
1676 {
1677 ajWarn("Wrong no. (%d) of tokens for a DHF file on line %S\n",
1678 ntok, line);
1679 ajStrDel(&line);
1680 ajStrDel(&subline);
1681 ajDmxScophitDel(&scophit);
1682 ajStrDel(&type);
1683 return NULL;
1684 }
1685
1686 /* Acc */
1687 token = ajStrParseC(subline, "^");
1688 ajStrAssignS(&scophit->Acc, token);
1689 ajStrTrimWhite(&scophit->Acc);
1690
1691 if(ajStrMatchC(scophit->Acc, "."))
1692 ajStrSetClear(&scophit->Acc);
1693
1694 /* Spr */
1695 token = ajStrParseC(NULL, "^");
1696 ajStrAssignS(&scophit->Spr, token);
1697
1698 if(ajStrMatchC(scophit->Spr, "."))
1699 ajStrSetClear(&scophit->Spr);
1700
1701 /* Start */
1702 token = ajStrParseC(NULL, "^");
1703 ajFmtScanS(token, "%d", &scophit->Start);
1704
1705 /* End */
1706 token = ajStrParseC(NULL, "^");
1707 ajFmtScanS(token, "%d", &scophit->End);
1708
1709 /* Type */
1710 token = ajStrParseC(NULL, "^");
1711 ajStrAssignS(&type, token);
1712
1713 if(ajStrMatchC(type, "SCOP"))
1714 scophit->Type = ajEDomainTypeSCOP;
1715 else if(ajStrMatchC(type, "CATH"))
1716 scophit->Type = ajEDomainTypeCATH;
1717
1718 /* Dom */
1719 token = ajStrParseC(NULL, "^");
1720 ajStrAssignS(&scophit->Dom, token);
1721
1722 if(ajStrMatchC(scophit->Dom, "."))
1723 ajStrSetClear(&scophit->Dom);
1724
1725 /* Domain identifier */
1726 token = ajStrParseC(NULL, "^");
1727 ajFmtScanS(token, "%d", &scophit->Sunid_Family);
1728
1729 token = ajStrParseC(NULL, "^");
1730 ajStrAssignS(&scophit->Class, token);
1731
1732 if(ajStrMatchC(scophit->Class, "."))
1733 ajStrSetClear(&scophit->Class);
1734
1735 token = ajStrParseC(NULL, "^");
1736 ajStrAssignS(&scophit->Architecture, token);
1737
1738 if(ajStrMatchC(scophit->Architecture, "."))
1739 ajStrSetClear(&scophit->Architecture);
1740
1741 token = ajStrParseC(NULL, "^");
1742 ajStrAssignS(&scophit->Topology, token);
1743 if(ajStrMatchC(scophit->Topology, "."))
1744 ajStrSetClear(&scophit->Topology);
1745
1746 token = ajStrParseC(NULL, "^");
1747 ajStrAssignS(&scophit->Fold, token);
1748
1749 if(ajStrMatchC(scophit->Fold, "."))
1750 ajStrSetClear(&scophit->Fold);
1751
1752 token = ajStrParseC(NULL, "^");
1753 ajStrAssignS(&scophit->Superfamily, token);
1754
1755 if(ajStrMatchC(scophit->Superfamily, "."))
1756 ajStrSetClear(&scophit->Superfamily);
1757
1758 token = ajStrParseC(NULL, "^");
1759 ajStrAssignS(&scophit->Family, token);
1760
1761 if(ajStrMatchC(scophit->Family, "."))
1762 ajStrSetClear(&scophit->Family);
1763
1764 token = ajStrParseC(NULL, "^");
1765 ajStrAssignS(&scophit->Model, token);
1766
1767 if(ajStrMatchC(scophit->Model, "."))
1768 ajStrSetClear(&scophit->Model);
1769
1770 token = ajStrParseC(NULL, "^");
1771 ajFmtScanS(token, "%f", &scophit->Score);
1772
1773 token = ajStrParseC(NULL, "^");
1774 ajFmtScanS(token, "%f", &scophit->Pval);
1775
1776 token = ajStrParseC(NULL, "^");
1777 ajFmtScanS(token, "%f", &scophit->Eval);
1778
1779 donefirst = ajTrue;
1780 }
1781 else
1782 {
1783 if(scophit)
1784 ajStrAppendS(&scophit->Seq, line);
1785 }
1786 }
1787
1788 /* EOF therefore process last hit */
1789 if(donefirst)
1790 {
1791 ajStrRemoveWhite(&scophit->Seq);
1792 ajStrDel(&line);
1793 ajStrDel(&subline);
1794 ajStrDel(&type);
1795 return scophit;
1796 }
1797
1798 ajStrDel(&line);
1799 ajStrDel(&subline);
1800 ajStrDel(&type);
1801 ajDmxScophitDel(&scophit);
1802
1803 return NULL;
1804 }
1805
1806
1807
1808
1809 /* @func ajDmxScopalgWrite ****************************************************
1810 **
1811 ** Write an AJAX SCOP Alignment object to an AJAX FIle in EMBOSS simple
1812 ** multiple sequence format (same as that used by clustal) annotated with
1813 ** domain classification as below (records are for SCOP domains in this
1814 ** example):
1815 **
1816 **
1817 ** # TY SCOP
1818 ** # XX
1819 ** # CL Alpha and beta proteins (a+b)
1820 ** # XX
1821 ** # FO Phospholipase D/nuclease
1822 ** # XX
1823 ** # SF Phospholipase D/nuclease
1824 ** # XX
1825 ** # FA Phospholipase D
1826 ** # XX
1827 ** # SI 64391
1828 ** # XX
1829 ** d1f0ia1 1 AATPHLDAVEQTLRQVSPGLEGDVWERTSGNKLDGSAADPSDWLLQTP-GCWGDDKC 50
1830 ** d1f0ia2 1 -----------------------------NVPV---------IAVG-GLG---VGIK 15
1831 **
1832 ** d1f0ia1 51 A-------------------------------D-RVGTKRLLAKMTENIGNATRTVD 75
1833 ** d1f0ia2 16 DVDPKSTFRPDLPTASDTKCVVGLHDNTNADRDYDTV-NPEESALRALVASAKGHIE 65
1834 **
1835 **
1836 **
1837 ** @param [r] scopalg [const AjPScopalg] AJAX SCOP Alignment
1838 ** @param [u] outf [AjPFile] AJAX Output file stream
1839 **
1840 ** @return [AjBool] True on success (an alignment was written)
1841 **
1842 ** @release 2.9.0
1843 ** @@
1844 ******************************************************************************/
1845
ajDmxScopalgWrite(const AjPScopalg scopalg,AjPFile outf)1846 AjBool ajDmxScopalgWrite(const AjPScopalg scopalg, AjPFile outf)
1847 {
1848 ajuint i = 0U;
1849 ajuint j = 0U;
1850
1851 ajint tmp_wid = 0; /* Temp. variable for width */
1852 ajint code_wid = 0; /* Max. code width +1 */
1853 ajint seq_wid = 0; /* Width of alignment rounded up to nearest 60 */
1854 ajuint nblk = 0U; /* Number of blocks of alignment in output */
1855
1856 AjPStr tmp_seq = NULL; /* Temp. variable for sequence */
1857 AjPStr nogap = NULL; /* Temp. variable for sequence w/o gaps */
1858
1859 ajint len_nogap = 0; /* Length of no_gap */
1860 ajint pos = 0; /* House-keeping */
1861
1862 ajint start = 0; /* Start position of sequence fragment wrt full
1863 length alignment */
1864 ajuint end = 0; /* End position of sequence fragment wrt full
1865 length alignment */
1866 AjPInt idx = NULL; /* Index */
1867
1868 idx = ajIntNewRes(scopalg->Number);
1869
1870 for(i = 0U; i < scopalg->Number; i++)
1871 ajIntPut(&idx, scopalg->Number, 1);
1872
1873 /* Write SCOP classification records to file */
1874 if(scopalg->Type == ajEDomainTypeSCOP)
1875 {
1876 ajFmtPrintF(outf,"# TY SCOP\n# XX\n");
1877 ajFmtPrintF(outf,"# CL %S\n# XX\n", scopalg->Class);
1878
1879 ajFmtPrintSplit(outf, scopalg->Fold, "# FO ", 75, " \t\n\r");
1880 ajFmtPrintF(outf, "# XX\n");
1881 ajFmtPrintSplit(outf, scopalg->Superfamily, "# SF ", 75, " \t\n\r");
1882 ajFmtPrintF(outf, "# XX\n");
1883 ajFmtPrintSplit(outf,scopalg->Family, "# FA ", 75, " \t\n\r");
1884 ajFmtPrintF(outf, "# XX\n");
1885
1886 #if AJFALSE
1887 ajFmtPrintSplit(outf,scopalg->Fold, "\nXX\n# FO ", 75,
1888 " \t\n\r");
1889 ajFmtPrintSplit(outf,scopalg->Superfamily, "# XX\n# SF ", 75,
1890 " \t\n\r");
1891 ajFmtPrintSplit(outf,scopalg->Family, "# XX\n# FA ", 75,
1892 " \t\n\r");
1893 ajFmtPrintF(outf,"# XX\n");
1894 #endif /* AJFALSE */
1895
1896 ajFmtPrintF(outf, "# SI %d\n# XX", scopalg->Sunid_Family);
1897 }
1898 else
1899 {
1900 ajFmtPrintF(outf, "# TY CATH\n# XX\n");
1901 ajFmtPrintF(outf, "# CL %S\n# XX\n", scopalg->Class);
1902
1903 ajFmtPrintSplit(outf, scopalg->Architecture, "# AR ", 75, " \t\n\r");
1904 ajFmtPrintF(outf, "# XX\n");
1905 ajFmtPrintSplit(outf, scopalg->Topology, "# TP ", 75, " \t\n\r");
1906 ajFmtPrintF(outf, "# XX\n");
1907 ajFmtPrintSplit(outf, scopalg->Superfamily, "# SF ", 75, " \t\n\r");
1908 ajFmtPrintF(outf, "# XX\n");
1909
1910 #if AJFALSE
1911 ajFmtPrintSplit(outf, scopalg->Architecture,
1912 "\nXX\n# AR ", 75, " \t\n\r");
1913 ajFmtPrintSplit(outf, scopalg->Topology, "# XX\n# TP ", 75,
1914 " \t\n\r");
1915 ajFmtPrintSplit(outf, scopalg->Superfamily, "# XX\n# SF ", 75,
1916 " \t\n\r");
1917 ajFmtPrintF(outf, "# XX\n");
1918 #endif /* AJFALSE */
1919
1920 ajFmtPrintF(outf, "# SI %d\n# XX", scopalg->Sunid_Family);
1921 }
1922
1923 /* Find max. width of code, and add 1 to it for 1 whitespace */
1924 for(i = 0U; i < scopalg->Number; i++)
1925 if((tmp_wid = MAJSTRGETLEN(scopalg->Codes[i])) > code_wid)
1926 code_wid = tmp_wid;
1927 code_wid++;
1928
1929 /* Calculate no. of blocks in alignment */
1930 seq_wid = ajRound(scopalg->Width, 50);
1931 nblk = (ajint) (seq_wid / 50);
1932
1933
1934 /* Print out sequence in blocks */
1935 for(i = 0U; i < nblk; i++)
1936 {
1937 start = i * 50;
1938 end = start + 49;
1939
1940 if(end>=scopalg->Width)
1941 end = scopalg->Width - 1;
1942
1943 ajFmtPrintF(outf, "\n");
1944 for(j = 0U; j < scopalg->Number; j++)
1945 {
1946 ajStrAssignSubS(&tmp_seq, scopalg->Seqs[j], start, end);
1947 ajStrAssignS(&nogap, tmp_seq);
1948 /* Remove gap characters */
1949 ajStrRemoveSetC(&nogap, " -");
1950 len_nogap = MAJSTRGETLEN(nogap);
1951
1952 pos = ajIntGet(idx, j);
1953
1954 ajFmtPrintF(outf, "%*S%7d %-50S%7d\n",
1955 code_wid,
1956 pos,
1957 scopalg->Codes[j],
1958 tmp_seq,
1959 pos + len_nogap - 1);
1960
1961 ajIntPut(&idx, j, pos + len_nogap);
1962 }
1963 }
1964
1965 ajIntDel(&idx);
1966
1967 return ajTrue;
1968 }
1969
1970
1971
1972
1973 /* @func ajDmxScopalgWriteClustal *********************************************
1974 **
1975 ** Write an AJAX SCOP Alignment object to an AJAX File in CLUSTAL format
1976 ** (just the alignment without the domain classification information).
1977 **
1978 ** @param [r] scopalg [const AjPScopalg] AJAX SCOP Alignment
1979 ** @param [u] outf [AjPFile] AJAX Outfile file
1980 **
1981 ** @return [AjBool] True on success (a file has been written)
1982 **
1983 ** @release 2.9.0
1984 ** @@
1985 ******************************************************************************/
1986
ajDmxScopalgWriteClustal(const AjPScopalg scopalg,AjPFile outf)1987 AjBool ajDmxScopalgWriteClustal(const AjPScopalg scopalg, AjPFile outf)
1988 {
1989 ajuint i = 0U;
1990
1991 if(!scopalg)
1992 {
1993 ajWarn("Null args passed to ajDmxScopalgWriteClustal");
1994 return ajFalse;
1995 }
1996
1997 /* remove i from the print statement before committing */
1998 ajFmtPrintF(outf, "CLUSTALW\n\n");
1999 ajFmtPrintF(outf, "\n");
2000
2001 for(i = 0U; i < scopalg->Number; ++i)
2002 ajFmtPrintF(outf, "%S_%d %S\n", scopalg->Codes[i], i,
2003 scopalg->Seqs[i]);
2004
2005 ajFmtPrintF(outf, "\n");
2006 ajFmtPrintF(outf, "\n");
2007
2008 return ajTrue;
2009 }
2010
2011
2012
2013
2014 /* @func ajDmxScopalgWriteClustal2 ********************************************
2015 **
2016 ** Write an AJAX SCOP Alignment object to an AJAX File in CLUSTAL format
2017 ** (just the alignment without the domain classification information).
2018 **
2019 ** @param [r] scopalg [const AjPScopalg] AJAX SCOP Alignment
2020 ** @param [u] outf [AjPFile] AJAX Outfile file
2021 **
2022 ** @return [AjBool] True on success (a file has been written)
2023 **
2024 ** @release 2.9.0
2025 ** @@
2026 ******************************************************************************/
2027
ajDmxScopalgWriteClustal2(const AjPScopalg scopalg,AjPFile outf)2028 AjBool ajDmxScopalgWriteClustal2(const AjPScopalg scopalg, AjPFile outf)
2029 {
2030 ajuint i = 0U;
2031
2032 if(!scopalg)
2033 {
2034 ajWarn("Null args passed to ajDmxScopalgWriteClustal2");
2035 return ajFalse;
2036 }
2037
2038 /* remove i from the print statement before committing */
2039 ajFmtPrintF(outf, "\n");
2040
2041 for(i = 0; i < scopalg->Number; i++)
2042 ajFmtPrintF(outf, "%S_%d %S\n", scopalg->Codes[i], i,
2043 scopalg->Seqs[i]);
2044
2045 ajFmtPrintF(outf,"\n");
2046
2047 return ajTrue;
2048 }
2049
2050
2051
2052
2053
2054 /* @func ajDmxScopalgWriteFasta ***********************************************
2055 **
2056 ** Write an AJAX SCOP Alignment object to an AJAX File in FASTA format
2057 ** (just the alignment without the domain classification information).
2058 **
2059 ** @param [r] scopalg [const AjPScopalg] AJAX SCOP Alignment
2060 ** @param [u] outf [AjPFile] AJAX Outfile file
2061 **
2062 ** @return [AjBool] True on success (a file has been written)
2063 **
2064 ** @release 2.9.0
2065 ** @@
2066 ******************************************************************************/
2067
ajDmxScopalgWriteFasta(const AjPScopalg scopalg,AjPFile outf)2068 AjBool ajDmxScopalgWriteFasta(const AjPScopalg scopalg, AjPFile outf)
2069 {
2070 ajuint i = 0U;
2071
2072 if(!scopalg)
2073 {
2074 ajWarn("Null args passed to ajDmxScopalgWriteFasta");
2075 return ajFalse;
2076 }
2077
2078 #if AJFALSE
2079 /* remove i from the print statement before committing */
2080 ajFmtPrintF(outf, "CLUSTALW\n\n");
2081 ajFmtPrintF(outf, "\n");
2082 #endif /* AJFALSE */
2083
2084 for(i = 0U; i < scopalg->Number; i++)
2085 ajFmtPrintF(outf, ">%S_%d\n%S\n", scopalg->Codes[i], i,
2086 scopalg->Seqs[i]);
2087
2088 ajFmtPrintF(outf,"\n");
2089 ajFmtPrintF(outf,"\n");
2090
2091 return ajTrue;
2092 }
2093
2094
2095
2096
2097 /* @section Miscellaneous *****************************************************
2098 **
2099 ** These functions may have diverse functions that do not fit into the other
2100 ** categories.
2101 **
2102 ******************************************************************************/
2103
2104
2105
2106
2107 /* @func ajDmxScopSeqFromSunid ************************************************
2108 **
2109 ** Write a sequence corresponding to an AJAX SCOP domain given a Sunid for the
2110 ** domain. The sequence is taken from one of an AJAX List of AJAX SCOP objects
2111 ** that is provided. The SWISS-Prot sequence is taken in priority over the PDB
2112 ** sequence.
2113 **
2114 ** @param [r] identifier [ajint] Search term
2115 ** @param [w] seq [AjPStr*] Result sequence
2116 ** @param [r] scops [const AjPList] Sorted AJAX List of AJAX SCOP objects
2117 **
2118 ** @return [AjBool] True if a SWISS-Prot identifier code was found for the
2119 ** PDB code.
2120 **
2121 ** @release 2.9.0
2122 ** @@
2123 ******************************************************************************/
2124
ajDmxScopSeqFromSunid(ajint identifier,AjPStr * seq,const AjPList scops)2125 AjBool ajDmxScopSeqFromSunid(ajint identifier, AjPStr *seq,
2126 const AjPList scops)
2127 {
2128 ajuint dim = 0U; /* Size of array */
2129 ajint idx = 0; /* Index into array for the Pdb code */
2130
2131 AjPScop *array = NULL; /* Array derived from list */
2132
2133 if(!identifier || !scops)
2134 {
2135 ajWarn("Bad args passed to ajDmxScopSeqFromSunid");
2136 return ajFalse;
2137 }
2138
2139 dim = (ajuint) ajListToarray(scops, (void ***) &array);
2140
2141 if(!dim)
2142 {
2143 ajWarn("Empty list passed to ajDmxScopSeqFromSunid");
2144 return ajFalse;
2145 }
2146
2147 if((idx = ajScopArrFindSunid(array, dim, identifier)) == -1)
2148 {
2149 AJFREE(array);
2150 return ajFalse;
2151 }
2152
2153 /* swissprot sequence has priority */
2154 if((ajStrGetLen(array[idx]->SeqSpr)) == 0)
2155 ajStrAssignS(seq, array[idx]->SeqPdb);
2156 else
2157 ajStrAssignS(seq, array[idx]->SeqSpr);
2158
2159 AJFREE(array);
2160
2161 return ajTrue;
2162 }
2163
2164
2165
2166
2167 /* @func ajDmxExit ************************************************************
2168 **
2169 ** Cleanup of Dmx function internals.
2170 **
2171 ** @return [void]
2172 **
2173 ** @release 6.1.0
2174 ** @@
2175 ******************************************************************************/
2176
ajDmxExit(void)2177 void ajDmxExit(void)
2178 {
2179 ajStrDel(&dmxGStrline);
2180 ajStrDel(&dmxGStrtype);
2181 ajStrDel(&dmxGStrclass);
2182 ajStrDel(&dmxGStrfold);
2183 ajStrDel(&dmxGStrsuper);
2184 ajStrDel(&dmxGStrfamily);
2185 ajStrDel(&dmxGStrarch);
2186 ajStrDel(&dmxGStrtopo);
2187 ajStrDel(&dmxGStrpostsim);
2188 ajStrDel(&dmxGStrposttmp);
2189 ajStrDel(&dmxGStrposisim);
2190 ajStrDel(&dmxGStrpositmp);
2191 ajStrDel(&dmxGStrseq1);
2192 ajStrDel(&dmxGStrcodetmp);
2193
2194 return;
2195 }
2196
2197
2198
2199
2200 /* @func ajDmxDummyFunction ***************************************************
2201 **
2202 ** Dummy function to catch all unused functions defined in the ajdmx
2203 ** source file.
2204 **
2205 ** @return [void]
2206 **
2207 **
2208 ** @release 2.9.0
2209 ******************************************************************************/
2210
ajDmxDummyFunction(void)2211 void ajDmxDummyFunction(void)
2212 {
2213 return;
2214 }
2215
2216
2217
2218
2219 /* @funcstatic dmxTraceScophit ************************************************
2220 **
2221 ** Reports internals of a SCOPhit object
2222 **
2223 ** @param [r] scophit [const AjPScophit] AJAX SCOP Hit object
2224 ** @param [r] title [const char*] title
2225 ** @return [void]
2226 **
2227 ** @release 4.1.0
2228 ******************************************************************************/
2229
dmxTraceScophit(const AjPScophit scophit,const char * title)2230 static void dmxTraceScophit(const AjPScophit scophit, const char *title)
2231 {
2232 ajDebug("SCOPhit trace: %s\n", title);
2233 ajDebug("Type: %d\n", scophit->Type);
2234 ajDebug("Acc: '%S'\n", scophit->Acc);
2235 ajDebug("Start: %d\n", scophit->Start);
2236 ajDebug("End: %d\n", scophit->End);
2237
2238 return;
2239 }
2240