Mercurial > repos > yating-l > jbrowse_hub
comparison trackObject.py @ 0:e4f3f2ed4fa5 draft
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
| author | yating-l |
|---|---|
| date | Fri, 10 Mar 2017 13:48:19 -0500 |
| parents | |
| children | e7c80e9b70ae |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:e4f3f2ed4fa5 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 import os | |
| 4 import shutil | |
| 5 import utils | |
| 6 import bedToGff3 | |
| 7 import blastxmlToGff3 | |
| 8 | |
| 9 class trackObject: | |
| 10 def __init__(self, dataFile, dataType, chrom_size): | |
| 11 self.dataFile = dataFile | |
| 12 self.fileName = os.path.basename(dataFile) | |
| 13 self.dataType = dataType | |
| 14 self.chrom_size = chrom_size | |
| 15 try: | |
| 16 if not os.path.exists('raw'): | |
| 17 os.mkdir('raw') | |
| 18 except OSError as oserror: | |
| 19 print "Cannot create raw folder error({0}): {1}".format(oserror.errno, oserror.strerror) | |
| 20 else: | |
| 21 self.raw_folder = 'raw' | |
| 22 | |
| 23 def addToRaw(self): | |
| 24 des_path = os.path.join(self.raw_folder, self.fileName) | |
| 25 if self.dataType == 'gff3' or self.dataType == 'fasta' or self.dataType == 'bam' or self.dataType == 'bigwig' or self.dataType == 'bai': | |
| 26 if self.dataType == 'gff3': | |
| 27 self.checkGff3() | |
| 28 try: | |
| 29 shutil.copyfile(self.dataFile, des_path) | |
| 30 except shutil.Error as err1: | |
| 31 print "Cannot move file, error({0}: {1})".format(err1.errno, err1.strerror) | |
| 32 except IOError as err2: | |
| 33 print "Cannot move file, error({0}: {1})".format(err2.errno, err2.strerror) | |
| 34 elif self.dataType == 'bedSimpleRepeats': | |
| 35 bedToGff3.bedToGff3(self.dataFile, self.chrom_size, 'trfbig', des_path) | |
| 36 elif self.dataType == 'bedSpliceJunctions': | |
| 37 bedToGff3.bedToGff3(self.dataFile, self.chrom_size, 'regtools', des_path) | |
| 38 elif self.dataType == 'blastxml': | |
| 39 blastxmlToGff3.blastxml2gff3(self.dataFile, des_path) | |
| 40 elif self.dataType == 'gtf': | |
| 41 utils.gtfToGff3(self.dataFile, des_path, self.chrom_size) | |
| 42 | |
| 43 def checkGff3(self): | |
| 44 with open(self.dataFile, 'r') as f: | |
| 45 for line in f: | |
| 46 if not line.startswith('#'): | |
| 47 seq_type = line.rstrip().split('\t')[2] | |
| 48 if seq_type == 'transcript': | |
| 49 self.dataType = 'gff3-transcript' | |
| 50 break | |
| 51 if seq_type == 'mRNA': | |
| 52 break |
