-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ce40c8
commit 86e93b9
Showing
20 changed files
with
1,448 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
[submodule "igv.js-reports"] | ||
path = igv.js-reports | ||
url = https://github.com/igvteam/igv.js-reports.git | ||
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
Submodule igv.js-reports
deleted from
35d449
Binary file not shown.
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,7 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Top-level package for igv-reports.""" | ||
|
||
__author__ = """Jim Robinson""" | ||
__email__ = '[email protected]' | ||
__version__ = '0.1.0' |
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 @@ | ||
import pysam | ||
|
||
def get_data(bam_file, region=None): | ||
args = ["-b", "-h", bam_file] | ||
if region: | ||
range_string = region['chr'] + ":" + str(region['start']) + "-" + str(region['end']) | ||
args.append(range_string) | ||
return pysam.view(*args) | ||
|
||
|
||
class BamReader: | ||
|
||
def __init__(self, filename): | ||
|
||
self.filename = filename | ||
|
||
|
||
def slice(self, region = None) : | ||
args = ["-b", "-h", self.filename] | ||
if region: | ||
range_string = region['chr'] + ":" + str(region['start']) + "-" + str(region['end']) | ||
args.append(range_string) | ||
|
||
args2 = [self.filename, range_string] | ||
samview = pysam.view(*args2) | ||
|
||
return pysam.view(*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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import json | ||
|
||
from .feature import parse | ||
|
||
|
||
class BedTable: | ||
|
||
# Always remember the *self* argument | ||
def __init__(self, bed_file): | ||
|
||
self.features = [] | ||
|
||
featureList = parse(bed_file) | ||
unique_id = 1 | ||
for var in featureList: | ||
self.features.append((var, unique_id)) | ||
unique_id += 1 | ||
|
||
def to_JSON(self): | ||
|
||
jsonArray = []; | ||
|
||
for tuple in self.features: | ||
feature = tuple[0] | ||
unique_id = tuple[1] | ||
obj = { | ||
"unique_id": unique_id, | ||
"Chrom": feature.chr, | ||
"Start": feature.start + 1, | ||
"End": feature.end, | ||
"Name": feature.name | ||
} | ||
|
||
jsonArray.append(obj) | ||
|
||
return json.dumps(jsonArray) |
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,56 @@ | ||
|
||
from base64 import b64encode | ||
from gzip import compress | ||
import argparse | ||
from . import utils | ||
from .regions import parse_region | ||
|
||
|
||
#This module exports functions to convert text or binary data to a data URI readable by igv.js. | ||
|
||
def get_data_uri(data): | ||
|
||
""" | ||
Return a data uri for the input, which can be either a string or byte array | ||
""" | ||
|
||
if isinstance(data, str): | ||
data = compress(data.encode()) | ||
mediatype = "data:application/gzip" | ||
else: | ||
if data[0] == 0x1f and data[1] == 0x8b: | ||
mediatype = "data:application/gzip" | ||
else: | ||
mediatype = "data:application:octet-stream" | ||
|
||
enc_str = b64encode(data) | ||
|
||
data_uri = mediatype + ";base64," + str(enc_str)[2:-1] | ||
return data_uri | ||
|
||
|
||
def file_to_data_uri(filename, filetype=None, genomic_range=None): | ||
reader = utils.getreader(filename, filetype) | ||
region = parse_region(genomic_range) if genomic_range else None | ||
data = reader.slice(region) | ||
data_uri = get_data_uri(data) | ||
return data_uri | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("filename", help="name of file to be converted to data uri") | ||
parser.add_argument("-t", "--filetype", help="type of file to be converted to data uri") | ||
parser.add_argument("-r", "--region" , help="genomic region to be converted in the form chr:start-stop") | ||
args = parser.parse_args() | ||
|
||
if args.region: | ||
region = parse_region(args.region) | ||
else: | ||
region = None | ||
|
||
uri = file_to_data_uri(args.filename, args.filetype, region) | ||
print(uri) | ||
|
||
if __name__ == "__main__": | ||
main() |
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 @@ | ||
from . import regions | ||
import pysam | ||
|
||
def get_data(fasta_file,region=None): | ||
|
||
if None == region: | ||
|
||
with open(fasta_file,"r") as f: | ||
|
||
return(f.read()) | ||
|
||
else : | ||
|
||
if isinstance(region,str): | ||
region = regions.parse_region(region) | ||
|
||
chr = region["chr"] | ||
start = region["start"] - 1 | ||
end = region["end"] | ||
|
||
fasta = pysam.FastaFile(fasta_file) | ||
|
||
slice_seq = fasta.fetch(chr, start, end) | ||
|
||
fasta.close() | ||
|
||
return slice_seq | ||
|
Oops, something went wrong.