Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Fix #3 Log files and final clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jenzopr committed Jan 27, 2017
1 parent 3cd0162 commit 73e69a9
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions uropa.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
# Configure logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

streamHandle = logging.StreamHandler()
loggerFormat = logging.Formatter('[%(levelname)s] - %(message)s')
streamHandle.setFormatter(loggerFormat)
Expand All @@ -114,20 +114,21 @@
else:
streamHandle.setLevel(logging.WARNING)
logger.addHandler(streamHandle)

if args.log is not None:
logpath = os.path.dirname(args.log)
if not os.path.exists(logpath):
try:
os.makedirs(logpath)
fileHandle = logging.FileHandler(args.log, mode='w')
fileHandle.setLevel(logging.DEBUG)
fileHandle.setFormatter(loggerFormat)
logger.addHandler(fileHandle)
except OSError:
logger.error("Could not create directory for log file {}".format(logpath))
except IOError:
logger.error("Could not create log file {}".format(args.log))
try:
fileHandle = logging.FileHandler(args.log, mode='w')
fileHandle.setLevel(logging.DEBUG)
fileHandle.setFormatter(loggerFormat)
logger.addHandler(fileHandle)
except IOError:
logger.error("Could not create log file {}".format(args.log))

logger.info("Start time: %s", datetime.datetime.now().strftime("%d.%m.%Y %H:%M"))

Expand Down Expand Up @@ -181,7 +182,7 @@
query_features = list(chain.from_iterable([q["feature"] for q in queries]))
feat_not_valid = [f for f in query_features if f not in gtf_feat]
feat_valid = [f for f in query_features if f not in feat_not_valid]

if feat_not_valid:
logger.warning("Invalid features present (found in a query but not in the GTF): %s", ','.join(feat_not_valid))

Expand All @@ -200,7 +201,7 @@
summ_dict["gtf"] = annot_gtf
summ_dict["bed"] = peaks_bed

with open("summary_config.json", "w") as fj:
with open(outdir+"summary_config.json", "w") as fj:
json.dump(summ_dict, fj, indent=4)

distances = reduce(list.__add__, map(lambda q: q["distance"], queries))
Expand All @@ -226,9 +227,9 @@
# Table-columns for All queries
query_attributes_none = list([q["show.attributes"] for q in queries])
query_attributes = [a for a in np.unique(list(chain.from_iterable(query_attributes_none))) if a is not None and a != 'None']

logger.info("Additional attributes included in output: %s", ','.join(query_attributes))

# query included, when there is no hit from tabix
nas_len = len(query_attributes) + 10
NAsList = list(np.repeat("NA", nas_len))
Expand All @@ -253,7 +254,7 @@
"genomic_location",
"feat_ovl_peak",
"peak_ovl_feat"]

header = "\t".join(header_base + query_attributes + ["query"])

outdir_len = len(outdir.split("/"))
Expand Down Expand Up @@ -321,7 +322,7 @@
allhits_partials = glob.glob(outdir + "AllHits_Partial*")
besthits_partials = glob.glob(outdir + "BestHits_Partial*")


ovls.write_final_file(
args.threads,
outdir,
Expand Down Expand Up @@ -441,11 +442,11 @@
logger.warning("Visualized summary output could not be created from %s.", ' '.join(call))
except OSError:
logger.warning("Rscript command not available for summary output.")
if os.path.exists(summary_output):
os.remove("summary_config.json")

# Remove all other un-necessary files :
# Remove all other un-necessary files :
if outputs_ready:
if os.path.exists(outdir+"summary_config.json"):
os.remove(outdir+"summary_config.json")
os.remove(gtf_index) # .gz
os.remove(gtf_index + ".tbi")
if not args.no_comments:
Expand Down

0 comments on commit 73e69a9

Please sign in to comment.