Exemple #1
0
def score_and_link_cycles(args):
    if args.binwidth:
        histseg.Global_BINWIDTH = args.binwidth
    if not args.historystats and args.cnavg:
        historyScores = histseg.combine_history_statsfiles(args.cnavg)
    elif not os.path.isfile(args.historystats) and args.cnavg:
        historyScores = histseg.combine_history_statsfiles(args.cnavg)
        np.savetxt(args.historystats, historyScores, fmt="%d", delimiter='\t')
    elif os.path.isfile(args.historystats):
        historyScores = np.loadtxt(args.historystats, dtype=int)
    if not historyScores:
        sys.exit("Need to use --historystats or --cnavg option")
    totalp = 0
    if args.totalp:
        totalp = args.totalp
    else:
        totalp = histseg.compute_likelihood_histories(historyScores[:, 0],
                                                      historyScores)
    allevents = []
    if args.cnavg:
        sys.stderr.write("using cnavg dir: %s\n" % (args.cnavg))
        allevents = histseg.get_events_from_cnavgdir(args.cnavg, historyScores,
                                                     totalp)
    elif args.inpickle and os.path.isfile(args.inpickle):
        sys.stderr.write("using pickle file\n")
        allevents = pickle.load(open(args.inpickle, 'rb'))
    sys.stderr.write("there are %d events\n" % (len(allevents)))
    if args.outpickle:
        for event in allevents:
            event.trim()
        eventfile = open(args.outpickle, 'wb')
        pickle.dump(allevents, eventfile, pickle.HIGHEST_PROTOCOL)
    if args.events:
        eventfile = open(args.events, 'w')
        for evnt in allevents:
            eventfile.write("%s" % (str(evnt)))
    # link the events...
    if args.links:
        if not allevents:
            sys.exit(
                "Need events to link!  use --inpickle or --cnavg or --events")
        if not totalp:
            sys.exit("Need a --totalp or --cnavg or --historystats options")
        eventlinks = link_events_by_order_within_histories(allevents)
        linkfile = open(args.links, 'w')
        for link in eventlinks:
            link.likelihood = histseg.compute_likelihood_histories(
                link.histories, historyScores)
            linkfile.write("%s" % (str(link)))
def score_and_link_cycles(args):
	if args.binwidth: 
		histseg.Global_BINWIDTH=args.binwidth
	if not args.historystats and args.cnavg: 	
		historyScores=histseg.combine_history_statsfiles(args.cnavg)
	elif not os.path.isfile(args.historystats) and args.cnavg: 
		historyScores=histseg.combine_history_statsfiles(args.cnavg)
		np.savetxt(args.historystats, historyScores, fmt="%d", delimiter='\t')
	elif os.path.isfile(args.historystats):
		historyScores=np.loadtxt(args.historystats, dtype=int)
	if not historyScores: 
		sys.exit("Need to use --historystats or --cnavg option")
	totalp=0
	if args.totalp: 
		totalp=args.totalp
	else: 
		totalp = histseg.compute_likelihood_histories(historyScores[:,0], historyScores)
	allevents=[]
	if args.cnavg: 
		sys.stderr.write("using cnavg dir: %s\n" % (args.cnavg))
		allevents=histseg.get_events_from_cnavgdir(args.cnavg, historyScores, totalp)
	elif args.inpickle and os.path.isfile(args.inpickle): 
		sys.stderr.write("using pickle file\n")
		allevents=pickle.load(open(args.inpickle, 'rb'))
	sys.stderr.write("there are %d events\n" % (len(allevents)))
	if args.outpickle: 
		for event in allevents: 
			event.trim()
		eventfile= open(args.outpickle, 'wb')
		pickle.dump(allevents, eventfile, pickle.HIGHEST_PROTOCOL)
	if args.events: 
		eventfile=open(args.events, 'w')
		for evnt in allevents: 
			eventfile.write("%s" % (str(evnt)))
	# link the events...
	if args.links: 
		if not allevents: 
			sys.exit("Need events to link!  use --inpickle or --cnavg or --events")
		if not totalp: 
			sys.exit("Need a --totalp or --cnavg or --historystats options")	
		eventlinks = link_events_by_order_within_histories(allevents)
		linkfile=open(args.links, 'w')
		for link in eventlinks: 
			link.likelihood=histseg.compute_likelihood_histories(link.histories, historyScores)
			linkfile.write("%s" % (str(link)))
	def run(self):
		opts=self.options
		if opts.simulation:
			truefile=os.path.join(opts.cnavgout, "true.braney")
			truehist=os.path.join(opts.cnavgout, "HISTORIES_0.braney")
#			subprocess.call("grep -v ^$ %s | gzip > %s" % (truefile, truehist), shell=True)
			subprocess.check_call("awk 'BEGIN{OFS=\"\\t\"}{if ($1==\"A\" && $9>1) $9=1; if($1 != \"A\" && $5>1) $5=1; print $0}' %s | sed 1d | gzip > %s" % (truefile, truehist), shell=True)
			make_STATS_from_truebraney(truefile, os.path.join(opts.cnavgout, "HISTORY_STATS_0"))
		statsfiles=glob.glob(self.cnavgout+"/"+"HISTORY_STATS*")
		sys.stderr.write("statsfiles: %s\n" % (str(statsfiles)))
		historyScores=histseg.combine_history_statsfiles(self.cnavgout)
		np.savetxt(self.historystatsfile, historyScores, fmt='%d', delimiter='\t')
 def run(self):
     opts = self.options
     if opts.simulation:
         truefile = os.path.join(opts.cnavgout, "true.braney")
         truehist = os.path.join(opts.cnavgout, "HISTORIES_0.braney")
         #			subprocess.call("grep -v ^$ %s | gzip > %s" % (truefile, truehist), shell=True)
         subprocess.check_call(
             "awk 'BEGIN{OFS=\"\\t\"}{if ($1==\"A\" && $9>1) $9=1; if($1 != \"A\" && $5>1) $5=1; print $0}' %s | sed 1d | gzip > %s"
             % (truefile, truehist),
             shell=True)
         make_STATS_from_truebraney(
             truefile, os.path.join(opts.cnavgout, "HISTORY_STATS_0"))
     statsfiles = glob.glob(self.cnavgout + "/" + "HISTORY_STATS*")
     sys.stderr.write("statsfiles: %s\n" % (str(statsfiles)))
     historyScores = histseg.combine_history_statsfiles(self.cnavgout)
     np.savetxt(self.historystatsfile,
                historyScores,
                fmt='%d',
                delimiter='\t')