Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
master_project_JLU2018/bin/3.1_create_gtf/Modules/CrossMapper.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
72 lines (52 sloc)
2.63 KB
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
import urllib.request | |
import os | |
from Modules import CrossMap | |
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): | |
# 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 chain-file | |
if is_dir: | |
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) | |
self.chainfile = self.get_chain_file(org, wd, is_dir) | |
# 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, 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 chain-file for conversion. | |
# Custom chain-files and chain-files for more organism can be specified in this section | |
if org == "hg19": | |
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" ) | |
urllib.request.urlretrieve("http://hgdownload.soe.ucsc.edu/goldenPath/hg38/" | |
"liftOver/hg38ToHg19.over.chain.gz", | |
file_link) | |
return file_link | |
elif org == "mm9": | |
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" ) | |
urllib.request.urlretrieve("http://hgdownload.soe.ucsc.edu/goldenPath/mm10/" | |
"liftOver/mm10ToMm9.over.chain.gz", | |
file_link) | |
return file_link |