Mercurial > repos > yufei-luo > s_mart
comparison commons/core/parsing/ElandParser.py @ 36:44d5973c188c
Uploaded
author | m-zytnicki |
---|---|
date | Tue, 30 Apr 2013 15:02:29 -0400 |
parents | 769e306b7933 |
children |
comparison
equal
deleted
inserted
replaced
35:d94018ca4ada | 36:44d5973c188c |
---|---|
1 # | |
2 # Copyright INRA-URGI 2009-2010 | |
3 # | |
4 # This software is governed by the CeCILL license under French law and | |
5 # abiding by the rules of distribution of free software. You can use, | |
6 # modify and/ or redistribute the software under the terms of the CeCILL | |
7 # license as circulated by CEA, CNRS and INRIA at the following URL | |
8 # "http://www.cecill.info". | |
9 # | |
10 # As a counterpart to the access to the source code and rights to copy, | |
11 # modify and redistribute granted by the license, users are provided only | |
12 # with a limited warranty and the software's author, the holder of the | |
13 # economic rights, and the successive licensors have only limited | |
14 # liability. | |
15 # | |
16 # In this respect, the user's attention is drawn to the risks associated | |
17 # with loading, using, modifying and/or developing or reproducing the | |
18 # software by the user in light of its specific status of free software, | |
19 # that may mean that it is complicated to manipulate, and that also | |
20 # therefore means that it is reserved for developers and experienced | |
21 # professionals having in-depth computer knowledge. Users are therefore | |
22 # encouraged to load and test the software's suitability as regards their | |
23 # requirements in conditions enabling the security of their systems and/or | |
24 # data to be ensured and, more generally, to use and operate it in the | |
25 # same conditions as regards security. | |
26 # | |
27 # The fact that you are presently reading this means that you have had | |
28 # knowledge of the CeCILL license and that you accept its terms. | |
29 # | |
30 import sys | |
31 from commons.core.parsing.MapperParser import MapperParser | |
32 from SMART.Java.Python.structure import Mapping | |
33 | |
34 class ElandParser(MapperParser): | |
35 """A class that parses ELAND format""" | |
36 | |
37 def __init__(self, fileName, verbosity = 0): | |
38 super(ElandParser, self).__init__(fileName, verbosity) | |
39 | |
40 | |
41 def __del__(self): | |
42 super(ElandParser, self).__del__() | |
43 | |
44 | |
45 def getFileFormats(): | |
46 return ["eland"] | |
47 getFileFormats = staticmethod(getFileFormats) | |
48 | |
49 | |
50 def skipFirstLines(self): | |
51 pass | |
52 | |
53 | |
54 def getInfos(self): | |
55 super(ElandParser, self).getInfos() | |
56 | |
57 | |
58 def parseLine(self, line): | |
59 | |
60 line = line.strip() | |
61 | |
62 fields = line.split("\t") | |
63 if len(fields) < 22: | |
64 sys.exit("Line %d '%s' does not look like a ELAND line (number of fields is %d instead of 22)" % (self.currentLineNb, line, len(fields))) | |
65 | |
66 flowCell = fields[0] | |
67 run = fields[1] | |
68 lane = fields[2] | |
69 tile = fields[3] | |
70 xcoord = fields[4] | |
71 ycoord = fields[5] | |
72 index = fields[6] | |
73 number = fields[7] | |
74 read = fields[8] | |
75 quality = fields[9] | |
76 chromosome = fields[10] | |
77 contig = fields[11] | |
78 position = fields[12] | |
79 strand = fields[13] | |
80 description = fields[14] | |
81 singleScore = fields[15] | |
82 pairScore = fields[16] | |
83 partnerChromosome = fields[17] | |
84 partnerContig = fields[18] | |
85 partnerOffset = fields[19] | |
86 partnerStrand = fields[20] | |
87 filtering = fields[21] | |
88 | |
89 if number != "1": | |
90 sys.exit("S-MART cannot handle pair-end reads yet!") | |
91 | |
92 # nothing found | |
93 if position == "": | |
94 return None | |
95 | |
96 name = "%s_%s:%s:%s:%s:%s#0/1" % (flowCell, run, lane, tile, xcoord, ycoord) | |
97 direction = 1 if strand == "F" else -1 | |
98 nbMismatches = 0 | |
99 for char in description: | |
100 if ord("A") <= ord(char) and ord(char) <= ord("Z"): | |
101 nbMismatches += 1 | |
102 | |
103 mapping = Mapping() | |
104 mapping.setTagValue("qualityString", quality) | |
105 | |
106 mapping.queryInterval.setName(name) | |
107 mapping.queryInterval.setDirection(direction) | |
108 mapping.queryInterval.setStart(1) | |
109 mapping.queryInterval.setEnd(len(read)) | |
110 | |
111 mapping.targetInterval.setChromosome(chromosome) | |
112 mapping.targetInterval.setStart(int(position)) | |
113 mapping.targetInterval.setEnd(int(position) + len(read)) | |
114 mapping.targetInterval.setDirection(1) | |
115 | |
116 mapping.setSize(len(read)) | |
117 mapping.setDirection(direction) | |
118 | |
119 mapping.setNbGaps(0) | |
120 mapping.setNbMismatches(nbMismatches) | |
121 mapping.setTagValue("score", int(singleScore)) | |
122 | |
123 if filtering == "Y": | |
124 return mapping | |
125 # mapping filtered out | |
126 return None |