https://github.com/will-rowe/gfa
A Go library for working with Graphical Fragment Assembly format
https://github.com/will-rowe/gfa
gfa graphical-fragment-assembly variation-graph
Last synced: 5 months ago
JSON representation
A Go library for working with Graphical Fragment Assembly format
- Host: GitHub
- URL: https://github.com/will-rowe/gfa
- Owner: will-rowe
- License: mit
- Created: 2018-03-13T22:01:45.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-05-02T08:48:28.000Z (about 7 years ago)
- Last Synced: 2024-06-20T16:36:19.869Z (almost 2 years ago)
- Topics: gfa, graphical-fragment-assembly, variation-graph
- Language: Go
- Homepage:
- Size: 43.9 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
***
## Overview
This is a Go library for working with the `Graphical Fragment Assembly` (GFA) format.
> The purpose of the GFA format is to capture sequence graphs as the product of an assembly, a representation of variation in genomes, splice graphs in genes, or even overlap between reads from long-read sequencing technology.
Read the GFA spec [here](https://github.com/GFA-spec/GFA-spec/blob/master/GFA1.md).
Current limitations:
* restricted to GFA version 1
* does not handle the containment field
* validation is limited
## Installation
``` go
go get github.com/will-rowe/gfa
```
## Example usage
### convert an MSA file to a GFA file
``` go
package main
import (
"log"
"os"
"github.com/will-rowe/gfa"
)
var (
inputFile = "./example.msa"
)
func main() {
// open the MSA
msa, _ := gfa.ReadMSA(inputFile)
// convert the MSA to a GFA instance
myGFA, err := gfa.MSA2GFA(msa)
if err != nil {
log.Fatal(err)
}
// create a gfaWriter
outfile, err := os.Create("./example.gfa")
defer outfile.Close()
writer, err := gfa.NewWriter(outfile, myGFA)
if err != nil {
log.Fatal(err)
}
// write the GFA content
if err := myGFA.WriteGFAContent(writer); err != nil {
log.Fatal(err)
}
}
```
### process a GFA file line by line
``` go
package main
import (
"flag"
"io"
"log"
"os"
"github.com/will-rowe/gfa"
)
var (
inputFile = flag.String("inputFile", "", "input GFA file (empty for STDIN)")
)
func main() {
flag.Parse()
var r io.Reader
// open file stream and close it when finished
if *inputFile == "" {
r = os.Stdin
} else {
fh, err := os.Open(*inputFile)
if err != nil {
log.Fatalf("could not open file %q:", err)
}
defer fh.Close()
r = fh
}
// create a GFA reader
reader, err := gfa.NewReader(r)
if err != nil {
log.Fatal("can't read gfa file: %v", err)
}
// collect the GFA instance
myGFA := reader.CollectGFA()
// check version and print the header / comment lines
if myGFA.GetVersion() != 1 {
log.Fatal("gfa file is not in version 1 format")
}
log.Println(myGFA.PrintHeader())
if comments := myGFA.PrintComments(); comments != "" {
log.Println(comments)
}
// read the GFA file
for {
line, err := reader.Read()
if err == io.EOF {
break
}
if err != nil {
log.Fatal("error reading line in gfa file: %v", err)
}
// each line produced by Read() satisfies the gfaLine interface
formattedLine := line.PrintGFAline()
log.Printf("gfa line: %v", formattedLine)
// you can also add the line to the GFA instance
if err := line.Add(myGFA); err != nil {
log.Fatal("error adding line to GFA instance: %v", err)
}
}
}
```