-
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 #755 from uclahs-cds/czhu-fix-index
Map GTF to memory
- Loading branch information
Showing
21 changed files
with
844 additions
and
295 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
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,46 @@ | ||
""" GTFIndexMetadata """ | ||
from typing import IO | ||
from moPepGen.version import MetaVersion | ||
|
||
MOPEPGEN_GTF_INDEX_METADATA_PREFIX = '##' | ||
|
||
class GTFIndexMetadata(): | ||
""" Class for GTF index metadata. """ | ||
def __init__(self, source:str=None, version:MetaVersion=None): | ||
""" constructor """ | ||
self.source = source | ||
self.version = version or MetaVersion() | ||
|
||
def write(self, handle:IO): | ||
""" Write metadata to handle. """ | ||
prefix = MOPEPGEN_GTF_INDEX_METADATA_PREFIX | ||
handle.write(f"{prefix}source={self.source}\n") | ||
handle.write(f"{prefix}python={self.version.python}\n") | ||
handle.write(f"{prefix}moPepGen={self.version.mopepgen}\n") | ||
handle.write(f"{prefix}biopython={self.version.biopython}\n") | ||
|
||
@classmethod | ||
def parse(cls, handle:IO): | ||
""" Read metadata from handle """ | ||
pos = handle.tell() | ||
it = handle.readline() | ||
metadata = {} | ||
version = {} | ||
prefix = MOPEPGEN_GTF_INDEX_METADATA_PREFIX | ||
while it and it.startswith(prefix): | ||
key, val = it.lstrip(prefix).rstrip().split('=', 1) | ||
if val == '': | ||
val = None | ||
if key in ('python', 'moPepGen', 'biopython'): | ||
version[key.lower()] = val | ||
else: | ||
metadata[key] = val | ||
|
||
pos = handle.tell() | ||
it = handle.readline() | ||
|
||
handle.seek(pos) | ||
|
||
version = MetaVersion(**version) | ||
|
||
return cls(source=metadata['source'], version=version) |
Oops, something went wrong.