File: hspstream.dy

package info (click to toggle)
wise 2.4.1-21
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 27,140 kB
  • sloc: ansic: 276,365; makefile: 1,003; perl: 886; lex: 93; yacc: 81; sh: 24
file content (204 lines) | stat: -rw-r--r-- 4,512 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204

%{
#include "../dynlibsrc/hsp.h"
#include "sequencestream.h"


%}


%{
#include "hspstream.h"

%func
untyped linear hsp manager to stream
%%
void untyped_LinearHSPmanager_to_Stream(void * lm,Wise2WriteStreamInterface * ws)
{
  return typed_LinearHSPmanager_to_Stream((void*)lm,ws);
}

%func
typed linear hsp manager to stream

writes out sequneces first, with query as first
sequence and then each target in turn, and then all the
hsps in turn, only writing down the target name
%%
void typed_LinearHSPmanager_to_Stream(LinearHSPmanager * lm,Wise2WriteStreamInterface * ws)
{
  int i,j;
  SequenceSet * out;
  char buffer[512];

  /* assumme that each HSPset has only one target sequence */

  out = SequenceSet_alloc_len(lm->len+1);  

  /* query goes in first */
  add_SequenceSet(out,hard_link_Sequence(lm->query));
  for(i=0;i<lm->len;i++) {
    if( lm->set[i]->len > 0 ) {
      if( lm->set[i]->hsp[0]->target == NULL) {
	warn("Unable to transport HSP at position %d, as no linked target sequence",i);
      } else {
	add_SequenceSet(out,hard_link_Sequence(lm->set[i]->hsp[0]->target));
      }
    }
  }

  typed_write_SequenceSet_to_Stream(out,ws);
  free_SequenceSet(out);

  /* now write the hsps */

  for(i=0;i<lm->len;i++) {
    if( lm->set[i]->len > 0 && lm->set[i]->hsp[0]->target != NULL ) {
      for(j=0;j<lm->set[i]->len;j++) {
	sprintf(buffer,"%s %d %d %d %d %d\n",
	      lm->set[i]->hsp[j]->target->name,
		lm->set[i]->hsp[j]->query_start,
		lm->set[i]->hsp[j]->target_start,
		lm->set[i]->hsp[j]->length,
		lm->set[i]->hsp[j]->score,
		lm->set[i]->hsp[j]->target_reverse);
	/*	fprintf(stderr,"%s %d %d %d %d %d\n",
		lm->set[i]->hsp[j]->target->name,
		lm->set[i]->hsp[j]->query_start,
		lm->set[i]->hsp[j]->target_start,
		lm->set[i]->hsp[j]->length,
		lm->set[i]->hsp[j]->score,
		lm->set[i]->hsp[j]->target_reverse);
	*/

	WISE2_WRITE_STRING(buffer,ws);
      }
    }
  }

  WISE2_WRITE_STRING("//\n",ws);
  
}


%func
untyped read
%%
void * untyped_LinearHSPmanager_from_Stream(Wise2ReadStreamInterface * rs)
{
  return (void*) typed_LinearHSPmanager_from_Stream(rs);
}


%func
typed linear hsp manager from stream

assummes sequences coming in first, with query as first sequence
and then hsps one after the other
%%
LinearHSPmanager * typed_LinearHSPmanager_from_Stream(Wise2ReadStreamInterface * rs)
{

  SequenceSet * set;
  LinearHSPmanager * lm;
  HSPset * curr;
  HSP * h;

  int seq_pos;
  int dummy;
  int i;

  char buffer[MAXLINE];

  set = typed_SequenceSet_from_Stream(rs);

  /*
  for(i=0;i<set->len;i++) {
    fprintf(stderr,"Got %d, %s with %s\n",i,set->set[i]->name,set->set[i]->desc);
  }
  */


  lm = LinearHSPmanager_alloc_std();
  lm->query = hard_link_Sequence(set->set[0]);

  if( set->len == 1 ) {
    WISE2_READ_BUFFER(buffer,MAXLINE,rs);
    /* should check it is // */

    return lm;
  }



  seq_pos = 1;
  curr = HSPset_alloc_std();
  add_LinearHSPmanager(lm,curr);

  while( WISE2_READ_BUFFER(buffer,MAXLINE,rs) != NULL ) {
    auto int k;
    auto int temp_len = strlen(set->set[seq_pos]->name);

    if( strncmp(buffer,"//",2) == 0 ) {
      break;
    }
    

    /* is space is because we can have partial matching
       at the start of the of an identifier, in particular with
       uniprot alternative splice -X names
    */

    for(k=0;k < MAXLINE;k++) {
      if( isspace(buffer[k]) ) {
	buffer[k] = '\0';
	break;
      }
    }

    /*fprintf(stderr,"Comparing %s to %s with %d (%d) %d %d\n",buffer,set->set[seq_pos]->name,strncmp(buffer,set->set[seq_pos]->name,temp_len),temp_len,isspace(buffer[temp_len]),(int)(buffer[temp_len]) );
     */

    if( strcmp(buffer,set->set[seq_pos]->name) != 0 ) {

      seq_pos++;
      if( seq_pos >= set->len ) {
	warn("Overrun set sequences\n");
	break;
      }
      curr = HSPset_alloc_std();
      add_LinearHSPmanager(lm,curr);

      if( strncmp(buffer,set->set[seq_pos]->name,temp_len) != 0 ) {
	warn("Unable to match hsp name of [%s] to sequence name of %s, skipping\n",buffer,set->set[seq_pos]->name);
	continue;
      }


    }

    /* parse this hsp */
    h = HSP_alloc();
    h->query = hard_link_Sequence(set->set[0]);
    h->target = hard_link_Sequence(set->set[seq_pos]);

    sscanf(buffer+strlen(set->set[seq_pos]->name)+1,"%d %d %d %d %d",&h->query_start,&h->target_start,&h->length,&h->score,&dummy);
    if( dummy == 0 ) {
      h->target_reverse = 0;
    } else {
      h->target_reverse = 1;
    }
    
    add_HSPset(curr,h);

  }



  free_SequenceSet(set);


  return lm;
}

%}