2 Utility functions to make bedfiles.
6 def make_bed_from_eland_stream(instream, outstream, name, description, chromosome_prefix='chr'):
8 read an eland result file from instream and write a bedfile to outstream
10 # indexes into fields in eland_result.txt file
15 # map eland_result.txt sense
16 sense_map = { 'F': '+', 'R': '-'}
17 sense_color = { 'F': '0,0,255', 'R': '255,255,0' }
18 # provide default track names
19 if name is None: name = "track"
20 if description is None: description = "eland result file"
21 bed_header = 'track name="%s" description="%s" visibility=4 itemRgb="ON"'
22 bed_header += os.linesep
23 outstream.write(bed_header % (name, description))
27 # we need more than the CHR field, and it needs to match a chromosome
28 if len(fields) <= CHR or \
29 (chromosome_prefix is not None and \
30 fields[CHR][:3] != chromosome_prefix):
33 stop = int(start) + len(fields[SEQ])
34 chromosome, extension = fields[CHR].split('.')
35 assert extension == "fa"
36 outstream.write('%s %s %d read 0 %s - - %s%s' % (
40 sense_map[fields[SENSE]],
41 sense_color[fields[SENSE]],
45 def make_description(database, flowcell_id, lane):
47 compute a bedfile name and description from the fctracker database
49 from gaworkflow.util.fctracker import fctracker
51 fc = fctracker(database)
52 cells = fc._get_flowcells("where flowcell_id='%s'" % (flowcell_id))
54 raise RuntimeError("couldn't find flowcell id %s" % (flowcell_id))
56 if lane < 1 or lane > 8:
57 raise RuntimeError("flowcells only have lanes 1-8")
59 name = "%s-%s" % (flowcell_id, lane)
61 cell_id, cell = cells.items()[0]
62 assert cell_id == flowcell_id
64 cell_library_id = cell['lane_%d_library_id' %(lane,)]
65 cell_library = cell['lane_%d_library' %(lane,)]
66 description = "%s-%s" % (cell_library['library_name'], cell_library_id)
67 return name, description