annotate Gtf.py @ 27:cdd33c5c8ac1 draft

planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 05fc99e5a081e3f2a0f152ad952ba60c50661229
author yating-l
date Mon, 10 Jul 2017 12:28:50 -0400
parents df42241d3731
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
1 #!/usr/bin/python
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
2
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
3 import os
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
4 import tempfile
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
5
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
6 # Internal dependencies
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
7 from Datatype import Datatype
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
8 from util import subtools
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
9
19
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
10 class InfoModifiedGtf():
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
11 def __init__(self, is_modified=False, array_modified_lines=[]):
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
12 self.is_modified = is_modified
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
13 self.array_modified_lines = array_modified_lines
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
14
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
15 def get_str_modified_lines(self):
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
16 return ','.join(map(str, self.array_modified_lines))
1
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
17
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
18 class Gtf( Datatype ):
10
acc233161f50 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1b1063f90004764bcf504f4340738eca5c4b1f9d
rmarenco
parents: 1
diff changeset
19 def __init__( self, input_gtf_false_path, data_gtf):
acc233161f50 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1b1063f90004764bcf504f4340738eca5c4b1f9d
rmarenco
parents: 1
diff changeset
20
acc233161f50 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1b1063f90004764bcf504f4340738eca5c4b1f9d
rmarenco
parents: 1
diff changeset
21 super(Gtf, self).__init__()
1
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
22
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
23 self.track = None
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
24
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
25 self.input_gtf_false_path = input_gtf_false_path
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
26 self.name_gtf = data_gtf["name"]
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
27 self.priority = data_gtf["order_index"]
16
3233451a3bd6 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit fc73ec22a0db3ab09c4ac13dc58f0b54ae37845c
rmarenco
parents: 13
diff changeset
28 self.track_color = data_gtf["track_color"]
17
c02720d1afee planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1adbf397de1fc7af4d91e026093d7fff983e21cf
rmarenco
parents: 16
diff changeset
29 # TODO: Think about how to avoid repetition of the group_name everywhere
c02720d1afee planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1adbf397de1fc7af4d91e026093d7fff983e21cf
rmarenco
parents: 16
diff changeset
30 self.group_name = data_gtf["group_name"]
26
df42241d3731 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit c11beb58525fe6453a2180fe7783f6e8b0151901-dirty
yating-l
parents: 23
diff changeset
31 self.database = data_gtf["database"]
23
2677f1899aa8 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 07210e24fe7d22f5dfc84061310280f67f781fb1-dirty
yating-l
parents: 19
diff changeset
32 if data_gtf["long_label"]:
2677f1899aa8 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 07210e24fe7d22f5dfc84061310280f67f781fb1-dirty
yating-l
parents: 19
diff changeset
33 self.long_label = data_gtf["long_label"]
2677f1899aa8 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 07210e24fe7d22f5dfc84061310280f67f781fb1-dirty
yating-l
parents: 19
diff changeset
34 else:
2677f1899aa8 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 07210e24fe7d22f5dfc84061310280f67f781fb1-dirty
yating-l
parents: 19
diff changeset
35 self.long_label = self.name_gtf
11
d05236b15f81 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents: 10
diff changeset
36 #print "Creating TrackHub GTF from (falsePath: %s; name: %s)" % ( self.input_gtf_false_path, self.name_gtf)
1
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
37
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
38 # TODO: See if we need these temporary files as part of the generated files
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
39 genePredFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".genePred")
13
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
40 unsorted_bigGenePred_file = tempfile.NamedTemporaryFile(bufsize=0, suffix=".unsorted.bigGenePred")
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
41 sorted_bigGenePred_file = tempfile.NamedTemporaryFile(suffix=".sortedBed.bigGenePred")
1
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
42
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
43 # GtfToGenePred
19
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
44 ## Checking the integrity of the inputs
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
45 modified_gtf = self._checkAndFixGtf()
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
46
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
47 ## Processing the gtf
1
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
48 subtools.gtfToGenePred(self.input_gtf_false_path, genePredFile.name)
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
49
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
50 # TODO: From there, refactor because common use with Gff3.py
13
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
51 # genePredToBigGenePred processing
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
52 subtools.genePredToBigGenePred(genePredFile.name, unsorted_bigGenePred_file.name)
1
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
53
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
54 # Sort processing
13
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
55 subtools.sort(unsorted_bigGenePred_file.name, sorted_bigGenePred_file.name)
1
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
56
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
57 # bedToBigBed processing
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
58 trackName = "".join( ( self.name_gtf, ".bb") )
13
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
59
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
60 auto_sql_option = os.path.join(self.tool_directory, 'bigGenePred.as')
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
61
1
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
62 myBigBedFilePath = os.path.join(self.myTrackFolderPath, trackName)
13
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
63
1
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
64 with open(myBigBedFilePath, 'w') as bigBedFile:
13
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
65 subtools.bedToBigBed(sorted_bigGenePred_file.name,
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
66 self.chromSizesFile.name,
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
67 bigBedFile.name,
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
68 autoSql=auto_sql_option,
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
69 typeOption='bed12+8',
26
df42241d3731 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit c11beb58525fe6453a2180fe7783f6e8b0151901-dirty
yating-l
parents: 23
diff changeset
70 tab=True,
df42241d3731 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit c11beb58525fe6453a2180fe7783f6e8b0151901-dirty
yating-l
parents: 23
diff changeset
71 extraIndex='name')
13
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
72
1
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
73
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
74 # Create the Track Object
11
d05236b15f81 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents: 10
diff changeset
75 self.createTrack(file_path=trackName,
d05236b15f81 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents: 10
diff changeset
76 track_name=trackName,
23
2677f1899aa8 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 07210e24fe7d22f5dfc84061310280f67f781fb1-dirty
yating-l
parents: 19
diff changeset
77 long_label=self.long_label, track_type='bigGenePred',
13
25809f699cb3 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
rmarenco
parents: 11
diff changeset
78 visibility='dense', priority=self.priority,
16
3233451a3bd6 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit fc73ec22a0db3ab09c4ac13dc58f0b54ae37845c
rmarenco
parents: 13
diff changeset
79 track_file=myBigBedFilePath,
17
c02720d1afee planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1adbf397de1fc7af4d91e026093d7fff983e21cf
rmarenco
parents: 16
diff changeset
80 track_color=self.track_color,
26
df42241d3731 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit c11beb58525fe6453a2180fe7783f6e8b0151901-dirty
yating-l
parents: 23
diff changeset
81 group_name=self.group_name,
df42241d3731 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit c11beb58525fe6453a2180fe7783f6e8b0151901-dirty
yating-l
parents: 23
diff changeset
82 database=self.database)
1
fb5e60d4d18a planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff changeset
83
19
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
84 # TODO: Use Logging instead of print
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
85 if modified_gtf.is_modified:
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
86 print("- Warning: Gtf %s created with a modified version of your Gtf because of start/end coordinates issues."
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
87 % self.name_gtf)
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
88 print("Here are the lines removed: " + modified_gtf.get_str_modified_lines())
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
89 else:
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
90 print("- Gtf %s created" % self.name_gtf)
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
91
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
92 def _checkAndFixGtf(self):
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
93 """
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
94 Call _checkAndFixGtf, check the integrity of gtf file,
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
95 if coordinates exceed chromosome size, either removed the whole line(s) or truncated to the end of the scaffold
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
96 depending on the user choice
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
97 default: remove the whole line(s)
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
98 """
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
99 # Set the boolean telling if we had to modify the file
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
100 modified_gtf = InfoModifiedGtf()
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
101
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
102 # Create a temp gtf just in case we have issues
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
103 temp_gtf = tempfile.NamedTemporaryFile(bufsize=0, suffix=".gtf", delete=False)
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
104
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
105 # TODO: Get the user choice and use it
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
106 # TODO: Check if the start > 0 and the end <= chromosome size
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
107 # Get the chrom.sizes into a dictionary to have a faster access
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
108 # TODO: Think about doing this in Datatype.py, so everywhere we have access to this read-only dictionary
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
109 dict_chrom_sizes = {}
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
110 with open(self.chromSizesFile.name, 'r') as chromSizes:
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
111 lines = chromSizes.readlines()
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
112 for line in lines:
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
113 fields = line.split()
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
114 # fields[1] should be the name of the scaffold
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
115 # fields[2] should be the size of the scaffold
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
116 # TODO: Ensure this is true for all lines
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
117 dict_chrom_sizes[fields[0]] = fields[1]
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
118
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
119 # Parse the GTF and check each line using the chrom sizes dictionary
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
120 with open(temp_gtf.name, 'a+') as tmp:
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
121 with open(self.input_gtf_false_path, 'r') as gtf:
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
122 lines = gtf.readlines()
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
123 for index, line in enumerate(lines):
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
124 # If this is not a comment, we check the fields
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
125 if not line.startswith('#'):
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
126 fields = line.split()
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
127 # We are interested in fields[0] => Seqname (scaffold)
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
128 # We are interested in fields[3] => Start of the scaffold
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
129 # We are interested in fields[4] => End of the scaffold
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
130 scaffold_size = dict_chrom_sizes[fields[0]]
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
131 start_position = fields[3]
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
132 end_position = fields[4]
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
133
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
134 if start_position > 0 and end_position <= scaffold_size:
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
135 # We are good, so we copy this line
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
136 tmp.write(line)
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
137 tmp.write(os.linesep)
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
138
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
139
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
140 # The sequence is not good, we are going to process it regarding the user choice
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
141 # TODO: Process the user choice
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
142 # By default, we are assuming the user choice is to remove the lines: We don't copy it
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
143
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
144 # If we are here, it means the gtf has been modified
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
145 else:
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
146 # We save the line for the feedback to the user
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
147 modified_gtf.array_modified_lines.append(index + 1)
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
148
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
149 if modified_gtf.is_modified is False:
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
150 modified_gtf.is_modified = True
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
151 else:
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
152 pass
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
153 else:
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
154 tmp.write(line)
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
155 tmp.write(os.linesep)
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
156
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
157 # Once the process it completed, we just replace the path of the gtf
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
158 self.input_gtf_false_path = temp_gtf.name
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
159
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
160 # TODO: Manage the issue with the fact the dataset is going to still exist on the disk because of delete=False
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
161
0152500d9acd Uploaded
rmarenco
parents: 17
diff changeset
162 return modified_gtf