Commit 8effab39 authored by Mathieu Giraud's avatar Mathieu Giraud

repseq_vdj.py, should-vdj-to-tap.py: VDJ_File()

New class VDJ_File() in repseq_vdj.py, responsible for loading and saving .vdj files
parent 8a42fa93
......@@ -236,17 +236,59 @@ def should_results_from_vidjil(program, f_should, f_log):
### VDJ File
class VDJ_File():
'''
Handle .vdj files
These files contain (#, >) couples of V(D)J designations, such as in:
#TRDD2*01 1/AGG/1 TRDD3*01 TRD+
>TRDD2*01 TRDD3*01
'''
def __init__(self):
self.hr = []
def __iter__(self):
return self.hr.__iter__()
def __len__(self):
return len(self.hr)
def write(self, f):
for (header, result) in self.hr:
f.write("#%s\n" % header)
f.write(">%s\n" % result)
f.write("\n")
def parse_from_gen(self, gen):
self.hr = list(gen)
def parse_from_file(self, f):
should = ''
for l in f:
l = l.strip()
if not l:
continue
if l[0] == '#':
should = l[1:]
elif l[0] == '>':
self.hr += [ (should, l[1:]) ]
### Main
if __name__ == '__main__':
vdj = VDJ_File()
if 'mixcr' in sys.argv[1]:
gen = header_mixcr_results(sys.argv[1])
vdj.parse_from_gen(header_mixcr_results(sys.argv[1]))
else:
gen = header_vquest_results(sys.argv[1], sys.argv[2])
vdj.parse_from_gen(header_vquest_results(sys.argv[1], sys.argv[2]))
# output .vdj data
for (header, result) in gen:
print "#%s" % header
print ">%s" % result
print
vdj.write(sys.stdout)
......@@ -65,28 +65,6 @@ global_stats_failed = defaultdict(int)
global_stats_todo = defaultdict(int)
def should_results_from_vdj(f_vdj):
'''
Parses a .vdj file
Yields (#, >) couples of V(D)J designations, such as in:
#TRDD2*01 1/AGG/1 TRDD3*01 TRD+
>TRDD2*01 TRDD3*01
'''
should = ''
for l in open(f_vdj):
l = l.strip()
if not l:
continue
if l[0] == '#':
should = l[1:]
elif l[0] == '>':
yield should, l[1:]
def should_pattern_to_regex(p):
'''
Converts patterns such as the following ones into a Python regex.
......@@ -306,7 +284,10 @@ if __name__ == '__main__':
if '.vdj' in f_should:
f_vdj = f_should
f_tap = f_vdj + TAP_SUFFIX
write_should_results_to_tap(list(should_results_from_vdj(f_vdj)), f_tap)
vdj = repseq_vdj.VDJ_File()
vdj.parse_from_file(open(f_vdj))
write_should_results_to_tap(vdj, f_tap)
continue
should_to_tap_one_file(f_should)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment