Commit c239bba8 authored by Adam Caprez's avatar Adam Caprez
Browse files

Add quiet option for download and import scripts.

parent 0f462add
......@@ -12,6 +12,7 @@ import datetime
parser = argparse.ArgumentParser(description="Download raw JSON for all experiments.")
parser.add_argument("-o", "--output-dir", dest="outputdir", default=os.getcwd(), help="Output directory. (default: %(default)s)")
parser.add_argument("-q", "--quiet", action='store_true', help="Quiet mode. Do not print progress information. (default: false)")
args = parser.parse_args()
encode_baseurl = "https://www.encodeproject.org/experiments/"
......@@ -39,7 +40,8 @@ for i, exp_id in enumerate(exp_ids):
r = requests.get(exp_url, params=json_arg)
with open(os.path.join(args.outputdir, "data", "%s.json" % (exp_id,)), "w") as wh:
wh.write(r.text)
progress(i, total)
progress(total, total)
if not args.quiet:
progress(i, total)
if not args.quiet:
progress(total, total)
print
......@@ -15,6 +15,7 @@ parser.add_argument("-p", "--password", dest="password", help="Database password
parser.add_argument("-i", "--input-dir", dest="inputdir", default=os.getcwd(), help="Directory containing per-experiment JSON files. (default: %(default)s)")
parser.add_argument("-d", "--drop", dest="drop", default=False, action="store_true", help="Drop data if it exists. (default: %(default)s)")
parser.add_argument("-s", "--samples", dest="samples", default=False, action="store_true", help="Only recreate the samples collection.")
parser.add_argument("-q", "--quiet", action='store_true', help="Quiet mode. Do not print progress information. (default: false)")
args = parser.parse_args()
......@@ -31,8 +32,8 @@ if args.drop:
if not args.samples:
# Insert all experiment JSON files into DB
json_filelist = os.listdir(args.inputdir)
print "Creating experiments collection..."
if not args.quiet:
print "Creating experiments collection..."
for i, json_file in enumerate(json_filelist):
if json_file.endswith("json"):
exp_file_contents = open(os.path.join(args.inputdir, json_file)).read()
......@@ -44,7 +45,8 @@ if not args.samples:
db.experiments.insert_one(exp_json_data)
except Exception:
pass
progress(i, len(json_filelist))
if not args.quiet:
progress(i, len(json_filelist))
organism = {
"mm": "mouse",
......@@ -61,7 +63,8 @@ cursor = db.experiments.find({
total = cursor.count()
# Create the samples collection using the 'files' value from each experiment
print "\nCreating samples collection..."
if not args.quiet:
print "\nCreating samples collection..."
for i, document in enumerate(cursor):
for f in document["files"]:
doc = {}
......@@ -87,7 +90,8 @@ for i, document in enumerate(cursor):
db.samples.update_one({'_id': result.inserted_id}, {"$set": f})
except Exception:
pass
progress(i, total)
if not args.quiet:
progress(i, total)
print
cursor.close()
Supports Markdown
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