Mercurial > repos > yating-l > jbrowsearchivecreator
comparison trackObject.py @ 0:8d1cf7ce65cd draft
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
| author | yating-l |
|---|---|
| date | Thu, 18 May 2017 17:25:33 -0400 |
| parents | |
| children | b5d7748d1b7b |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:8d1cf7ce65cd |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 import os | |
| 4 import shutil | |
| 5 import utils | |
| 6 import bedToGff3 | |
| 7 import blastxmlToGff3 | |
| 8 | |
| 9 | |
| 10 class trackObject: | |
| 11 def __init__(self, chrom_size, genome, extra_files_path): | |
| 12 self.chrom_size = chrom_size | |
| 13 outputDirect = os.path.join(extra_files_path, genome) | |
| 14 self.raw_folder = os.path.join(outputDirect, 'raw') | |
| 15 #Store metadata of the tracks | |
| 16 self.tracks = [] | |
| 17 try: | |
| 18 if os.path.exists(self.raw_folder): | |
| 19 if os.path.isdir(self.raw_folder): | |
| 20 shutil.rmtree(self.raw_folder) | |
| 21 else: | |
| 22 os.remove(self.raw_folder) | |
| 23 os.makedirs(self.raw_folder) | |
| 24 except OSError as oserror: | |
| 25 print "Cannot create raw folder error({0}): {1}".format(oserror.errno, oserror.strerror) | |
| 26 | |
| 27 def addToRaw(self, dataFile, dataType): | |
| 28 """ | |
| 29 Convert gff3, BED, blastxml and gtf files into gff3 files | |
| 30 and store converted files in folder 'raw' | |
| 31 """ | |
| 32 false_path = os.path.abspath(dataFile) | |
| 33 fileName = os.path.basename(dataFile) | |
| 34 des_path = os.path.join(self.raw_folder, fileName) | |
| 35 track = {} | |
| 36 if dataType == 'bed' or dataType == 'gff3' or dataType == 'gff3_mrna' or dataType == 'gff3_transcript' or dataType == 'fasta' or dataType == 'bam' or dataType == 'bigwig': | |
| 37 if dataType == 'bam': | |
| 38 # JBrowse will raise error: not a BAM file if the filename hasn't .bam extension | |
| 39 extension = os.path.splitext(fileName)[1] | |
| 40 if extension != '.bam': | |
| 41 fileName = fileName + '.bam' | |
| 42 des_path = os.path.join(self.raw_folder, fileName) | |
| 43 bam_index = utils.createBamIndex(dataFile) | |
| 44 indexname = os.path.basename(bam_index) | |
| 45 des_path_for_index = os.path.join(self.raw_folder, indexname) | |
| 46 shutil.copyfile(bam_index, des_path_for_index) | |
| 47 track['index'] = indexname | |
| 48 | |
| 49 try: | |
| 50 shutil.copyfile(dataFile, des_path) | |
| 51 except shutil.Error as err1: | |
| 52 print "Cannot move file, error({0}: {1})".format(err1.errno, err1.strerror) | |
| 53 except IOError as err2: | |
| 54 print "Cannot move file, error({0}: {1})".format(err2.errno, err2.strerror) | |
| 55 elif dataType == 'bedSimpleRepeats': | |
| 56 bedToGff3.bedToGff3(dataFile, self.chrom_size, 'trfbig', des_path) | |
| 57 elif dataType == 'bedSpliceJunctions': | |
| 58 bedToGff3.bedToGff3(dataFile, self.chrom_size, 'regtools', des_path) | |
| 59 elif dataType == 'blastxml': | |
| 60 blastxmlToGff3.blastxml2gff3(dataFile, des_path) | |
| 61 elif dataType == 'gtf': | |
| 62 utils.gtfToGff3(dataFile, des_path, self.chrom_size) | |
| 63 track['fileName'] = fileName | |
| 64 track['dataType'] = dataType | |
| 65 track['false_path'] = false_path | |
| 66 #self.SetMetadata(track, metaData) | |
| 67 self.tracks.append(track) | |
| 68 | |
| 69 |
