func main() { flag.Parse() // Now really print out the connected components seqtype := alphabet.DNA f1, err := os.Open(*in) if err != nil { fmt.Fprintf(os.Stderr, "Error: %v.\n", err) os.Exit(1) } defer f1.Close() f2, err := os.Create(*out) if err != nil { fmt.Fprintf(os.Stderr, "Error: %v.\n", err) os.Exit(1) } defer f2.Close() fastaSeqs := fasta.NewReader(f1, linear.NewSeq("", nil, seqtype)) fastaOut := fasta.NewWriter(f2, 80) rand.Seed(time.Now().UnixNano()) list := rand.Perm(*total) keep := make(map[int]bool) for i := 0; i < *numkeep; i++ { keep[list[i]] = true } counter := 0 for true { seq, e := fastaSeqs.Read() if e != nil { break } if keep[counter] { fastaOut.Write(seq) } counter++ } fmt.Fprintf(os.Stderr, "Done.\n") }
// Write meta data to a GFF file. func (self *Writer) WriteMetaData(d interface{}) (n int, err error) { switch d.(type) { case []byte, string: n, err = self.w.WriteString("##" + d.(string) + "\n") case *seq.Seq: sw := fasta.NewWriter(self.f, self.Width) sw.IDPrefix = []byte(fmt.Sprintf("##%s ", d.(*seq.Seq).Moltype)) sw.SeqPrefix = []byte("##") n, err = sw.Write(d.(*seq.Seq)) if err != nil { return } err = sw.Flush() if err != nil { return } var m int m, err = self.w.WriteString("##end-" + d.(*seq.Seq).Moltype.String() + "\n") n += m if err != nil { return } err = self.w.Flush() return case *feat.Feature: start := d.(*feat.Feature).Start if self.OneBased && start >= 0 { start++ } n, err = self.w.WriteString("##sequence-region " + string(d.(*feat.Feature).ID) + " " + strconv.Itoa(start) + " " + strconv.Itoa(d.(*feat.Feature).End) + "\n") default: n, err = 0, bio.NewError("Unknown meta data type", 0, d) } if err == nil { err = self.w.Flush() } return }