| 1 |
#!/usr/bin/env python |
| 2 |
# Looking in /usr/local/ir/bin on the Compaqs for the correct Python interpreter. |
| 3 |
# export PYTHONPATH=${PYTHONPATH}:$WORK/cds/IR/COMPASS/src/AtacPipeline |
| 4 |
|
| 5 |
""" |
| 6 |
Extensive documentation for the Python language is available at |
| 7 |
http://www.python.org. |
| 8 |
""" |
| 9 |
|
| 10 |
import os, sys, time, getopt, tempfile |
| 11 |
import MyFile |
| 12 |
import MatchRecord |
| 13 |
|
| 14 |
class AtacFile: |
| 15 |
|
| 16 |
# The data flow is a pipeline augmented by two read-only indexed |
| 17 |
# FASTA files. |
| 18 |
|
| 19 |
def __init__( self, runName): |
| 20 |
"You must supply a atac file called runName.atac." |
| 21 |
self.runName = runName |
| 22 |
self.comments = [] |
| 23 |
self.metacommands = [] |
| 24 |
self.globals = {} |
| 25 |
self.tableformat = {} |
| 26 |
self.tabledata = {} |
| 27 |
self.matches = MyFile.myfile() |
| 28 |
self.runs = MyFile.myfile() |
| 29 |
|
| 30 |
fp = open(runName,"r") |
| 31 |
for line in fp: |
| 32 |
self.atac_file_parse_line(line) |
| 33 |
|
| 34 |
def atac_file_parse_line( self, line): |
| 35 |
line = line.strip() |
| 36 |
if(not line): |
| 37 |
return |
| 38 |
# end if |
| 39 |
linetype = line[0] |
| 40 |
if(linetype == '#'): |
| 41 |
# Just a comment: squirrel away or ignore |
| 42 |
self.comments.append(line) |
| 43 |
return |
| 44 |
elif(linetype == '!'): |
| 45 |
self.metacommands.append(line) |
| 46 |
return |
| 47 |
elif(linetype == '/'): |
| 48 |
# Add to the globals dictionary |
| 49 |
(key,value) = line[1:].split('=') |
| 50 |
self.globals[key] = value.strip() |
| 51 |
return |
| 52 |
elif(linetype == '@'): |
| 53 |
list = line[1:].split() |
| 54 |
name = list[0] |
| 55 |
self.tableformat[name] = list[1:] |
| 56 |
self.tabledata[name] = [] # an empty list |
| 57 |
return |
| 58 |
elif(linetype == 'M'): |
| 59 |
fields = line.split() |
| 60 |
if(fields[1] == 'r'): |
| 61 |
print >>self.runs, line |
| 62 |
else: |
| 63 |
print >>self.matches, line |
| 64 |
return |
| 65 |
elif(line == ''): |
| 66 |
pass |
| 67 |
else: |
| 68 |
print >>sys.stderr, "The offending line:" |
| 69 |
print >>sys.stderr, line |
| 70 |
assert(0) |
| 71 |
# end if |
| 72 |
# end def |
| 73 |
|
| 74 |
def checkpoint(self, filename): |
| 75 |
self.globals["modificationDate"] = time.asctime() |
| 76 |
fp = open(filename,"w") |
| 77 |
for line in self.metacommands: |
| 78 |
print >>fp, line |
| 79 |
for line in self.comments: |
| 80 |
print >>fp, line |
| 81 |
# Output the globals in lexigraphical order. |
| 82 |
list = [] |
| 83 |
for key in self.globals: |
| 84 |
list.append("/" + key + "=" + str(self.globals[key])) |
| 85 |
list.sort() |
| 86 |
for line in list: |
| 87 |
print >>fp, line |
| 88 |
self.matches.seek(0) |
| 89 |
for line in self.matches: |
| 90 |
fp.write(line) |
| 91 |
self.matches.seek(0) |
| 92 |
self.runs.seek(0) |
| 93 |
for line in self.runs: |
| 94 |
fp.write(line) |
| 95 |
self.runs.seek(0) |
| 96 |
fp.close() |