Skip to content
Permalink
b97841f5cd
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
72 lines (52 sloc) 2.63 KB
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