1 /* @source seqmatchall application
2 **
3 ** All against all comparison of a set of sequences
4 **
5 ** @author Copyright (C) Ian Longden (guess by ajb)
6 ** @@
7 **
8 ** This program is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License
10 ** as published by the Free Software Foundation; either version 2
11 ** of the License, or (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with this program; if not, write to the Free Software
20 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ******************************************************************************/
22
23 #include "emboss.h"
24
25
26
27
28 static void seqmatchall_matchListPrint(void *x,void *cl);
29 static void seqmatchall_listPrint(AjPAlign align, const AjPList list);
30
31 static AjPSeq *seqs = NULL;
32 static ajuint iseq1 = 0;
33 static ajuint iseq2 = 0;
34
35 ajuint statwordlen;
36
37
38
39
40 /* @prog seqmatchall **********************************************************
41 **
42 ** Does an all-against-all comparison of a set of sequences
43 **
44 ******************************************************************************/
45
main(int argc,char ** argv)46 int main(int argc, char **argv)
47 {
48 AjPTable seq1MatchTable = 0;
49 AjPList matchlist;
50 AjPSeqset seqset;
51 AjPAlign align = NULL;
52
53 ajuint i;
54 ajuint j;
55 ajuint nseqs;
56
57 embInit("seqmatchall", argc, argv);
58
59 seqset = ajAcdGetSeqset("sequence1");
60 statwordlen = ajAcdGetInt("wordsize");
61 align = ajAcdGetAlign("outfile");
62
63 ajAlignSetExternal(align, ajTrue);
64 embWordLength(statwordlen);
65 seqs = ajSeqsetGetSeqarray(seqset);
66 nseqs = ajSeqsetGetSize(seqset);
67
68 for(i=0;i<nseqs;i++)
69 {
70 iseq1 = i;
71 seq1MatchTable = 0;
72 if(ajSeqGetLen(seqs[iseq1]) > statwordlen)
73 {
74 if(embWordGetTable(&seq1MatchTable, seqs[i])) /* get word table */
75 {
76 for(j=i+1;j<ajSeqsetGetSize(seqset);j++)
77 {
78 iseq2 = j;
79 if(ajSeqGetLen(seqs[j]) >= statwordlen)
80 {
81 matchlist = embWordBuildMatchTable(seq1MatchTable,
82 seqs[j], ajTrue);
83 if (ajListGetLength(matchlist))
84 {
85 seqmatchall_listPrint(align, matchlist);
86 ajAlignWrite(align);
87 ajAlignReset(align);
88 }
89 /* free the match structures */
90 embWordMatchListDelete(&matchlist);
91 }
92 }
93 }
94 embWordFreeTable(&seq1MatchTable); /* free table of words */
95 }
96 }
97
98 ajAlignClose(align);
99 ajAlignDel(&align);
100 ajSeqsetDel(&seqset);
101 ajSeqDelarray(&seqs);
102
103 embExit();
104
105 return 0;
106 }
107
108
109
110
111 /* @funcstatic seqmatchall_matchListPrint *************************************
112 **
113 ** Undocumented.
114 **
115 ** @param [r] x [void*] Undocumented
116 ** @param [r] cl [void*] Undocumented
117 ** @return [void]
118 ** @@
119 ******************************************************************************/
120
seqmatchall_matchListPrint(void * x,void * cl)121 static void seqmatchall_matchListPrint(void *x,void *cl)
122 {
123 EmbPWordMatch p;
124 AjPAlign align;
125
126 p = (EmbPWordMatch)x;
127 align = (AjPAlign) cl;
128 /*
129 ajFmtPrintF(outfile, "%d %d %d %s %d %d %s\n",
130 (*p).length,
131 (*p).seq1start+1,(*p).seq1start+(*p).length,seq1->Name->Ptr,
132 (*p).seq2start+1,(*p).seq2start+(*p).length,seq2->Name->Ptr);
133 */
134
135 ajAlignDefineSS(align, seqs[iseq1], seqs[iseq2]);
136 ajAlignSetScoreI(align, p->length);
137 /* ungapped so same length for both sequences */
138 ajAlignSetSubRange(align,
139 p->seq1start, 1, p->length,
140 ajSeqIsReversed(seqs[iseq1]), ajSeqGetLen(seqs[iseq1]),
141 p->seq2start, 1, p->length,
142 ajSeqIsReversed(seqs[iseq2]), ajSeqGetLen(seqs[iseq2]));
143
144
145 return;
146 }
147
148
149
150
151 /* @funcstatic seqmatchall_listPrint ******************************************
152 **
153 ** Undocumented.
154 **
155 ** @param [u] align [AjPAlign] Alignment object
156 ** @param [r] list [const AjPList] Undocumented
157 ** @@
158 ******************************************************************************/
159
seqmatchall_listPrint(AjPAlign align,const AjPList list)160 static void seqmatchall_listPrint(AjPAlign align, const AjPList list)
161 {
162 ajListMapread(list, &seqmatchall_matchListPrint, align);
163
164 return;
165 }
166