Mercurial > repos > yating-l > jbrowse_hub
annotate trackObject.py @ 22:fcf2865c950c draft
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit e81fecac281f299db00cfc88a068e056b031ae9d-dirty
author | yating-l |
---|---|
date | Tue, 14 Mar 2017 16:23:09 -0400 |
parents | e1f188b43750 |
children | a4a54b925c73 |
rev | line source |
---|---|
0
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
1 #!/usr/bin/env python |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
2 |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
3 import os |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
4 import shutil |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
5 import utils |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
6 import bedToGff3 |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
7 import blastxmlToGff3 |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
8 |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
9 class trackObject: |
5
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
10 def __init__(self, chrom_size, genome, extra_files_path): |
0
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
11 self.chrom_size = chrom_size |
5
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
12 outputDirect = os.path.join(extra_files_path, genome) |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
13 self.raw_folder = os.path.join(outputDirect, 'raw') |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
14 print self.raw_folder |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
15 self.tracks = [] |
0
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
16 try: |
5
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
17 if os.path.exists(self.raw_folder): |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
18 if os.path.isdir(self.raw_folder): |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
19 shutil.rmtree(self.raw_folder) |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
20 else: |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
21 os.remove(self.raw_folder) |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
22 os.makedirs(self.raw_folder) |
0
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
23 except OSError as oserror: |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
24 print "Cannot create raw folder error({0}): {1}".format(oserror.errno, oserror.strerror) |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
25 |
5
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
26 def addToRaw(self, dataFile, dataType): |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
27 ''' |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
28 Convert gff3, BED, blastxml and gtf files into gff3 files |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
29 and store converted files in folder 'raw' |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
30 ''' |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
31 fileName = os.path.basename(dataFile) |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
32 des_path = os.path.join(self.raw_folder, fileName) |
12
e1f188b43750
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
5
diff
changeset
|
33 if dataType == 'gff3_mrna' or dataType == 'gff3_transcript' or dataType == 'fasta' or dataType == 'bam' or dataType == 'bigwig' or dataType == 'bai': |
0
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
34 try: |
5
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
35 shutil.copyfile(dataFile, des_path) |
0
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
36 except shutil.Error as err1: |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
37 print "Cannot move file, error({0}: {1})".format(err1.errno, err1.strerror) |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
38 except IOError as err2: |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
39 print "Cannot move file, error({0}: {1})".format(err2.errno, err2.strerror) |
5
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
40 elif dataType == 'bedSimpleRepeats': |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
41 bedToGff3.bedToGff3(dataFile, self.chrom_size, 'trfbig', des_path) |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
42 elif dataType == 'bedSpliceJunctions': |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
43 bedToGff3.bedToGff3(dataFile, self.chrom_size, 'regtools', des_path) |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
44 elif dataType == 'blastxml': |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
45 blastxmlToGff3.blastxml2gff3(dataFile, des_path) |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
46 elif dataType == 'gtf': |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
47 utils.gtfToGff3(dataFile, des_path, self.chrom_size) |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
48 track = { |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
49 'fileName': fileName, |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
50 'dataType': dataType |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
51 } |
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
52 self.tracks.append(track) |
0
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
53 |
12
e1f188b43750
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
5
diff
changeset
|
54 |
e1f188b43750
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
5
diff
changeset
|
55 |
e1f188b43750
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
5
diff
changeset
|
56 ''' |
e1f188b43750
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
5
diff
changeset
|
57 def checkGff3(self, dataFile, dataType): |
5
e7c80e9b70ae
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
0
diff
changeset
|
58 with open(dataFile, 'r') as f: |
0
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
59 for line in f: |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
60 if not line.startswith('#'): |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
61 seq_type = line.rstrip().split('\t')[2] |
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
62 if seq_type == 'transcript': |
12
e1f188b43750
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
5
diff
changeset
|
63 return 'gff3-transcript' |
0
e4f3f2ed4fa5
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
diff
changeset
|
64 if seq_type == 'mRNA': |
12
e1f188b43750
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
5
diff
changeset
|
65 return 'gff3' |
e1f188b43750
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
yating-l
parents:
5
diff
changeset
|
66 ''' |