Skip to content

Commit

Permalink
skip stop script execution when encountering invalid input
Browse files Browse the repository at this point in the history
  • Loading branch information
zwdzwd committed Feb 24, 2016
1 parent 7f6df70 commit 7c3a2ff
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bin/transvar
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from transvar.localdb import add_parser_index
if __name__ == '__main__':

import sys
if sys.argv[1] in ['-version', '--version']:
if len([a for a in sys.argv if a in ['-version', '--version']]) > 0:
import transvar
sys.stderr.write("TransVar Version %s\n" % transvar.__version__)
sys.exit(1)
Expand Down
104 changes: 75 additions & 29 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,47 +43,93 @@ def wrap(line):
yield ' '*3+line[:k]
line = line[k:]

fh = open(sys.argv[2], 'w') # open('README.md.temp', 'w')
indir = sys.argv[1]
outdir = sys.argv[2]

if not os.path.exists(outdir):
os.mkdir(outdir)
# outdir = open(sys.argv[2], 'w') # open('README.md.temp', 'w')

import transvar

result = ''
for line in open(sys.argv[1]):
for ifn in os.listdir(indir):
if not ifn.endswith(".md"):
continue

line = line.replace('@VERSION', transvar.__version__)
ifh = open(os.path.join(indir, ifn))

if line.startswith('$'): # exexcute sentinel
ofn = os.path.join(outdir, ifn)
ofh = open(ofn, "w")

fh.write(line)
line = line[2:].strip()
ar = re.split(r'[\'"]', line.strip())
result = ''
tofill = False
infill = False
for line in ifh:

B = []
for i, e in enumerate(ar):
if i % 2 == 0:
if len(e.strip())>0:
B.extend(e.strip().split())
else:
B.append(e.strip())
line = line.replace('@VERSION', transvar.__version__)

if line.startswith('$'): # exexcute sentinel

ofh.write(line)
line = line[2:].strip()
ar = re.split(r'[\'"]', line.strip())

B = []
for i, e in enumerate(ar):
if i % 2 == 0:
if len(e.strip())>0:
B.extend(e.strip().split())
else:
B.append(e.strip())

p = Popen(B, stdin=PIPE, stdout=PIPE, stderr=PIPE)
result, err = p.communicate()
result = result.strip()

p = Popen(B, stdin=PIPE, stdout=PIPE, stderr=PIPE)
result, err = p.communicate()
result = result.strip()
print
print '======'+line+'======'
print result
print '\n'.join([rr for rr in result.split('\n') if not (len(rr.strip()) == 0 or rr.startswith('[') or rr.startswith('input'))])
tofill = True
infill = False
oldfill = ''

print
print '======'+line+'======'
print '\n'.join([rr for rr in result.split('\n') if not (len(rr.strip()) == 0 or rr.startswith('[') or rr.startswith('input'))])
elif line.startswith('```text') and tofill:
infill = True
tofill = False
ofh.write(line)

elif line.startswith('```') and infill:

newfill = ''
for rr in result.split('\n'):

if len(rr.strip()) == 0 or rr.startswith('[') or rr.startswith('input'):
continue

for r in wrap(rr):
newfill += r+'\n'

if newfill != oldfill:
print '\n+++ NEW +++'
print newfill
print '\n+++ OLD +++'
print oldfill
raw_input("Difference ...")
else:
print "\nSame!\n"

elif line.startswith('@'):
ofh.write(newfill)
ofh.write('```\n')

for rr in result.split('\n'):
infill = False

if len(rr.strip()) == 0 or rr.startswith('[') or rr.startswith('input'):
continue
elif infill:
oldfill += line

for r in wrap(rr):
fh.write(r+'\n')
else:

else:
ofh.write(line)

fh.write(line)
ifh.close()
ofh.close()
4 changes: 3 additions & 1 deletion transvar/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ def vcf_parse_mutation(args, at='g'):
q.refseq = ref.upper()
q.altseq = alt.upper()
else:
err_raise(InvalidInputError, 'invalid VCF line: %s' % line)
q = Query()
q.msg = "InvalidVCFLine%s" % line
err_warn("Invalid VCF Line: %s" % line)

q.op = line.strip()

Expand Down
2 changes: 2 additions & 0 deletions transvar/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ def __init__(self):
self.is_codon = True
self.gn_name = None
self.tpt = ''
self.msg = ''
self.tok = None # by default, is a failed query

def set_pos(self, pos_str):

Expand Down

0 comments on commit 7c3a2ff

Please sign in to comment.