+class ElandMatches(collections.MutableMapping):
+ def __init__(self, eland_container):
+ # the order in patterns determines the preference for what
+ # will be found.
+ self.eland_container = eland_container
+ MAPPED = eland_container.update_result_with_eland
+ SEQUENCE = eland_container.update_result_with_sequence
+
+ sample = '(?P<sample>[^_]+)'
+ hiIndex = '_(?P<index>(NoIndex|[AGCT])+)'
+ hiLane = '_L(?P<lane>[\d]+)'
+ gaLane = '_(?P<lane>[\d]+)'
+ hiRead = '_R(?P<read>[\d]+)'
+ gaRead = '(_(?P<read>[\d])+)?'
+ part = '_(?P<part>[\d]+)'
+ ext = '(?P<extention>(\.bz2|\.gz)?)'
+
+ hiPrefix = sample + hiIndex + hiLane + hiRead + part
+ gaPrefix = sample + gaLane + gaRead
+ P = collections.namedtuple('Patterns', 'pattern counter priority')
+ self.patterns = [
+ P(hiPrefix +'_export.txt' + ext, MAPPED, 6),
+ P(gaPrefix + '_eland_result.txt' + ext, MAPPED, 5),
+ P(gaPrefix + '_eland_extended.txt' + ext, MAPPED, 4),
+ P(gaPrefix + '_eland_multi.txt' + ext, MAPPED, 3),
+ P(gaPrefix + '_export.txt' + ext, MAPPED, 2),
+ P(gaPrefix + '_sequence.txt' + ext, SEQUENCE, 1),
+ ]
+ self.file_sets = {}
+ self.file_priority = {}
+ self.file_counter = {}
+
+ def add(self, pathname):
+ """Add pathname to our set of files
+ """
+ path, filename = os.path.split(pathname)
+
+ for pattern, counter, priority in self.patterns:
+ rematch = re.match(pattern, filename)
+ if rematch is not None:
+ m = ElandMatch(pathname, counter, **rematch.groupdict())
+ key = m.make_samplekey()
+ old_priority = self.file_priority.get(key, 0)
+ if priority > old_priority:
+ self.file_sets[key] = set((m,))
+ self.file_counter[key] = counter
+ self.file_priority[key] = priority
+ elif priority == old_priority:
+ self.file_sets[key].add(m)
+
+ def count(self, key, gerald=None, genome_maps=None):
+ #previous sig: gerald, e.results, lane_id, end, pathnames, genome_maps
+ counter = self.file_counter[key]
+ file_set = self.file_sets[key]
+ filenames = [ f.filename for f in file_set ]
+ return counter(gerald, key,
+ filenames, genome_maps)
+
+ def __iter__(self):
+ return iter(self.file_sets)