-
Notifications
You must be signed in to change notification settings - Fork 0
Gtf creation #40
Merged
Merged
Gtf creation #40
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c0c36bc
Added more comments and author / mail description
e1db4c2
Added functionality to Fix #19
f3b93f2
Tries to Fix #18
39cdf16
renamed ID field to gene_id in response to: #29
6016c18
added "_" separation in the third gtf-column in response to #29
91c4ed5
Commented every function / method to resolve #29
30838d4
Commented every function / method to resolve #29
a747799
Removed data_files
94794d5
Merge remote-tracking branch 'origin/dev' into gtf_creation
fc9c02c
Added ";" in attributes (last) field -> fix #29
b3223d1
Added Validator -> Fix #32
947cbfb
Added Validator
4f40b11
Changed comments for pullrequest
571cf5f
Changed comments for pullrequest
6cd7e0e
Changed comments for pullrequest
0d9cca0
Changed comments activity categorizer
7f8cc35
Changed comments activity table generator
6150f03
Merge remote-tracking branch 'origin/dev' into gtf_creation
93ceb85
Added gitignore !
e3c0023
removed pycache files
b97841f
Specified statement in GTFGen
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
|
@@ -10,26 +10,49 @@ class CrossMapper: | |
Class to download chain_files for chrossmapping hg38 or mm10 to older assembly versions. | ||
Utilizes CrossMap.py. see wiki for more information. | ||
|
||
@author: Sebastian Beyvers | ||
@contact: sebastian.beyvers@med.uni-giessen.de | ||
|
||
|
||
""" | ||
|
||
def __init__(self, org, wd, out, is_dir): | ||
self.org = org | ||
|
||
# Constructor for CrossMapper class | ||
# input_parameter: org = input organism | ||
# wd = working directory | ||
# out = path to output-file -> Parameter | ||
# is_dir = boolean if wd is data_dir or just working directory | ||
|
||
# Get path to tempfile / outputfile and chainfile | ||
|
||
if is_dir: | ||
self.infile = os.path.join( wd + "/temp/" + org + ".gtf") | ||
self.infile = os.path.join(wd + "/temp/" + org + ".gtf") | ||
else: | ||
self.infile = os.path.join(wd+"/data/temp/"+org+".gtf") | ||
self.outfile = os.path.join(out+"/" + org + "_mapped.gtf") | ||
self.outfile = os.path.join(out) | ||
self.chainfile = self.get_chain_file(org, wd, is_dir) | ||
# Execute Crossmapper for gff/gtf files | ||
|
||
# Execute Crossmap for gff/gtf files | ||
|
||
(mapTree, targetChromSizes, sourceChromSizes) = CrossMap.read_chain_file(self.chainfile) | ||
|
||
# Map results and save output to self.outfile | ||
|
||
CrossMap.crossmap_gff_file(mapTree, self.infile, self.outfile) | ||
|
||
def get_chain_file(self, org, wd, isdir): | ||
def get_chain_file(self, org, wd, is_data_dir): | ||
|
||
# Defines the Chain files for different conversions. | ||
# input_parameter: org = organism | ||
# wd = working directory | ||
# is_data_dir = is wd data_dir or not | ||
|
||
# return_value: Link to Chainfile for conversion. | ||
# Custom chainfiles and chainfiles for more organism can be specified in this section | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chain files |
||
|
||
if org == "hg19": | ||
if isdir: | ||
if is_data_dir: | ||
file_link = os.path.join(wd+"temp/hg38tohg19.over.chain.gz") | ||
else: | ||
file_link = os.path.join(wd + "/data/temp/hg38tohg19.over.chain.gz" ) | ||
|
@@ -39,7 +62,7 @@ def get_chain_file(self, org, wd, isdir): | |
return file_link | ||
|
||
elif org == "mm9": | ||
if isdir: | ||
if is_data_dir: | ||
file_link = os.path.join(wd+"temp/mm10ToMm9.over.chain.gz") | ||
else: | ||
file_link = os.path.join(wd + "/data/temp/hg38tohg19.over.chain.gz" ) | ||
|
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 |
---|---|---|
|
@@ -4,8 +4,22 @@ | |
|
||
class ActivityCategorizer: | ||
|
||
""" | ||
|
||
Class that categorizes activitydata based on json config and binary activitydata (table.bin). | ||
SebastianBeyvers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@author: Sebastian Beyvers | ||
@contact: sebastian.beyvers@med.uni-giessen.de | ||
|
||
""" | ||
|
||
def __init__(self, release, organism, wd, data_dir): | ||
|
||
# Constructor for ActivityCategorizer | ||
# input_parameter: organism = input organism | ||
# release = current used Ensembl release | ||
# wd = working dir (default working directory, data_dir is used if specified) | ||
# data_dir = data directory (this is used as directory if specified) | ||
|
||
# List of all Folders with Activity Tables | ||
|
||
self.folderlist = [] | ||
|
@@ -27,10 +41,19 @@ def __init__(self, release, organism, wd, data_dir): | |
print("Categorization finished !") | ||
|
||
def get_categorization(self): | ||
|
||
# Getter method to return the self.categorization variable | ||
|
||
return self.categorization | ||
|
||
def read_config(self, organism, wd): | ||
|
||
# Method to read the celltypes_organism.json config file | ||
# input_parameter: organism = input organism | ||
# wd = working directory to find the config files. | ||
# return_value: Dictionary with ensembl aliases based on config | ||
# -> Key = type (from config), value = list of ensembl aliases | ||
|
||
c_dict = {} | ||
path_to_config = os.path.join(wd +"/config/celltypes_"+organism+".json") | ||
with open(path_to_config) as input_file: | ||
|
@@ -43,6 +66,13 @@ def read_config(self, organism, wd): | |
|
||
def get_activity_data(self, release, organism, wd, data_dir): | ||
|
||
# Method to read the binary table.bin file and return its content as bytearray | ||
# input_parameter: organism = input organism | ||
# release = current used Ensembl release | ||
# wd = working dir (default working directory, data_dir is used if specified) | ||
# data_dir = data directory (this is used as directory if specified) | ||
# return_value: bytearray with activitystatus | ||
|
||
for folder in self.folderlist: | ||
# Generate path to binary File | ||
if data_dir: | ||
|
@@ -53,6 +83,9 @@ def get_activity_data(self, release, organism, wd, data_dir): | |
self.activity[folder] = bytearray(tables.read()) | ||
|
||
def generate_categorized_activity(self): | ||
|
||
# Categorizes the Activity by config defined categories. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. activity |
||
|
||
category_activity = {} | ||
|
||
for category, aliases in self.c_dict.items(): | ||
|
@@ -80,10 +113,16 @@ def generate_categorized_activity(self): | |
|
||
def activity_comparator(self, aliaslist): | ||
|
||
# Method to determine the resulting activitystatus if the entry contains | ||
# multiple differing activitystatus from aliases | ||
# e.g. if one alias is ACTIVE and one INACTIVE the result will be ACTIVE -> see wiki for more detailed info | ||
# input_parameter: aliaslist = list of aliases for activity_data | ||
# return_value: Array of Activitystatus by category (type in config) | ||
|
||
concatenated_array = bytearray([]) | ||
|
||
length = len(self.activity[aliaslist[0]]) | ||
input_arrays = [self.activity[x] for x in aliaslist] | ||
input_arrays = [self.activity[index] for index in aliaslist] | ||
for x in range(length): | ||
if any(y[x] == 0 for y in input_arrays): | ||
concatenated_array.append(0) | ||
|
@@ -103,4 +142,4 @@ def activity_comparator(self, aliaslist): | |
# e = ActivityCategorizer("../../config/celltypes_human.json", "release-94", "homo_sapiens") | ||
# print(len(e.categorization)) | ||
# for x in e.categorization.values(): | ||
# print(len(x)) | ||
SebastianBeyvers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# print(len(x)) |
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 |
---|---|---|
|
@@ -4,14 +4,26 @@ | |
class ATGenerator: | ||
|
||
""" | ||
Reads saved activity binary files (table.bin) | ||
|
||
Reads gzip files for activitydata and generates a bytearray with activitystatus. | ||
@author: Sebastian Beyvers | ||
@contact: sebastian.beyvers@med.uni-giessen.de | ||
|
||
""" | ||
|
||
def __init__(self, repre): | ||
|
||
# Constructor with parameter representation: List of keywords with a corresponding index | ||
# Only the Index as byte will be appended to a bytearray. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. index |
||
|
||
self.representation = repre | ||
|
||
def read_table(self, file): | ||
|
||
# Reads the activity-ensembl file ("/data/EnsemblData/release/organism/activity/*") | ||
# and returns the activity as bytearray, based on the representation in self.representation. | ||
# Only the index is saved -> see ActivityTable.py for current representation. | ||
|
||
activity_table = [] | ||
with gzip.open(file, 'rb') as f: | ||
for line in f: | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chain file