| Bsoft 2.0.5 Bernard's software package

bseqaln.cpp
Go to the documentation of this file.
1
9 #include "rwresprop.h"
10 #include "seq_align.h"
11 #include "seq_analysis.h"
12 #include "utilities.h"
13 #include "options.h"
14 #include "timer.h"
15
16 // Declaration of global variables
17 extern int verbose; // Level of output to the screen
18
19 // Usage assistance
20 const char* use[] = {
21 " ",
22 "Usage: bseqaln [options] input.seq output.seq",
23 "---------------------------------------------",
24 "Analyzes aligned protein sequences.",
25 "All sequence numbers and position numbers start at 1.",
26 "Numbering is according to the input, including gaps.",
27 " ",
28 "Actions:",
29 "-pair Align a pair of sequences (first two in input file).",
30 "-nogaps Strip gaps from input sequences.",
31 "-consolidategaps Remove positions in alignment with only gaps.",
32 "-identity Pairwise identity.",
33 "-similarity 0.5 Pairwise similarity: threshold for counting similar residues (default 0.5).",
34 "-profile Generate a profile from an alignment.",
35 "-information Information analysis.",
36 "-hydrophobicity 0.8 Hydrophobicity analysis: representation threshold (fraction of # of seqs).",
37 " ",
38 "Parameters:",
39 "-verbose 7 Verbosity of output.",
40 "-gap 10,0.2 Gap opening and extending penalties for alignment (default 20,0.2).",
41 "-segments 1-33,36-69 Selection of sequence segments (default all).",
42 " Every pair of numbers indicate a segment to select.",
43 "-sequences 2,18 Subset of sequences to compare (default all).",
44 "-window 17 Window for moving averages (default 20).",
45 " ",
46 "Input:",
47 "-properties file.star Property file (default = internal values).",
48 "-Similarity sim.star Residue similarity matrix (default blosum62.star).",
49 " ",
50 "Output:",
51 "-Image file.img Image output filename.",
52 "-Postscript file.ps Postscript output filename.",
53 " ",
54 NULL
55 };
56
57 int main(int argc, char **argv)
58 {
59 int i, j;
60 // int n, flag;
61 // char *pnt;
62
63 // Initialize variables
64 int sub1(0), sub2(0); // Subset to compare with
65 int consolidate_gaps(0);
66 int do_pair(0);
67 int do_id(0);
68 int do_sim(0);
69 int do_profile(0);
70 int do_hp(0);
71 int do_info(0);
72 double gapopen(20), gapextend(0.2);
73 // int sel[20]; // Residue range selection
74 int window(20); // Window for moving average
75 double sim_threshold(0.5); // Similarity threshold
76 double rep_threshold(0); // Representation threshold
77 Bstring segments; // Position selector
78 Bstring atom_select("all"); // Selection
79
80 // Initialize the file names and image structure
81 Bstring imgfile;
82 Bstring psfile;
83 Bstring propfile;
84 Bstring simfile; // Use default similarity matrix file
85 Bimage* pimg = NULL;
86
87 int optind;
88 Boption* option = get_option_list(use, argc, argv, optind);
89 Boption* curropt;
90 for ( curropt = option; curropt; curropt = curropt->next ) {
91 if ( curropt->tag == "pair" )
92 do_pair = 1;
93 if ( curropt->tag == "consolidategaps" )
94 consolidate_gaps = 1;
95 if ( curropt->tag == "identity" )
96 do_id = 1;
97 if ( curropt->tag == "similarity" ) {
98 if ( ( sim_threshold = curropt->value.real() ) < 0.01 )
99 cerr << "-similarity: A threshold must be specified!" << endl;
100 else
101 do_sim = 1;
102 }
103 if ( curropt->tag == "profile" )
104 do_profile = 1;
105 if ( curropt->tag == "information" )
106 do_info = 1;
107 if ( curropt->tag == "hydrophobicity" ) {
108 if ( ( rep_threshold = curropt->value.real() ) < 0.001 )
109 cerr << "-hydrophobicity: A threshold must be specified!" << endl;
110 else
111 do_hp = 1;
112 }
113 if ( curropt->tag == "window" )
114 if ( ( window = curropt->value.integer() ) < 1 )
115 cerr << "-window: A window size must be specified!" << endl;
116 if ( curropt->tag == "gap" ) {
117 if ( ( i = curropt->values(gapopen, gapextend) ) < 1 )
118 cerr << "-gap: At least one gap penalty must be specified!" << endl;
119 else if ( i == 1 )
120 gapextend = gapopen;
121 }
122 if ( curropt->tag == "nogaps" )
123 atom_select = "NOGAP";
124 if ( curropt->tag == "segments" ) {
125 segments = curropt->value;
126 if ( segments.length() < 1 )
127 cerr << "-segments: Numbers must be specified!" << endl;
128 }
129 if ( curropt->tag == "sequences" ) {
130 if ( curropt->values(sub1, sub2) < 2 )
131 cerr << "-sequences: Two numbers must be specified!" << endl;
132 else {
133 if ( sub1 > 0 ) sub1--;
134 if ( sub2 > sub1 ) sub2--;
135 else sub2 = sub1;
136 }
137 }
138 if ( curropt->tag == "properties" )
139 propfile = curropt->filename();
140 if ( curropt->tag == "Similarity" )
141 simfile = curropt->filename();
142 if ( curropt->tag == "Image" )
143 imgfile = curropt->filename();
144 if ( curropt->tag == "Postscript" )
145 psfile = curropt->filename();
146 }
147 option_kill(option);
148
149 double ti = timer_start();
150
151 // Read the molecule file
152 Bstring filename(argv[optind++]);
153 Bmolgroup* molgroup = read_molecule(filename, atom_select, propfile);
154 if ( !molgroup ) {
155 cerr << "Error: No molecules read!" << endl;
156 bexit(-1);
157 }
158
159 molecule_update_comment(molgroup, argc, argv);
160
161 Bmolecule* mol = NULL;
162 char* profile = NULL;
163
164 // Check the moving average window size
165 if ( window < 2 ) window = 2;
166 if ( window > 1000 ) window = 1000;
167
168 // Set the tags according to the sequences selected
169 if ( sub2 > 0 ) {
170 for ( j=0; j<molgroup->maxlen; j++ )
171 molgroup->seqflag[j] = 0;
172 for ( i=0, mol = molgroup->mol; mol; i++, mol = mol->next ) {
173 if ( mol->seq.length() && i>=sub1 && i<=sub2 ) {
174 for ( j=0; j<mol->seq.length(); j++ )
175 if ( mol->seq[j] != '-' )
176 molgroup->seqflag[j] = 1;
177 }
178 }
179 }
180
181 // Get the selection
182 /* if ( segments.length() ) {
183 pnt = segments;
184 n = 0;
185 while ( pnt && sscanf(pnt, "%d", &sel[n]) ) {
186 if ( ( pnt = strchr(pnt, ',') ) ) pnt++;
187 n++;
188 }
189 if ( 2*(n/2) != n ) {
190 sel[n] = molgroup->maxlen - 1;
191 n++;
192 }
193 i = flag = 0;
194 for ( j=0; j<molgroup->maxlen; j++ ) {
195 if ( j == sel[i] + flag - 1 ) {
196 i++;
197 flag = 1 - flag;
198 }
199 molgroup->seqflag[j] *= flag;
200 }
201 }
202 */
203 if ( segments.length() )
204 select_numbers(segments, molgroup->maxlen, molgroup->seqflag);
205
206 j = 0;
207 for ( i=0; i<molgroup->maxlen; i++ )
208 j += molgroup->seqflag[i];
209
210 if ( verbose & VERB_PROCESS )
211 cout << "Alignment positions flagged: " << j << endl << endl;
212
213 Bresidue_matrix* simat = get_residue_matrix(simfile);
214
215 if ( do_pair )
216 molgroup->maxlen = seq_pair_align(molgroup->mol, molgroup->mol->next, gapopen, gapextend, simat);
217
218 if ( consolidate_gaps ) molgroup_consolidate_gaps(molgroup);
219
220 if ( do_id ) pimg = seq_aligned_identity(molgroup);
221
222 if ( do_sim ) pimg = seq_aligned_similarity(molgroup, sim_threshold, simat);
223
224 if ( do_profile ) profile = seq_aligned_profile(molgroup);
225
226 if ( do_hp ) seq_aligned_hydrophobicity(molgroup, window, rep_threshold, propfile, psfile);
227
228 if ( do_info ) seq_aligned_information(molgroup, window, psfile);
229
230 if ( optind < argc )
231 write_molecule(argv[optind], molgroup);
232
233 if ( imgfile.length() && pimg ) {
234 pimg->label(get_cmd_line(argc, argv));
235 pimg->statistics();
236 write_img(imgfile, pimg, 0);
237 }
238
239 if ( pimg ) delete pimg;
240
241 molgroup_kill(molgroup);
242
243 residue_matrix_kill(simat);
244
245 if ( profile ) delete[] profile;
246
247 if ( verbose & VERB_TIME )
248 timer_report(ti);
249
250 bexit(0);
251 }
252
seq_align.h
Header file for functions to generate and analyze dot plots.
Bmolgroup::mol
Bmolecule * mol
Definition: rwmolecule.h:189
rwresprop.h
Header file for reading residue property files.
Bstring::real
double real()
Definition: Bstring.cpp:545
write_molecule
int write_molecule(char *filename, Bmolgroup *molgroup)
Writes a molecule group.
Definition: rwmolecule.cpp:975
seq_aligned_similarity
Bimage * seq_aligned_similarity(Bmolgroup *molgroup, double threshold, Bresidue_matrix *simat)
Calculates the pairwise similarities between aligned sequences.
Definition: seq_analysis.cpp:119
utilities.h
Header file for general utilities.
Boption::value
Bstring value
Definition: options.h:30
Bmolgroup::seqflag
int * seqflag
Definition: rwmolecule.h:188
Boption::tag
Bstring tag
Definition: options.h:29
Bstring::length
long length() const
Definition: Bstring.cpp:263
seq_aligned_profile
char * seq_aligned_profile(Bmolgroup *molgroup)
Generates a PROSITE format profile from an aligned set of sequences.
Definition: seq_analysis.cpp:197
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
get_option_list
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Definition: options.cpp:40
get_cmd_line
string get_cmd_line(int argc, char **argv)
Returns the command line as a string.
Definition: utilities.cpp:36
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
get_residue_matrix
Bresidue_matrix * get_residue_matrix(Bstring &filename)
Reading a residue matrix from a file.
Definition: rwresprop.cpp:164
Bimage
General image parameter class.
Definition: Bimage.h:163
Bmolecule::seq
Bstring seq
Definition: rwmolecule.h:114
Bmolgroup
Definition: rwmolecule.h:170
select_numbers
int select_numbers(Bstring &string, int n, int *numsel)
Converts a string with a selection specification into an integer array.
Definition: utilities.cpp:328
residue_matrix_kill
int residue_matrix_kill(Bresidue_matrix *resmat)
Deallocating a residue matrix.
Definition: rwresprop.cpp:208
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
molgroup_consolidate_gaps
int molgroup_consolidate_gaps(Bmolgroup *molgroup)
Removes redundant gaps from an alignment.
Definition: rwmolecule.cpp:1244
seq_aligned_hydrophobicity
int seq_aligned_hydrophobicity(Bmolgroup *molgroup, int window, double threshold, Bstring &hphobfile, Bstring &psfile)
Calculates the average hydrophobicity at every position in an alignment.
Definition: seq_analysis.cpp:456
Boption
A class for a command line input option.
Definition: options.h:26
Bimage::label
void label(string s)
Definition: Bimage.h:235
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
molgroup_kill
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
Definition: rwmolecule.cpp:374
main
int main(int argc, char **argv)
Definition: bseqaln.cpp:57
Bmolecule::next
Bmolecule * next
Definition: rwmolecule.h:108
Bmolgroup::maxlen
long maxlen
Definition: rwmolecule.h:180
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
seq_pair_align
long seq_pair_align(Bmolecule *mol1, Bmolecule *mol2, double gapopen, double gapextend, Bresidue_matrix *simat)
Aligns two sequences.
Definition: seq_align.cpp:34
seq_analysis.h
Header file for sequence analysis functions.
seq_aligned_identity
Bimage * seq_aligned_identity(Bmolgroup *molgroup)
Calculates the pairwise identities between aligned sequences.
Definition: seq_analysis.cpp:43
seq_aligned_information
int seq_aligned_information(Bmolgroup *molgroup, int window, Bstring &psfile)
Calculates the sequence logo representation for an alignment.
Definition: seq_analysis.cpp:302
Bresidue_matrix
Definition: rwresprop.h:44
Bmolecule
Definition: rwmolecule.h:107
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
molecule_update_comment
int molecule_update_comment(Bmolgroup *molgroup, int n, char **strings)
Puts a set of strings and time in the main comment of a molecule group.
Definition: rwmolecule.cpp:1462
use
const char * use[]
Definition: bseqaln.cpp:20
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bstring::integer
long integer()
Definition: Bstring.cpp:539
options.h
Header file for option handlers.
verbose
int verbose
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
read_molecule
Bmolgroup * read_molecule(const char *filename, const char *select, const char *paramfile)
The generalized function for reading molecular files.
Definition: rwmolecule.cpp:818