func (self *Reader) metaSequence(moltype, id string) (sequence *seq.Seq, err error) { var line, body []byte for { line, err = self.r.ReadBytes('\n') if err != nil { return nil, err } if len(line) > 0 && line[len(line)-1] == '\r' { line = line[:len(line)-1] } if len(line) == 0 { continue } if len(line) < 2 || !bytes.HasPrefix(line, []byte("##")) { return nil, bio.NewError("Corrupt metasequence", 0, line) } line = bytes.TrimSpace(line[2:]) if string(line) == "end-"+moltype { break } else { line = bytes.Join(bytes.Fields(line), nil) body = append(body, line...) } } sequence = seq.New(id, body, nil) sequence.Moltype = bio.ParseMoltype(moltype) return }
func (self *Reader) commentMetaline(line string) (f *feat.Feature, err error) { // Load these into a slice in a MetaField of the Feature fields := strings.Split(string(line), " ") switch fields[0] { case "gff-version": self.Version, err = strconv.Atoi(fields[1]) if err != nil { self.Version = DefaultVersion } return self.Read() case "source-version": if len(fields) > 1 { self.SourceVersion = strings.Join(fields[1:], " ") return self.Read() } else { return nil, bio.NewError("Incomplete source-version metaline", 0, fields) } case "date": if len(fields) > 1 { self.Date, err = time.Parse(self.TimeFormat, strings.Join(fields[1:], " ")) return self.Read() } else { return nil, bio.NewError("Incomplete date metaline", 0, fields) } case "Type": if len(fields) > 1 { self.Type = bio.ParseMoltype(fields[1]) return self.Read() } else { return nil, bio.NewError("Incomplete Type metaline", 0, fields) } case "sequence-region": if len(fields) > 3 { var start, end int start, err = strconv.Atoi(fields[2]) if err != nil { return nil, err } else { if self.OneBased { start = bio.OneToZero(start) } } end, err = strconv.Atoi(fields[3]) if err != nil { return nil, err } f = &feat.Feature{ Meta: &feat.Feature{ ID: fields[1], Start: start, End: end, }, } } else { return nil, bio.NewError("Incomplete sequence-region metaline", 0, fields) } case "DNA", "RNA", "Protein": if len(fields) > 1 { var s *seq.Seq s, err = self.metaSequence(fields[0], fields[1]) if err != nil { return } else { f = &feat.Feature{Meta: s} } } else { return nil, bio.NewError("Incomplete sequence metaline", 0, fields) } default: f = &feat.Feature{Meta: line} } return }