Skip to content

Commit

Permalink
Add infrastructure for ga2vcf and ga2sam tools
Browse files Browse the repository at this point in the history
Does not close ga4gh#83
  • Loading branch information
dcolligan committed Feb 23, 2015
1 parent c8a87fd commit 52b0662
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ga2sam_dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
Shim for running the ga2sam tool during development
"""
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import ga4gh.cli

if __name__ == "__main__":
ga4gh.cli.ga2sam_main()
11 changes: 11 additions & 0 deletions ga2vcf_dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
Shim for running the ga2vcf tool during development
"""
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import ga4gh.cli

if __name__ == "__main__":
ga4gh.cli.ga2vcf_main()
56 changes: 56 additions & 0 deletions ga4gh/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,68 @@

import time
import argparse
import sys

import ga4gh.frontend as frontend
import ga4gh.client as client
import ga4gh.backend as backend
import ga4gh.protocol as protocol
import ga4gh.datamodel.variants as variants
import ga4gh.converters as converters


##############################################################################
# ga2vcf
##############################################################################


def ga2vcf_main(parser=None):
if parser is None:
parser = argparse.ArgumentParser(
description="GA4GH VCF conversion tool")
addClientGlobalOptions(parser)
subparsers = parser.add_subparsers(title='subcommands',)
addVariantsSearchParser(subparsers)
args = parser.parse_args()
request = protocol.GASearchVariantsRequest()
setCommaSeparatedAttribute(request, args, 'datasetIds')
# TODO add outputFile cli argument
outputFile = sys.stdout
vcfConverter = converters.VcfConverter(request, outputFile)
vcfConverter.convert()


##############################################################################
# ga2sam
##############################################################################


def ga2sam_main(parser=None):

def usingWorkaroundsFor(workaround):
return workaround in workarounds

if parser is None:
parser = argparse.ArgumentParser(
description="GA4GH SAM conversion tool")
addClientGlobalOptions(parser)
subparsers = parser.add_subparsers(title='subcommands',)
addReadsSearchParser(subparsers)
args = parser.parse_args()
workarounds = set(args.workarounds.split(','))
request = protocol.GASearchReadsRequest()
if usingWorkaroundsFor(client.HttpClient.workaroundGoogle):
# google says referenceId not a valid field
request = SearchReadsRunner.GASearchReadsRequestGoogle()
setCommaSeparatedAttribute(request, args, 'readGroupIds')
request.start = args.start
request.end = args.end
request.referenceId = args.referenceId
request.referenceName = args.referenceName
# TODO add outputFile cli argument
outputFile = sys.stdout
samConverter = converters.SamConverter(request, outputFile)
samConverter.convert()


def setCommaSeparatedAttribute(request, args, attr):
Expand Down
40 changes: 40 additions & 0 deletions ga4gh/converters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Provides classes that take protocol requests, send that request to
the server, and write a particular genomics file type with the results.
"""
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals


class AbstractConverter(object):
"""
Abstract base class for converter classes
"""
def __init__(self, request, outputStream):
self._request = request
self._outputStream = outputStream


class SamConverter(AbstractConverter):
"""
Converts a request to a SAM file
"""
def __init__(self, searchReadsRequest, outputStream):
super(SamConverter, self).__init__(
searchReadsRequest, outputStream)

def convert(self):
raise NotImplementedError()


class VcfConverter(AbstractConverter):
"""
Converts a request to a VCF file
"""
def __init__(self, searchVariantsRequest, outputStream):
super(VcfConverter, self).__init__(
searchVariantsRequest, outputStream)

def convert(self):
raise NotImplementedError()
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def parseVersion(moduleFile):
'console_scripts': [
'ga4gh_client=ga4gh.cli:client_main',
'ga4gh_server=ga4gh.cli:server_main',
'ga2vcf=ga4gh.cli:ga2vcf_main',
'ga2sam=ga4gh.cli:ga2sam_main',
]
},
classifiers=[
Expand Down

0 comments on commit 52b0662

Please sign in to comment.