1093
static SeqPortPtr SeqPortFromAlignmentInterval (Int4 seqstart, Int4 seqstop, Uint1 strand, BioseqPtr bsp)
1099
if (bsp == NULL) return NULL;
1101
if (sinp == NULL) return NULL;
1102
sinp->from = seqstart;
1104
sinp->strand = strand;
1105
sinp->id = SeqIdDup (SeqIdFindBest (bsp->id, 0));
1106
slp = ValNodeNew (NULL);
1111
slp->choice = SEQLOC_INT;
1112
slp->data.ptrvalue = (Pointer) sinp;
1113
spp = SeqPortNewByLoc (slp, Seq_code_iupacna);
1118
static void SetSequenceIntervalBuf
1127
Uint1Ptr target_buf)
1129
Int4 buf_len = stop - start + 1;
1134
if (seqstart == NULL || seqstop == NULL)
1139
*seqstart = ALNMGR_GAP;
1140
*seqstop = ALNMGR_GAP;
1145
strand = SeqAlignStrand (salp, row - 1);
1146
MemSet (target_buf, 0, buf_len);
1147
/* if this is a minus strand sequence, start is stop and stop is start */
1148
if (strand == Seq_strand_minus) {
1149
*seqstop = AlnMgr2MapSeqAlignToBioseq(salp, start, row);
1150
*seqstart = AlnMgr2MapSeqAlignToBioseq(salp, stop, row);
1152
*seqstart = AlnMgr2MapSeqAlignToBioseq(salp, start, row);
1153
*seqstop = AlnMgr2MapSeqAlignToBioseq(salp, stop, row);
1156
if (strand == Seq_strand_minus) {
1158
while (*seqstart == ALNMGR_GAP && i > 0) { /* count backward if we are in the gap */
1160
*seqstart = AlnMgr2MapSeqAlignToBioseq(salp, i, row);
1164
while (*seqstart == ALNMGR_GAP && i < aln_len) { /* count forward if we in the gap */
1166
*seqstart = AlnMgr2MapSeqAlignToBioseq(salp, i, row);
1169
if (*seqstop == -1 || *seqstop>=bsp->length) *seqstop = bsp->length - 1; /* -1 means exeed sequence length */
1171
if (strand == Seq_strand_minus) {
1173
while (*seqstop == ALNMGR_GAP && i > 0) { /* count backward if we are in the gap */
1175
*seqstop = AlnMgr2MapSeqAlignToBioseq(salp, i, row);
1179
while (*seqstop == ALNMGR_GAP && i < aln_len) { /* count forward if we are in the gap */
1181
*seqstop = AlnMgr2MapSeqAlignToBioseq(salp, i, row);
1185
if (*seqstart == ALNMGR_GAP && *seqstop == ALNMGR_GAP) {
1188
if (*seqstop < 0) *seqstop = bsp->length - 1;
1189
if (*seqstart < 0) *seqstart = *seqstop;
1190
if (strand == Seq_strand_minus) {
1191
if (*seqstop - *seqstart > buf_len)
1192
*seqstart = *seqstop - buf_len;
1194
if (*seqstop - *seqstart > buf_len) *seqstop = *seqstart + buf_len; /* not to exeed the current line */
1197
spp = SeqPortFromAlignmentInterval (*seqstart, *seqstop, strand, bsp);
1198
SeqPortRead (spp, target_buf, *seqstop - *seqstart + 1);
1204
AlignmentIntervalToString
1210
Boolean view_whole_entity,
1213
Int4 PNTR alnbuffer_len,
1214
Boolean show_substitutions)
1216
Int4 aln_len = AlnMgr2GetAlnLength(salp, FALSE);
1217
SeqIdPtr sip = AlnMgr2GetNthSeqIdPtr(salp, row);
1218
BioseqPtr bsp = BioseqLockById(sip);
1219
Int4 alnbuf_len = stop - start + 1;
1221
Int4 seqstart, seqstop;
1225
Uint1 target_strand;
1226
SeqIdPtr sip_target;
1227
BioseqPtr bsp_target;
1230
Uint1Ptr target_buf;
1233
MemSet(alnbuf, '-', alnbuf_len); /* assume all gaps and fill the sequence later */
1234
MemSet(seqbuf, 0, alnbuf_len);
1235
if (target_row < 0) return;
1237
if (stop > aln_len && start > aln_len)
1239
aln_len = AlnMgr2GetAlnLength(salp, FALSE);
1243
if (stop > aln_len) {
1244
MemSet (alnbuf + aln_len - start, 0, stop - aln_len);
1246
alnbuf_len = stop - start + 1;
1249
if (alnbuffer_len != NULL) {
1250
*alnbuffer_len = alnbuf_len;
1253
strand = SeqAlignStrand (salp, row - 1);
1254
target_strand = SeqAlignStrand (salp, target_row - 1);
1255
/* if this is a minus strand sequence, start is stop and stop is start */
1256
if (strand == Seq_strand_minus) {
1257
seqstop = AlnMgr2MapSeqAlignToBioseq(salp, start, row);
1258
seqstart = AlnMgr2MapSeqAlignToBioseq(salp, stop, row);
1260
seqstart = AlnMgr2MapSeqAlignToBioseq(salp, start, row);
1261
seqstop = AlnMgr2MapSeqAlignToBioseq(salp, stop, row);
1264
if (strand == Seq_strand_minus) {
1266
while (seqstart == ALNMGR_GAP && i > 0) { /* count backward if we are in the gap */
1268
seqstart = AlnMgr2MapSeqAlignToBioseq(salp, i, row);
1272
while (seqstart == ALNMGR_GAP && i < aln_len) { /* count forward if we in the gap */
1274
seqstart = AlnMgr2MapSeqAlignToBioseq(salp, i, row);
1278
if (seqstop == -1 || seqstop>=bsp->length)
1280
seqstop = bsp->length - 1; /* -1 means exeed sequence length */
1283
if (strand == Seq_strand_minus) {
1285
while (seqstop == ALNMGR_GAP && i > 0) { /* count backward if we are in the gap */
1287
seqstop = AlnMgr2MapSeqAlignToBioseq(salp, i, row);
1291
while (seqstop == ALNMGR_GAP && i < aln_len) { /* count forward if we are in the gap */
1293
seqstop = AlnMgr2MapSeqAlignToBioseq(salp, i, row);
1297
if (seqstart == ALNMGR_GAP && seqstop == ALNMGR_GAP) seqstart = seqstop = 0; /* whole line are gaps */
1298
if (seqstop < 0) seqstop = bsp->length - 1;
1299
if (seqstart < 0) seqstart = seqstop;
1300
if (strand == Seq_strand_minus) {
1301
if (seqstop - seqstart > alnbuf_len)
1303
seqstart = seqstop - alnbuf_len;
1306
if (seqstop - seqstart > alnbuf_len)
1308
seqstop = seqstart + alnbuf_len; /* not to exeed the current line */
1312
spp = SeqPortFromAlignmentInterval (seqstart, seqstop, strand, bsp);
1313
SeqPortRead (spp, seqbuf, seqstop - seqstart + 1);
1314
if (seqbuf [stop - start] == 0) {
1315
seq_len = StringLen ((CharPtr) seqbuf);
1317
seq_len = stop - start + 1;
1323
if (row != target_row && ! view_whole_entity && target_row != ROW_UNDEFINED) {
1324
sip_target = AlnMgr2GetNthSeqIdPtr(salp, target_row);
1325
bsp_target = BioseqLockById(sip_target);
1327
target_buf = (Uint1Ptr) MemNew (stop - start + 1);
1328
MemSet (target_buf, 0, stop - start + 1);
1329
if (target_buf != NULL) {
1330
SetSequenceIntervalBuf (salp, bsp_target, target_row, start, stop,
1331
&target_start, &target_stop, aln_len, target_buf);
1342
for (aln_pos = start; aln_pos <= stop; aln_pos ++) {
1343
Int4 seq_pos = AlnMgr2MapSeqAlignToBioseq(salp, aln_pos, row);
1344
Int4 target_pos = AlnMgr2MapSeqAlignToBioseq(salp, aln_pos, target_row);
1347
alnbuf [aln_pos - start] = TO_LOWER (seqbuf[k]);
1348
if (show_substitutions)
1350
/* Handle mismatches (insert dots when matched) */
1351
if (row != target_row && ! view_whole_entity && target_row != ROW_UNDEFINED) {
1352
if(target_pos >= 0 && target_pos < bsp_target->length) { /* no gap in the target sequence */
1353
if (seqbuf[k] == target_buf[i]) {
1354
alnbuf[aln_pos - start] = GAP_CHAR;
1361
if (target_pos >= 0) {
1366
if (alnbuf[alnbuf_len] == 0) {
1367
*alnbuffer_len = StringLen ((CharPtr) alnbuf);
1370
if (bsp_target != NULL) {
1371
BioseqUnlock (bsp_target);
1373
if (sip_target != NULL) {
1374
SeqIdFree (sip_target);
1376
if (target_buf != NULL) {
1377
MemFree (target_buf);
1383
1125
static void DrawAlignment
1384
1126
(Int2 x, Int2 y, Int4 line, Int4 row, Uint1Ptr buf, Uint1Ptr seqbuf,
9784
static SeqAlignPtr LIBCALLBACK GetSeqAlignPiece (SeqLocPtr slp1, SeqLocPtr slp2)
9786
BLAST_SummaryOptions *options = NULL;
9787
SBlastSeqalignArray * seqalign_arr=NULL;
9788
SeqAlignPtr salp = NULL;
9791
if (slp1 == NULL || slp2 == NULL) return NULL;
9794
bsp = BioseqFindFromSeqLoc (slp1);
9800
BLAST_SummaryOptionsInit(&options);
9802
if (ISA_na (bsp->mol))
9804
options->program = eBlastn;
9808
options->program = eBlastp;
9811
options->gapped_calculation = TRUE;
9812
options->cutoff_evalue = 10;
9813
options->gap_x_dropoff = 100;
9814
options->gap_open = 4;
9815
options->gap_extend = 1;
9816
options->nucleotide_mismatch = -1;
9817
options->word_size = 7;
9819
BLAST_TwoSeqLocSets(options, slp1, slp2, NULL, &seqalign_arr, NULL, NULL, NULL);
9821
if (seqalign_arr != NULL)
9823
salp = seqalign_arr->array[0];
9824
seqalign_arr->array[0] = NULL;
9825
seqalign_arr = SBlastSeqalignArrayFree(seqalign_arr);
9828
BLAST_SummaryOptionsFree(options);
9998
9832
NLM_EXTERN SeqAlignPtr Sequin_GlobalAlign2Seq (BioseqPtr bsp1, BioseqPtr bsp2, BoolPtr revcomp)
10000
return Sqn_GlobalAlign2SeqEx (bsp1, bsp2, revcomp, GetSeqAlign);
9834
return Sqn_GlobalAlign2SeqEx (bsp1, bsp2, revcomp, GetSeqAlign, GetSeqAlignPiece);
10003
9837
/* This function produces a text representation of the alignment salp starting one nucleotide