MCPcopy Create free account
hub / github.com/MG-RAST/Shock / StreamSamtools

Method StreamSamtools

shock-server/request/streamer.go:168–215  ·  view source on GitHub ↗
(filePath string, region string, args ...string)

Source from the content-addressed store, hash-verified

166}
167
168func (s *Streamer) StreamSamtools(filePath string, region string, args ...string) (err error) {
169 //involking samtools in command line:
170 //samtools view [-c] [-H] [-f INT] ... filname.bam [region]
171
172 argv := []string{}
173 argv = append(argv, "view")
174 argv = append(argv, args...)
175 argv = append(argv, filePath)
176
177 if region != "" {
178 argv = append(argv, region)
179 }
180
181 index.LoadBamIndex(filePath)
182
183 cmd := exec.Command("samtools", argv...)
184 stdout, perr := cmd.StdoutPipe()
185 if perr != nil {
186 err = fmt.Errorf("(request.StreamSamtools) failed: file=%s; error=%s", filePath, perr.Error())
187 return
188 }
189
190 serr := cmd.Start()
191 if serr != nil {
192 err = fmt.Errorf("(request.StreamSamtools) failed: file=%s; error=%s", filePath, serr.Error())
193 return
194 }
195
196 go func() {
197 _, ioerr := io.Copy(s.W, stdout)
198 if ioerr != nil {
199 s.E = ioerr
200 }
201 }()
202 if s.E != nil {
203 err = fmt.Errorf("(request.StreamSamtools) failed: file=%s; error=%s", filePath, s.E.Error())
204 return
205 }
206
207 werr := cmd.Wait()
208 if werr != nil {
209 err = fmt.Errorf("(request.StreamSamtools) failed: file=%s; error=%s", filePath, werr.Error())
210 return
211 }
212
213 index.UnLoadBamIndex(filePath)
214 return
215}
216
217//helper function to translate args in URL query to samtools args
218//manual: http://samtools.sourceforge.net/samtools.shtml

Callers 1

ReadMethod · 0.80

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected