-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgseq-flank.go
55 lines (47 loc) · 1.09 KB
/
gseq-flank.go
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
package main
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"time"
)
// Takes an ID and returns the fasta sequence from Ensembl
// expanding the sequence by 1000bp up and downstream (hard coded)
func GetSequence(id string) string {
client := &http.Client{}
baseurl := "http://rest.ensembl.org"
ext := "/sequence/id/" + id + "?expand_5prime=1000;expand_3prime=1000;"
req, err := http.NewRequest("GET", baseurl+ext, nil)
// fmt.Println(baseurl + ext)
req.Header.Set("content-type", "text/x-fasta")
if err != nil {
log.Fatal(err)
}
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
seq, err := ioutil.ReadAll(resp.Body)
return string(seq)
}
func main() {
log.SetOutput(os.Stderr)
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
id := scanner.Text()
seq := GetSequence(id)
time.Sleep(100 * time.Millisecond)
d := []byte(seq)
err := ioutil.WriteFile(id+".1000bp.updown.fa", d, 0644)
if err != nil {
panic(err)
}
}
if err := scanner.Err(); err != nil {
fmt.Fprintln(os.Stderr, "reading standard input:", err)
}
}