Permalink
Browse files

anonymize filter working, needs api intergration

  • Loading branch information...
1 parent c3267ce commit e8f72c39e0a9bcf284628411ef38ecb83c4e912d @jaredwilkening jaredwilkening committed Mar 23, 2012
Showing with 92 additions and 9 deletions.
  1. +2 −2 Roadmap.txt
  2. +5 −4 errors/errors.go
  3. +67 −0 filters/anonymize/anonymize.go
  4. +10 −0 filters/filters.go
  5. +2 −0 shock-server/nodeController.go
  6. +6 −3 shock-server/util.go
View
@@ -6,8 +6,8 @@ Release 0.2 (3/22/12)
- basic user management: Done
Release 0.3 (4/1/12)
- - checksums on content
- - object version checksum
+ - checksums on content: Done
+ - object version checksum: Done
- data set mirroring
- virtual nodes
- filters
View
@@ -9,8 +9,9 @@ var (
)
const (
- MongoDocNotFound = "Document not found"
- UnAuth = "User Unauthorized"
- NoAuth = "No Authorization"
- InvalidIndex = "Invalid Index"
+ MongoDocNotFound = "Document not found"
+ UnAuth = "User Unauthorized"
+ NoAuth = "No Authorization"
+ InvalidIndex = "Invalid Index"
+ InvalidFileTypeForFilter = "Invalid file type for filter"
)
@@ -0,0 +1,67 @@
+package anonymize
+
+import (
+ "io"
+ "errors"
+ e "github.com/MG-RAST/Shock/errors"
+ "github.com/kortschak/BioGo/io/seqio/fasta"
+ "github.com/kortschak/BioGo/io/seqio/fastq"
+ "github.com/kortschak/BioGo/io/seqio"
+ "fmt"
+)
+
+type Reader struct {
+ f io.ReadCloser
+ r seqio.Reader
+ rfasta *fasta.Reader
+ rfastq *fastq.Reader
+ counter int
+}
+
+func NewReader(f io.ReadCloser) *Reader {
+ return &Reader{ f: f, r: nil, rfasta: fasta.NewReader(f), rfastq: fastq.NewReader(f), counter: 1}
+}
+
+func (r *Reader) determineSeqType() (err error){
+ _, fastaE := r.rfasta.Read()
+ _, fastqE := r.rfastq.Read()
+ if fastaE != nil && fastqE != nil {
+ err = errors.New(e.InvalidFileTypeForFilter)
+ } else if fastaE != nil {
+ err = r.rfastq.Rewind(); if err != nil {
+ return
+ }
+ r.r = r.rfastq
+ } else {
+ err = r.rfastq.Rewind(); if err != nil {
+ return
+ }
+ r.r = r.rfasta
+ }
+ return
+}
+
+func (r *Reader) Read(p []byte) (n int, err error) {
+ if r.r == nil {
+ err = r.determineSeqType(); if err != nil {
+ return
+ }
+ }
+ seq, err := r.r.Read(); if err != nil {
+ return
+ }
+ seq.ID = fmt.Sprintf("%d", r.counter)
+ r.counter += 1
+ record := []byte(fmt.Sprintf(">%s\n%s\n",seq.ID, seq.Seq))
+ copy(p[0:len(record)],record)
+ n = len(record)
+ return
+}
+
+func (r *Reader) Close() {
+ r.rfasta.Close()
+ r.rfastq.Close()
+ return
+}
+
+
View
@@ -0,0 +1,10 @@
+package filters
+
+import (
+ "io"
+)
+
+interface Filter {
+ io.Reader
+}
+
@@ -188,6 +188,7 @@ func (cr *NodeController) Read(id string, cx *goweb.Context) {
s.size = size
err = s.stream()
if err != nil {
+ // fix
fmt.Println("err", err.Error())
}
} else {
@@ -251,6 +252,7 @@ func (cr *NodeController) Read(id string, cx *goweb.Context) {
s := &streamer{rs: nf, ws: cx.ResponseWriter, contentType: "application/octet-stream", filename: node.Id, size: node.File.Size}
err = s.stream()
if err != nil {
+ // fix
fmt.Println("err", err.Error())
}
}
View
@@ -8,6 +8,7 @@ import (
"fmt"
"github.com/MG-RAST/Shock/conf"
ds "github.com/MG-RAST/Shock/datastore"
+ "github.com/MG-RAST/Shock/filters/anonymize"
"github.com/MG-RAST/Shock/user"
"io"
"math/rand"
@@ -19,7 +20,7 @@ import (
)
type streamer struct {
- rs io.Reader
+ rs io.ReadCloser
ws http.ResponseWriter
contentType string
filename string
@@ -37,8 +38,10 @@ type partStreamer struct {
func (s *streamer) stream() (err error) {
s.ws.Header().Set("Content-Type", s.contentType)
s.ws.Header().Set("Content-Disposition", fmt.Sprintf(":attachment;filename=%s", s.filename))
- s.ws.Header().Set("Content-Length", fmt.Sprint(s.size))
- _, err = io.Copy(s.ws, s.rs)
+ //s.ws.Header().Set("Content-Length", fmt.Sprint(s.size))
+ ar := anonymize.NewReader(s.rs)
+ defer ar.Close()
+ _, err = io.Copy(s.ws, ar)
return
}

0 comments on commit e8f72c3

Please sign in to comment.