39
39
* ------- ---------- -----------------------------------------------------
41
41
* $Log: seqport.c,v $
42
* Revision 6.150 2006/03/22 15:31:32 kans
43
* SeqPortStreamSeqLoc gives unique message when bailing on gi 0 as opposed to failure after trying to load
45
* Revision 6.149 2006/03/07 21:34:28 kans
46
* checks for gi 0 now also check for negative value
48
* Revision 6.148 2006/03/07 20:02:01 kans
49
* SeqPortStreamSeqLoc immediately treats gi 0 as an error
51
* Revision 6.147 2006/01/23 13:01:41 bollin
52
* when converting sequences from raw to delta, adjust any alignments that the
53
* sequence may be part of.
55
* Revision 6.146 2005/12/16 20:19:56 bollin
56
* only allow reverse for delta sequences when the delta sequence has no far locations
58
* Revision 6.145 2005/12/15 19:45:24 bollin
59
* added functions to reverse and complement delta sequences
42
61
* Revision 6.144 2005/08/24 15:14:31 kans
43
62
* modified MolWtForLoc to use StreamCache, added MolWtForBsp and MolWtForStr
2967
2987
sip = SeqLocId (slp);
2968
2988
if (sip == NULL) return 0;
2990
if (sip->choice == SEQID_GI && sip->data.intvalue <= 0) {
2992
/* gi 0 or negative is always a data error, just report and bail */
2994
SeqIdWrite (sip, buf, PRINTID_FASTA_SHORT, sizeof (buf) - 1);
2995
if (parentID != NULL) {
2996
SeqIdWrite (parentID, pid, PRINTID_FASTA_LONG, sizeof (pid) - 1);
2997
ErrPostEx (SEV_ERROR, 0, 0, "SeqPortStream ignoring Bioseq %s component of %s", buf, pid);
2999
ErrPostEx (SEV_ERROR, 0, 0, "SeqPortStream ignoring Bioseq %s", buf);
2970
3005
bsp = BioseqLockById (sip);
4992
/*-------------- BioseqComplement () ---------------------------*/
4993
/***********************************************************************
4994
* BioseqComplement: Takes the nucleic acid sequence from Bioseq
4995
* Entry and gives the complement sequence in place
4996
* Does not change features.
4997
************************************************************************/
4998
NLM_EXTERN Boolean LIBCALL BioseqComplement (BioseqPtr bsp)
5027
static Boolean ComplementSeqData (Uint1 seqtype, Int4 seqlen, ByteStorePtr bysp)
5000
5029
SeqCodeTablePtr sctp;
5002
long readbyte, bslen;
5004
Uint1 seqtype, byte = 0, byte_to, newbyte = 0, residue;
5030
long readbyte, bslen;
5031
Uint1 byte = 0, byte_to, newbyte = 0, residue;
5005
5032
Uint1 comp, bitctr, mask, lshift, rshift, bc;
5009
ErrPostEx(SEV_ERROR,0,0, "Error: not a BioseqPtr\n");
5013
if (bsp->repr != Seq_repr_raw)
5015
ErrPostEx(SEV_ERROR,0,0, "Error: not a raw sequence\n");
5019
if (bsp->seq_data == NULL)
5021
5036
ErrPostEx(SEV_ERROR,0,0, "Error: no sequence data\n");
5025
seqtype = bsp->seq_data_type;
5026
if ( ISA_aa(bsp->mol)) {
5027
ErrPostEx(SEV_ERROR,0,0, "Error: cannot complement aa\n");
5031
5040
if ((sctp = SeqCodeTableFind (seqtype)) == NULL)
5033
5042
ErrPostEx(SEV_ERROR,0,0, "Can't open table\n");
5059
case Seq_code_iupacaa:
5060
case Seq_code_ncbi8aa:
5061
case Seq_code_ncbieaa:
5062
case Seq_code_ncbipaa:
5063
case Seq_code_iupacaa3:
5064
case Seq_code_ncbistdaa: /* ignore amino acid */
5065
ErrPostEx(SEV_ERROR,0,0, "Error: cannot complement aa ; No ->mol flag on Bioseq\n");
5067
case Seq_code_ncbipna:
5068
ErrPostEx(SEV_WARNING,0,0, "Error: Don't yet know how to complement profile\n");
5068
case Seq_code_iupacaa:
5069
case Seq_code_ncbi8aa:
5070
case Seq_code_ncbieaa:
5071
case Seq_code_ncbipaa:
5072
case Seq_code_iupacaa3:
5073
case Seq_code_ncbistdaa: /* ignore amino acid */
5074
ErrPostEx(SEV_ERROR,0,0, "Error: cannot complement aa ; No ->mol flag on Bioseq\n");
5076
case Seq_code_ncbipna:
5077
ErrPostEx(SEV_WARNING,0,0, "Error: Don't yet know how to complement profile\n");
5073
seqlen = bsp->length;
5074
bysp = bsp->seq_data;
5075
5083
bslen = BSLen(bysp);
5125
static Boolean DeltaBioseqComplement (BioseqPtr bsp)
5129
Boolean rval = FALSE;
5131
if (bsp == NULL || bsp->repr != Seq_repr_delta)
5136
dsp = (DeltaSeqPtr) bsp->seq_ext;
5139
if (dsp->choice != 2)
5141
ErrPostEx(SEV_ERROR,0,0, "Error: Can't complement delta sequences with far locs\n");
5147
dsp = (DeltaSeqPtr) bsp->seq_ext;
5150
slip = (SeqLitPtr) dsp->data.ptrvalue;
5151
/* complement data */
5152
if (slip->seq_data != NULL)
5154
rval &= ComplementSeqData (slip->seq_data_type, slip->length, slip->seq_data);
5162
/*-------------- BioseqComplement () ---------------------------*/
5163
/***********************************************************************
5164
* BioseqComplement: Takes the nucleic acid sequence from Bioseq
5165
* Entry and gives the complement sequence in place
5166
* Does not change features.
5167
************************************************************************/
5168
NLM_EXTERN Boolean LIBCALL BioseqComplement (BioseqPtr bsp)
5170
Boolean rval = FALSE;
5174
ErrPostEx(SEV_ERROR,0,0, "Error: not a BioseqPtr\n");
5177
else if (ISA_aa(bsp->mol))
5179
ErrPostEx(SEV_ERROR,0,0, "Error: cannot complement aa\n");
5182
else if (bsp->repr == Seq_repr_delta)
5184
rval = DeltaBioseqComplement (bsp);
5186
else if (bsp->repr == Seq_repr_raw)
5188
rval = ComplementSeqData (bsp->seq_data_type, bsp->length, bsp->seq_data);
5192
ErrPostEx(SEV_ERROR,0,0, "Error: not a raw or delta sequence\n");
5114
5197
} /* BioseqComplement */
5117
/*-------------- BioseqReverse () ---------------------------*/
5118
/***********************************************************************
5119
* BioseqReverse: Takes nucleic acid sequence from Bioseq Entry and
5120
* reverses the whole sequence in place
5121
* Does not change features.
5122
************************************************************************/
5123
NLM_EXTERN Boolean LIBCALL BioseqReverse (BioseqPtr bsp)
5200
static Boolean LIBCALL ReverseSeqData (Uint1 seqtype, Int4 seqlen, ByteStorePtr bysp1)
5125
ByteStorePtr bysp1 = '\0';
5126
5202
ByteStorePtr bysp2 = '\0';
5127
5203
long readbyte, bslen = 0;
5128
Int4 seqlen, count = 0;
5129
Uint1 seqtype, byte = 0, byte2, byte_to = 0, byte_to2, newbyte = 0;
5205
Uint1 byte = 0, byte2, byte_to = 0, byte_to2, newbyte = 0;
5130
5206
Uint1 newbyte2, finalbyte, residue, residue2, bitctr, bc2 = 0;
5131
5207
Uint1 bitctr2, mask, mask2, lshift, rshift, bc = 0, jagged;
5135
ErrPostEx(SEV_ERROR,0,0, "Error: not a BioseqPtr\n");
5139
if (bsp->repr != Seq_repr_raw)
5141
ErrPostEx(SEV_ERROR,0,0, "Error: not a raw sequence\n");
5145
if (bsp->seq_data == NULL)
5147
ErrPostEx(SEV_ERROR,0,0, "Error: No sequence data\n");
5211
ErrPostEx(SEV_ERROR,0,0, "Error: No sequence data\n");
5151
seqlen = bsp->length;
5152
seqtype = bsp->seq_data_type;
5153
5215
switch (seqtype){
5154
5216
case Seq_code_ncbi2na: /*bitshifts needed*/
5378
} /* ReverseSeqData */
5381
static Boolean DeltaBioseqReverse (BioseqPtr bsp)
5383
DeltaSeqPtr dsp, next_dsp, newchain = NULL;
5385
Boolean rval = FALSE;
5386
Boolean split = FALSE;
5388
if (bsp == NULL || bsp->repr != Seq_repr_delta)
5393
dsp = (DeltaSeqPtr) bsp->seq_ext;
5396
if (dsp->choice != 2)
5398
ErrPostEx(SEV_ERROR,0,0, "Error: Can't reverse delta sequences with far locs\n");
5404
dsp = (DeltaSeqPtr) bsp->seq_ext;
5408
slip = (SeqLitPtr) dsp->data.ptrvalue;
5410
if (slip->seq_data != NULL)
5412
rval &= ReverseSeqData (slip->seq_data_type, slip->length, slip->seq_data);
5415
/* reverse the chain */
5416
next_dsp = dsp->next;
5417
dsp->next = newchain;
5422
bsp->seq_ext = newchain;
5426
/*-------------- BioseqReverse () ---------------------------*/
5427
/***********************************************************************
5428
* BioseqReverse: Takes nucleic acid sequence from Bioseq Entry and
5429
* reverses the whole sequence in place
5430
* Does not change features.
5431
************************************************************************/
5432
NLM_EXTERN Boolean LIBCALL BioseqReverse (BioseqPtr bsp)
5438
ErrPostEx(SEV_ERROR,0,0, "Error: not a BioseqPtr\n");
5441
else if (bsp->repr == Seq_repr_delta)
5443
rval = DeltaBioseqReverse (bsp);
5445
else if (bsp->repr == Seq_repr_raw)
5447
rval = ReverseSeqData (bsp->seq_data_type, bsp->length, bsp->seq_data);
5451
ErrPostEx(SEV_ERROR,0,0, "Error: not a raw or delta sequence\n");
5317
5456
} /* BioseqReverse */
5319
5458
#define SPC_BUFF_CHUNK 1024
7831
7975
MemSet (extra_ns, 'N', diff);
7832
7976
extra_ns [diff] = 0;
7833
insertchar (extra_ns, offset, sip, moltype, FALSE);
7977
insertchar (extra_ns, offset, bsp->id, bsp->mol, FALSE);
7979
slp = SeqLocIntNew (offset, offset + diff - 1, Seq_strand_plus, bsp->id);
7980
for (vnp = align_annot_list; vnp != NULL; vnp = vnp->next)
7982
sanp = vnp->data.ptrvalue;
7983
if (sanp != NULL && sanp->type == 2)
7985
sanp->data = SeqAlignInsertByLoc (slp, sanp->data);
7838
slp = SeqLocIntNew (offset, offset - diff - 1, Seq_strand_plus, sip);
7992
slp = SeqLocIntNew (offset, offset - diff - 1, Seq_strand_plus, bsp->id);
7839
7993
SeqDeleteByLoc (slp, TRUE, FALSE);
7995
for (vnp = align_annot_list; vnp != NULL; vnp = vnp->next)
7997
sanp = vnp->data.ptrvalue;
7998
if (sanp != NULL && sanp->type == 2)
8000
sanp->data = SeqAlignDeleteByLoc (slp, sanp->data);
7840
8004
SeqLocFree (slp);