#!/usr/bin/env python ################################### # MERGES VENN DIAGRAM FILES # # THIS IS OPEN SOURCE CODE (YAY!) # ################################### # LICENSE # This code is licensed under the Creative Commons 3.0 # Attribution + ShareAlike license - for details see: # http://creativecommons.org/licenses/by-sa/3.0/ # # DATE: February 27th, 2014 # # PROGRAM AUTHOR (PROGRAMMER) # Graham Alvare - home.cc.umanitoba.ca/~alvare # # CO-AUTHORS/ACKNOWLEDGEMENTS # Justin Zhang - for providing me information on the SAM format, # and test data to build and debug this program. # Dr. Brian Fristensky - my work supervisor, and the man who introduced # me to the wonderful field of bioinformatics. # # QUESTIONS & COMMENTS # If you have any questions, please contact me: alvare@cc.umanitoba.ca # I usually get back to people within 1-2 weekdays (weekends, I am slower) # # P.S. Please also let me know of any bugs, or if you have any suggestions. # I am generally happy to help create new tools, or modify my existing # tools to make them more useful. # # Happy usage! import sys, os, os.path, csv, math import itertools if __name__=="__main__": if len(sys.argv) > 2: # read in the datasets to analyze sets = dict() for filename in sys.argv[1:]: fhandle = open(filename, "rU") csvread = csv.reader(fhandle, dialect='excel-tab') for line in csvread: group = line[1] value = line[2] if group.startswith("["): if group not in sets: sets[group] = dict() sets[group][filename] = value # process and write out the results csv_out = csv.writer(sys.stdout, dialect='excel-tab') csv_out.writerow(["group"] + sys.argv[1:]) for group in sorted(sets, key=lambda x: str(len(x.strip("[]").rstrip("[]").split(","))) + str(x)): row = [group] for filename in sys.argv[1:]: if filename in sets[group]: row.append(sets[group][filename]) else: row.append("N/A") # write the results to standard output csv_out.writerow(row) else: # print usage instructions print "Usage: merge_vdiagram.py " print "Output: a merged Venn-Diagram table (to standard output)."