go-sra-schemas-1.5

module
v0.0.0-...-2d5b814 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2015 License: BSD-2-Clause

README

Autogenerated golang structs for NCBI's Sequence Read Archive (SRA) XML schema

This repository contains Go packages to encode/xml.Unmarshal() the version 1.5 SRA XML schema formats. These include the SRA Study, SRA Sample, SRA Experiment, SRA Run, SRA Analysis and SRA Submission definitions.

The code has been autogenerated with the go-xsd package. You can go get all the packages or simply fetch a selected subset of them. In your go project just type:

# for all the packages
go get -d github.com/indraniel/go-sra-schemas-1.5/...

# for a single package
go get github.com/indraniel/go-sra-schemas-1.5/SRA.run.xsd_go

Example Usage

You will need to define a custom struct in your own code to use these autogenerated packages. For example, to use the SRA Run package you can create a simple program like this:

package main

import (
	"encoding/xml"
	"fmt"
	srarun "github.com/indraniel/go-sra-schemas-1.5/SRA.run.xsd_go"
)

type SraRun struct {
	XMLName xml.Name `xml:"RUN_SET"`
	srarun.TxsdRunSet
}

func (sr SraRun) String() string {
	xml, err := xml.MarshalIndent(sr, "", "\t")
	if err != nil {
		panic(err)
	}
	return string(xml)
}

func main() {
	data := `
        <?xml version="1.0" encoding="UTF-8"?>
        <RUN_SET xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <RUN alias="150949" center_name="WUGSC" run_date="2011-10-18T02:37:00Z" run_center="WUGSC" accession="SRR648183">
            <IDENTIFIERS>
              <PRIMARY_ID>SRR648183</PRIMARY_ID>
              <SECONDARY_ID>SRZ031726</SECONDARY_ID>
              <SUBMITTER_ID namespace="WUGSC">150949</SUBMITTER_ID>
            </IDENTIFIERS>
            <EXPERIMENT_REF accession="SRX216593" refname="150935" refcenter="WUGSC">
              <IDENTIFIERS>
                <PRIMARY_ID>SRX216593</PRIMARY_ID>
                <SUBMITTER_ID namespace="WUGSC">150935</SUBMITTER_ID>
              </IDENTIFIERS>
            </EXPERIMENT_REF>
            <DATA_BLOCK>
              <FILES>
                <FILE filename="116008179.bam" filetype="bam" checksum="92651eb2a910f69d9b7e5aaeab06f278" checksum_method="MD5"/>
              </FILES>
            </DATA_BLOCK>
            <RUN_ATTRIBUTES>
              <RUN_ATTRIBUTE>
                <TAG>assembly</TAG>
                <VALUE>GRCh37-lite</VALUE>
              </RUN_ATTRIBUTE>
            </RUN_ATTRIBUTES>
          </RUN>
        </RUN_SET>
    `

	var sr SraRun
	xml.Unmarshal([]byte(data), &sr)

	// Changing an attribute
	runs := sr.TxsdRunSet.Runs
	runs[0].Title = "The Most Awesome Run Ever"

	fmt.Printf("%v\n", sr)
}

The above example used a custom struct called SraRun. It specifies two things:

  1. the XML name of the root element in your XML file, as is typical when working with encoding/xml.Unmarshal().
  2. type from the auto-generated package to embed right inside your custom struct.

The second part is the only tricky part. XML Schema Definition has no real concept of "root element", partly because they're designed to support use-cases where you embed a full document defined in one XSD deep inside a full document defined in another XSD. See go-xsd for more details.

Notice that the the re-rendered XML maybe ordered differently than the original XML. This is because the mapping between XML elements and data structures is inherently flawed: an XML element is an order-dependent collection of anonymous values, while a data structure is an order-independent collection of named values.

See the examples subdirectory for more SRA package use cases.

Updating the Autogenerated Code

New defintions and enumeration types get periodically added to the SRA XML schema. If you'd like to re-autogenerate the Go code try the following:

Assuming you've properly setup your GOPATH and GOROOT environment variables, go to $GOPATH/src/github.com/indraniel/go-sra-schemas-1.5 and do

$ make prepare
$ make
$ make tidy

Please note that that go-xsd's xsd-makepkg command declares the autogenerated structs in a different order each time you run it. This will yield a different ordered re-rendered XML.

Directories

Path Synopsis
Godeps
_workspace/src/github.com/go-forks/fsnotify
Package fsnotify implements file system notification.
Package fsnotify implements file system notification.
_workspace/src/github.com/go-utils/ufs
Go programming helpers for common file-system needs.
Go programming helpers for common file-system needs.
_workspace/src/github.com/go-utils/ugo
Go programming helpers for common miscellaneous needs.
Go programming helpers for common miscellaneous needs.
_workspace/src/github.com/go-utils/unet
Go programming helpers for common networking needs.
Go programming helpers for common networking needs.
_workspace/src/github.com/go-utils/uslice
Go programming helpers for common 'pseudo-generic' typed-slice needs.
Go programming helpers for common 'pseudo-generic' typed-slice needs.
_workspace/src/github.com/go-utils/ustr
Go programming helpers for common string-processing needs.
Go programming helpers for common string-processing needs.
_workspace/src/github.com/metaleap/go-xsd/types
A tiny package imported by all "go-xsd"-generated packages.
A tiny package imported by all "go-xsd"-generated packages.
_workspace/src/github.com/metaleap/go-xsd/xsd-makepkg/tests
A simple test function shared by the various test programs inside this directory (rss, atom, collada, svg etc.)
A simple test function shared by the various test programs inside this directory (rss, atom, collada, svg etc.)
Auto-generated by the "go-xsd" package located at: github.com/metaleap/go-xsd Comments on types and fields (if any) are from the XSD file located at: SRA.analysis.xsd
Auto-generated by the "go-xsd" package located at: github.com/metaleap/go-xsd Comments on types and fields (if any) are from the XSD file located at: SRA.analysis.xsd
Auto-generated by the "go-xsd" package located at: github.com/metaleap/go-xsd Comments on types and fields (if any) are from the XSD file located at: SRA.common.xsd
Auto-generated by the "go-xsd" package located at: github.com/metaleap/go-xsd Comments on types and fields (if any) are from the XSD file located at: SRA.common.xsd
Auto-generated by the "go-xsd" package located at: github.com/metaleap/go-xsd Comments on types and fields (if any) are from the XSD file located at: SRA.experiment.xsd
Auto-generated by the "go-xsd" package located at: github.com/metaleap/go-xsd Comments on types and fields (if any) are from the XSD file located at: SRA.experiment.xsd
Auto-generated by the "go-xsd" package located at: github.com/metaleap/go-xsd Comments on types and fields (if any) are from the XSD file located at: SRA.run.xsd
Auto-generated by the "go-xsd" package located at: github.com/metaleap/go-xsd Comments on types and fields (if any) are from the XSD file located at: SRA.run.xsd
Auto-generated by the "go-xsd" package located at: github.com/metaleap/go-xsd Comments on types and fields (if any) are from the XSD file located at: SRA.sample.xsd
Auto-generated by the "go-xsd" package located at: github.com/metaleap/go-xsd Comments on types and fields (if any) are from the XSD file located at: SRA.sample.xsd
Auto-generated by the "go-xsd" package located at: github.com/metaleap/go-xsd Comments on types and fields (if any) are from the XSD file located at: SRA.study.xsd
Auto-generated by the "go-xsd" package located at: github.com/metaleap/go-xsd Comments on types and fields (if any) are from the XSD file located at: SRA.study.xsd
Auto-generated by the "go-xsd" package located at: github.com/metaleap/go-xsd Comments on types and fields (if any) are from the XSD file located at: SRA.submission.xsd
Auto-generated by the "go-xsd" package located at: github.com/metaleap/go-xsd Comments on types and fields (if any) are from the XSD file located at: SRA.submission.xsd

Jump to

Keyboard shortcuts

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