-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from standage/add/generators
Script and generators
- Loading branch information
Showing
31 changed files
with
586 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
# | ||
# ----------------------------------------------------------------------------- | ||
# Copyright (C) 2016 Daniel Standage <daniel.standage@gmail.com> | ||
# | ||
# This file is part of tag (http://github.com/standage/tag) and is licensed | ||
# under the BSD 3-clause license: see LICENSE. | ||
# ----------------------------------------------------------------------------- | ||
|
||
from __future__ import print_function | ||
import tag | ||
|
||
|
||
mains = { | ||
'gff3': tag.cli.gff3.main, | ||
'occ': tag.cli.occ.main, | ||
} | ||
|
||
|
||
def main(args): | ||
assert args.cmd in mains | ||
mainmethod = mains[args.cmd] | ||
mainmethod(args) | ||
|
||
|
||
if __name__ == '__main__': | ||
main(tag.cli.parser().parse_args()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python | ||
# | ||
# ----------------------------------------------------------------------------- | ||
# Copyright (C) 2016 Daniel Standage <daniel.standage@gmail.com> | ||
# | ||
# This file is part of tag (http://github.com/standage/tag) and is licensed | ||
# under the BSD 3-clause license: see LICENSE. | ||
# ----------------------------------------------------------------------------- | ||
|
||
import argparse | ||
import sys | ||
import tag | ||
from . import gff3 | ||
from . import occ | ||
|
||
|
||
def parser(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-v', '--version', action='version', | ||
version='tag v{}'.format(tag.__version__)) | ||
parser.add_argument('-l', '--logfile', metavar='FILE', default=sys.stderr, | ||
type=argparse.FileType('w')) | ||
subparsers = parser.add_subparsers(dest='cmd', metavar='cmd', | ||
help='gff3 | occ') | ||
tag.cli.gff3.subparser(subparsers) | ||
tag.cli.occ.subparser(subparsers) | ||
|
||
return parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
# | ||
# ----------------------------------------------------------------------------- | ||
# Copyright (C) 2015 Daniel Standage <daniel.standage@gmail.com> | ||
# | ||
# This file is part of tag (http://github.com/standage/tag) and is licensed | ||
# under the BSD 3-clause license: see LICENSE. | ||
# ----------------------------------------------------------------------------- | ||
|
||
import argparse | ||
import tag | ||
|
||
|
||
def subparser(subparsers): | ||
subparser = subparsers.add_parser('gff3') | ||
subparser.add_argument('-o', '--out', metavar='FILE', | ||
default='/dev/stdout', help='write output to the ' | ||
'specified file; default is terminal (stdout)') | ||
subparser.add_argument('-r', '--relax', action='store_false', default=True, | ||
dest='strict', help='relax parsing stringency') | ||
subparser.add_argument('gff3', help='input file in GFF3 format') | ||
|
||
|
||
def main(args): | ||
reader = tag.reader.GFF3Reader(infilename=args.gff3, strict=args.strict) | ||
writer = tag.writer.GFF3Writer(reader, args.out) | ||
writer.write() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python | ||
# | ||
# ----------------------------------------------------------------------------- | ||
# Copyright (C) 2015 Daniel Standage <daniel.standage@gmail.com> | ||
# | ||
# This file is part of tag (http://github.com/standage/tag) and is licensed | ||
# under the BSD 3-clause license: see LICENSE. | ||
# ----------------------------------------------------------------------------- | ||
|
||
from __future__ import print_function | ||
import argparse | ||
from collections import defaultdict | ||
from intervaltree import IntervalTree | ||
import tag | ||
|
||
|
||
def interval_set_span(intset): | ||
begin = min([x for x, y, z in intset]) | ||
end = max([y for x, y, z in intset]) | ||
feats = set([z for x, y, z in intset]) | ||
return begin, end, feats | ||
|
||
|
||
def subparser(subparsers): | ||
subparser = subparsers.add_parser('occ') | ||
subparser.add_argument('-r', '--relax', action='store_false', default=True, | ||
dest='strict', help='relax parsing stringency') | ||
subparser.add_argument('gff3', help='input file') | ||
subparser.add_argument('type', help='feature type') | ||
|
||
|
||
def main(args): | ||
features = defaultdict(IntervalTree) | ||
reader = tag.reader.GFF3Reader(infilename=args.gff3, strict=args.strict) | ||
for feature in tag.select.features(reader, type=args.type, traverse=True): | ||
features[feature.seqid].addi(feature.start, feature.end, feature) | ||
if feature.is_multi and feature.is_toplevel: | ||
for sib in feature.siblings: | ||
features[sib.seqid].addi(sib.start, sib.end, sib) | ||
|
||
total_occ = 0 | ||
ints_acct_for = defaultdict(IntervalTree) | ||
for seqid in features: | ||
for interval in features[seqid]: | ||
begin, end, feat = interval | ||
if ints_acct_for[seqid][begin:end] != set(): | ||
continue | ||
|
||
feats = set([feat]) | ||
overlapping = features[seqid][begin:end] | ||
testbegin, testend, testfeats = interval_set_span(overlapping) | ||
while set(feats) < testfeats: | ||
begin, end, feats = testbegin, testend, testfeats | ||
overlapping = features[seqid][begin:end] | ||
testbegin, testend, testfeats = interval_set_span(overlapping) | ||
total_occ += end - begin | ||
ints_acct_for[seqid].addi(begin, end, feats) | ||
print(total_occ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.