Skip to content

Commit

Permalink
bugfix in genePred reader
Browse files Browse the repository at this point in the history
  • Loading branch information
preciserobot committed Sep 20, 2016
1 parent 5d0854d commit 233d35f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 28 deletions.
4 changes: 3 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!zippyvenv/bin/python
#!venv/bin/python

'''runs flask development server'''

from zippy import app

Expand Down
6 changes: 3 additions & 3 deletions zippy/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h3>Batch PCR</h3>
<h3>Primer Query</h3>
<form action="/adhoc_design/" method="post" enctype="multipart/form-data">
<span class="pop">BED, VCF, GenePred &nbsp</span><input type="file" name="filePath"><br><br>
or&nbsp<span class="pop">Chromosome:Start-End:[+-] &nbsp</span><input type="text" name="locus"><br><br>
or&nbsp<span class="pop">Chromosome:Start-End:[+-] &nbsp</span><input type="text" name="locus"> and <input type="text" name="gap"><br><br>
<input type="checkbox" name="design" value="True" checked>design &nbsp
<input type="checkbox" name="deep" value="True">deep search &nbsp
<input type="checkbox" name="store" value="True">store<br><br>
Expand All @@ -30,7 +30,7 @@ <h3>Primer Query</h3>
</div>
<div id="left";>
<h3>Primer Pair Query</h3>
<p>Search by primer pair name or date (yyyy-mm-dd)</p>
<p>Name or date (yyyy-mm-dd)</p>
<form action="/specify_searchname/" method="post" enctype="multipart/form-data">
<span class="pop">Search for &nbsp</span><input type="text" name="searchName"><br><br>
<input type="submit" id="revSubmit" value="Search">
Expand All @@ -40,7 +40,7 @@ <h3>Primer Pair Query</h3>
</div>
<div id="right">
<h3>Storage Location</h3>
<p>Upload a batch of primer storage locations as CSV file</p>
<p>Update from CSV file (PrimerName,Box,Well)</p>
<form action="/upload_batch_locations/" method="post" enctype="multipart/form-data">
<span class="pop">CSV file &nbsp</span><input type="file" name="locationsheet"><br><br>
<input type="submit" id="revSubmit" value="Upload">
Expand Down
3 changes: 3 additions & 0 deletions zippy/unittest/data/test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PrimerName,Box,Well
MTRR_3_fwd,10,Z9
MTRR_3_rev,10,A1
33 changes: 12 additions & 21 deletions zippy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,7 @@
app.config['DOWNLOAD_FOLDER'] = 'results'
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
app.config['CONFIG_FILE'] = os.path.join(APP_ROOT, 'zippy.json')
app.secret_key = 'someKey'

# app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
# app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
#
# celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
# celery.conf.update(app.config)
#
# @celery.task(bind=True)
# def query_zippy(uploadFile):
# filename = secure_filename(uploadFile.filename)
# print >> sys.stderr, filename
# uploadFile.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
# print >> sys.stderr, "file saved to ./uploads/%s" % filename
# os.chdir('./app/')
# print >> sys.stderr, subprocess.call(['./zippy.py', 'get', '--outfile', outfile, '../uploads/%s'% filename], shell=False)
# return "running zippy..."

app.secret_key = 'Zippy is the best handpuppet out there'

def allowed_file(filename):
return '.' in filename and \
Expand Down Expand Up @@ -112,7 +95,12 @@ def adhocdesign():
locus = request.form.get('locus')
design = request.form.get('design')
deep = request.form.get('deep')
gap = request.form.get('gap')
store = request.form.get('store')

print >> sys.stderr, 'locus', locus
print >> sys.stderr, 'gap', gap

# if locus:
if re.match('\w{1,2}:\d+-\d+',locus) or (uploadFile and allowed_file(uploadFile.filename)):
# get target
Expand All @@ -129,7 +117,10 @@ def adhocdesign():
config = json.load(conf, object_hook=ascii_encode_dict)
db = PrimerDB(config['database'])
# run Zippy
primerTable, resultList, missedIntervals = zippyPrimerQuery(config, target, design, None, db, store, deep)
primerTable, resultList, missedIntervals = zippyPrimerQuery(config, target, design, None, db, store, deep, gap)

print >> sys.stderr, primerTable

# get missed and render template
missedIntervalNames = []
for interval in missedIntervals:
Expand Down Expand Up @@ -272,8 +263,8 @@ def blacklist_pair(pairname):
def upload_samplesheet():
if request.method == 'POST':
locationsheet = request.files['locationsheet']
if not locationsheet:
flash('No csvfile submitted. Please try again','warning')
if not locationsheet or not locationsheet.filename.endswith('.csv'):
flash('Not a CSV file. Please try again','warning')
else:
filename = secure_filename(locationsheet.filename)
saveloc = os.path.join(app.config['UPLOAD_FOLDER'], filename)
Expand Down
6 changes: 3 additions & 3 deletions zippy/zippy.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def getPrimers(intervals, db, design, config, deep=True, rename=None, compatible
except:
print >> sys.stderr, 'Could not read blacklist cache, check permissions'
print >> sys.stderr, os.getcwd(), config['blacklistcache']
maxTier = len(config['design']['primer3']) if deep else 1 # only search first tier unless deep
maxTier = len(config['design']['primer3']) if deep or compatible else 1 # only search first tier unless deep or compatibility mode
seqhash = lambda x,y: hashlib.sha1(','.join([x,y])).hexdigest() # sequence pair hashing function
# build gap primers and hash valid pairs
if compatible:
Expand Down Expand Up @@ -608,14 +608,14 @@ def readprimerlocations(locationfile):
header = []
updateList = []
with open(locationfile) as csvfile:
readfile = csv.reader(csvfile, delimiter='\t')
readfile = csv.reader(csvfile, delimiter=',')
for line in readfile:
if not header:
header = line
else:
try:
row = dict(zip(header,line))
updateList.append([row['Primer Name'], Location(row['Box'].strip('Bbox'), row['Well'])])
updateList.append([row['PrimerName'], Location(row['Box'].strip('Bbox'), row['Well'])])
except:
raise Exception('InputFormatError')
return updateList
Expand Down
2 changes: 2 additions & 0 deletions zippy/zippylib/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def __init__(self,fh,getgenes=None,interval=None,overlap=None,flank=0,combine=Tr
gene = Interval(f[2],geneStart,geneEnd,f[12],reverse)
# parse exons
for e in zip(f[9].split(','),f[10].split(',')):
if e[1] < geneStart or geneEnd < e[0]:
continue # noncoding
try:
exonStart = int(e[0]) if noncoding else max(geneStart,int(e[0]))
exonEnd = int(e[1]) if noncoding else min(geneEnd,int(e[1]))
Expand Down

0 comments on commit 233d35f

Please sign in to comment.