polyjson

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package polyjson provides utilities to read and write poly.Sequence structs as JSON.

Poly's JSON schema is still in flux so be on the lookout for breaking changes as we approach the 1.0 release.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(file []byte) poly.Sequence

Parse parses a poly.Sequence JSON file and adds appropriate pointers to struct.

Example
package main

import (
	"fmt"
	"io/ioutil"

	"github.com/TimothyStiles/poly/io/polyjson"
)

func main() {
	file, _ := ioutil.ReadFile("../../data/sample.json")
	sequence := polyjson.Parse(file)

	fmt.Println(sequence.Meta.Source)
}
Output:

Saccharomyces cerevisiae (baker's yeast)

func Read

func Read(path string) poly.Sequence

Read reads a poly.Sequence JSON file.

Example
package main

import (
	"fmt"

	"github.com/TimothyStiles/poly/io/polyjson"
)

func main() {
	sequence := polyjson.Read("../../data/sample.json")

	fmt.Println(sequence.Meta.Source)
}
Output:

Saccharomyces cerevisiae (baker's yeast)

func Write

func Write(sequence poly.Sequence, path string)

Write writes a poly.Sequence struct out to json.

Example
package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"

	"github.com/TimothyStiles/poly/io/polyjson"
)

func main() {
	tmpDataDir, err := ioutil.TempDir("", "data-*")
	if err != nil {
		fmt.Println(err.Error())
	}
	defer os.RemoveAll(tmpDataDir)

	sequence := polyjson.Read("../../data/sample.json")

	tmpJSONFilePath := filepath.Join(tmpDataDir, "sample.json")
	polyjson.Write(sequence, tmpJSONFilePath)

	testSequence := polyjson.Read(tmpJSONFilePath)

	fmt.Println(testSequence.Meta.Source)
}
Output:

Saccharomyces cerevisiae (baker's yeast)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL