def computeAndWrite(reactor):
		"""The per-step work of reading reactor state and computing figures of interest is done here."""
		ens = reactor['ensemble']
		mon = reactor['monomer']
		numbers = [a.number for a in ens.assemblies]
		numbers.sort(reverse=True)
		if len(numbers)==0:
			sizestr = '0'
		else:
			sizestr = ','.join(['{:d}'.format(n) for n in numbers])
		largest_assembly = ens.largest()
		if largest_assembly is None:
			largest_radius = ens.monomer_radius
		else:
			largest_radius = largest_assembly.radius
		mean_radius = options.monomer_radius_nm
		if len(numbers)>0:
			mean_assembly_radius = ens.statistic(lambda x: x.radius, stats.mean)
			mean_radius = (mon.number * options.monomer_radius_nm + mean_assembly_radius * ens.number)/float(mon.number + ens.number)
		intwt_radius = intensityWeightedRadius(mon.number, options.monomer_radius_nm, [a.radius for a in ens.assemblies])

		prop_active = mon.getProportionActivated(reactor.temperature)
		prop_assembled = 1.0 - float(mon.number)/n_monomers

		line = ("{r.num_steps:d}\t{time:1.2f}\t{r.temperature}\t{prop_active:1.1E}\t{m.number:d}\t{prop_assembled:1.1E}\t{a.number:d}\t" + \
			"{largest_radius:1.2f}\t{mean_radius:s}\t{intwt_radius:s}\t{sizes:s}\n").format(
			r=reactor, time=min(options.simulation_time, reactor.time), prop_active=prop_active, m=mon, prop_assembled=prop_assembled, a=ens, 
			largest_radius=largest_radius, mean_radius=na.formatNA(mean_radius, '{:1.2f}'), 
			intwt_radius=na.formatNA(intwt_radius, '{:1.2f}'), sizes=sizestr)
		data_outs.write(line)
    def computeAndWrite(reactor):
        """The per-step work of reading reactor state and computing figures of interest is done here."""
        ens = reactor['ensemble']
        mon = reactor['monomer']
        numbers = [a.number for a in ens.assemblies]
        numbers.sort(reverse=True)
        if len(numbers) == 0:
            sizestr = '0'
        else:
            sizestr = ','.join(['{:d}'.format(n) for n in numbers])
        largest_assembly = ens.largest()
        if largest_assembly is None:
            largest_radius = ens.monomer_radius
        else:
            largest_radius = largest_assembly.radius
        mean_radius = options.monomer_radius_nm
        if len(numbers) > 0:
            mean_assembly_radius = ens.statistic(lambda x: x.radius,
                                                 stats.mean)
            mean_radius = (mon.number * options.monomer_radius_nm +
                           mean_assembly_radius *
                           ens.number) / float(mon.number + ens.number)
        intwt_radius = intensityWeightedRadius(
            mon.number, options.monomer_radius_nm,
            [a.radius for a in ens.assemblies])

        prop_active = mon.getProportionActivated(reactor.temperature)
        prop_assembled = 1.0 - float(mon.number) / n_monomers

        line = ("{r.num_steps:d}\t{time:1.2f}\t{r.temperature}\t{prop_active:1.1E}\t{m.number:d}\t{prop_assembled:1.1E}\t{a.number:d}\t" + \
         "{largest_radius:1.2f}\t{mean_radius:s}\t{intwt_radius:s}\t{sizes:s}\n").format(
         r=reactor, time=min(options.simulation_time, reactor.time), prop_active=prop_active, m=mon, prop_assembled=prop_assembled, a=ens,
         largest_radius=largest_radius, mean_radius=na.formatNA(mean_radius, '{:1.2f}'),
         intwt_radius=na.formatNA(intwt_radius, '{:1.2f}'), sizes=sizestr)
        data_outs.write(line)
Exemple #3
0
	def __str__(self):
		line = self.key
		floatformat = "{:1.4f}"
		line += '\n\tH/L      \t' + '\t'.join([na.formatNA(r,format=floatformat) for r in self.heavy_light_ratio_list]) + '\n'
		line += '\tH/L Normal.\t' + '\t'.join([na.formatNA(r,format=floatformat) for r in self.heavy_light_normalized_ratio_list]) + '\n'
		line += '\tIntensity H\t' + '\t'.join([na.formatNA(r,format=floatformat) for r in self.intensity_h_list]) + '\n'
		line += '\tIntensity L\t' + '\t'.join([na.formatNA(r,format=floatformat) for r in self.intensity_l_list]) + '\n'
		line += '\tMS/MS Count\t{0:d}\n'.format(self.msms_count)
		return line
Exemple #4
0
 def formatLine(self, entry):
     """ Format the entry by headers. """
     line = ""
     tab = '\t'
     # If entry is a dictionary...
     for h in self._header_list:
         try:
             fmt = "{:" + h.format + '}'
             if line != '':
                 line += tab
             line += fmt.format(entry[h.name])
         except ValueError as ve:
             if h.format == 's':  # string
                 line += fmt.format(naStringParser(entry[h.name]))
             else:
                 raise ve
         except TypeError as te:
             # This will occur if entry[h.name] is None. Format as NA.
             val = entry[h.name]
             res = na.formatNA(val)
             fmt = "{:s}"
             line += fmt.format(res)
     return line + '\n'
Exemple #5
0
Fichier : util.py Projet : dad/base
	def formatLine(self, entry):
		""" Format the entry by headers. """
		line = ""
		tab = '\t'
		# If entry is a dictionary...
		for h in self._header_list:
			try:
				fmt = "{:"+h.format+'}'
				if line != '':
					line += tab
				line += fmt.format(entry[h.name])
			except ValueError as ve:
				if h.format=='s': # string
					line += fmt.format(naStringParser(entry[h.name]))
				else:
					raise ve
			except TypeError as te:
				# This will occur if entry[h.name] is None. Format as NA.
				val = entry[h.name]
				res = na.formatNA(val)
				fmt = "{:s}"
				line += fmt.format(res)
		return line + '\n'
Exemple #6
0
        # Write output
    n_written = 0
    # Tack sequence on the end, for better readability
    columns = headers[:]
    columns.remove("sequence")
    data_outs.write("\t".join(columns) + "\tp.value\tp.value.adj\tsequence\n")
    for key in keys:
        flds = data[key]
        # entropy = flds['entropy']
        # length = flds['length'] # length of the region
        pval = p_value_dict[key]
        adj_pval = None
        if options.adjust:
            adj_pval = adjusted_p_value_dict[key]
        line = "\t".join(["{}".format(flds[col]) for col in columns])
        line += "\t{pval}\t{adj_pval}".format(
            pval=na.formatNA(pval, format="{:1.3E}"), adj_pval=na.formatNA(adj_pval, format="{:1.3E}")
        )
        line += "\t" + flds["sequence"] + "\n"
        data_outs.write(line)
        n_written += 1

        # Write out stopping time
    data_outs.write("# Run finished {}\n".format(util.timestamp()))

    # Shut down output
    if not options.out_fname is None:
        info_outs.write("# Wrote {} lines to {}\n".format(n_written, options.out_fname))
        outf.close()
Exemple #7
0
		#adjusted_p_value_dict = dict([(k, v) for (k,v) in zip(keys, adjusted_p_values)])
	
	# Write output
	n_written = 0
	# Tack sequence on the end, for better readability
	columns = headers[:]
	columns.remove('sequence')
	data_outs.write('\t'.join(columns) + "\tp.value\tp.value.adj\tsequence\n")
	for key in keys:
		flds = data[key]
		#entropy = flds['entropy']
		#length = flds['length'] # length of the region
		pval = p_value_dict[key]
		adj_pval = None
		if options.adjust:
			adj_pval = adjusted_p_value_dict[key]
		line = '\t'.join(['{}'.format(flds[col]) for col in columns])
		line += "\t{pval}\t{adj_pval}".format(pval=na.formatNA(pval, format="{:1.3E}"), adj_pval=na.formatNA(adj_pval, format="{:1.3E}"))
		line += '\t' + flds['sequence'] + '\n'
		data_outs.write(line)
		n_written += 1

	# Write out stopping time
	data_outs.write("# Run finished {}\n".format(util.timestamp()))

	# Shut down output
	if not options.out_fname is None:
		info_outs.write("# Wrote {} lines to {}\n".format(n_written, options.out_fname))
		outf.close()

Exemple #8
0
		for (pos, pep) in pep_list:
			n_peps += 1
			pepid = "{}-{}".format(options.target_orf, n_peps)
			line = gap*pos + pep.sequence + gap*(len_prot-(len(pep.sequence)+pos))
			outs.write(">{}\n{}\n".format(pepid, line))
	elif options.output_type == 'ratio':
		outs.write("seq\tmod.seq\tbegin\tend\tratio\tint.ratio\tintensity\tintensity.h\tintensity.l\n")
		n_written = 0
		for (pos, pep) in pep_list:
			#ratio_stats = pep.getHeavyLightRatioSummary()
			for (ri,ratio) in enumerate(pep.heavy_light_ratio_list):
				inth = pep.intensity_h_list[ri]
				intl = pep.intensity_l_list[ri]
				inten = None
				# Ratio of intensities
				int_ratio = None
				if not (na.isNA(inth) or na.isNA(intl)):
					inten = inth+intl
					if intl>0:
						int_ratio = inth/float(intl)
				outs.write("{seq}\t{modseq}\t{begin}\t{end}\t{ratio}\t{intratio}\t{inten}\t{inth}\t{intl}\n".format(
					seq=pep.sequence, modseq=pep.modified_sequence, begin=pos+1, end=pos+len(pep.sequence), 
					ratio=na.formatNA(ratio), intratio=na.formatNA(int_ratio), inten=na.formatNA(inten), inth=na.formatNA(inth), intl=na.formatNA(intl)))
				n_written += 1
		info_outs.write("# Wrote {} peptide records\n".format(n_written))
			#outs.write("{seq}\t{begin}\t{end}\t{ratio}\t{ratio_n}\n".format(
			#	seq=pep.sequence, begin=pos+1, end=pos+len(pep.sequence), ratio=na.formatNA(ratio_stats.median), ratio_n=na.formatNA(ratio_stats.n)))
		
			
	
Exemple #9
0
    # Write output
    n_written = 0
    # Tack sequence on the end, for better readability
    columns = headers[:]
    columns.remove('sequence')
    data_outs.write('\t'.join(columns) + "\tp.value\tp.value.adj\tsequence\n")
    for key in keys:
        flds = data[key]
        #entropy = flds['entropy']
        #length = flds['length'] # length of the region
        pval = p_value_dict[key]
        adj_pval = None
        if options.adjust:
            adj_pval = adjusted_p_value_dict[key]
        line = '\t'.join(['{}'.format(flds[col]) for col in columns])
        line += "\t{pval}\t{adj_pval}".format(
            pval=na.formatNA(pval, format="{:1.3E}"),
            adj_pval=na.formatNA(adj_pval, format="{:1.3E}"))
        line += '\t' + flds['sequence'] + '\n'
        data_outs.write(line)
        n_written += 1

    # Write out stopping time
    data_outs.write("# Run finished {}\n".format(util.timestamp()))

    # Shut down output
    if not options.out_fname is None:
        info_outs.write("# Wrote {} lines to {}\n".format(
            n_written, options.out_fname))
        outf.close()
Exemple #10
0
	if not options.sequence is None:
		seq = options.sequence
	
	if options.degap and not seq is None:
		seq = seq.replace('-','')

	if options.write_report and not seq is None:
		score_res = motif.score(seq, matrix, return_windows=True)
		header = 'pos\tresidue\tscore\tabove.threshold\twindow\n'
		outs.write(header)
		for sentry in score_res.results:
			resthresh_out = ' '
			if sentry.score >= options.score_threshold and sentry.residue != '-':
				resthresh_out = "*"
			line = "{pos}\t{aa}\t{resscore}\t{resthresh}\t{win}\n".format(
				pos=sentry.pos+1, aa=sentry.residue, resscore=na.formatNA(sentry.score,"{:1.2f}"), resthresh=resthresh_out, win=sentry.window)
			outs.write(line)
		sys.exit()
		
	if options.write_report and not orf_dict is None:
		header = "orf\tnum.sites\tnum.motifs\tprop.sites\tmax.score\t" + \
			'\t'.join(['num.motifs.{:d}'.format(i+1) for i in range(options.maximum_frequency_bin)]) + '\tnum.motifs.longer\n'
		outs.write(header)
		for (hdr,rawseq) in zip(headers,sequences):
			orf = biofile.firstField(hdr)
			if options.translate:
				seq = translate.translate(rawseq)
				if seq is None:
					outs.write("# Skipping {} -- bad translation\n".format(orf))
					continue
			else:
Exemple #11
0
            "seq\tmod.seq\tbegin\tend\tratio\tint.ratio\tintensity\tintensity.h\tintensity.l\n"
        )
        n_written = 0
        for (pos, pep) in pep_list:
            #ratio_stats = pep.getHeavyLightRatioSummary()
            for (ri, ratio) in enumerate(pep.heavy_light_ratio_list):
                inth = pep.intensity_h_list[ri]
                intl = pep.intensity_l_list[ri]
                inten = None
                # Ratio of intensities
                int_ratio = None
                if not (na.isNA(inth) or na.isNA(intl)):
                    inten = inth + intl
                    if intl > 0:
                        int_ratio = inth / float(intl)
                outs.write(
                    "{seq}\t{modseq}\t{begin}\t{end}\t{ratio}\t{intratio}\t{inten}\t{inth}\t{intl}\n"
                    .format(seq=pep.sequence,
                            modseq=pep.modified_sequence,
                            begin=pos + 1,
                            end=pos + len(pep.sequence),
                            ratio=na.formatNA(ratio),
                            intratio=na.formatNA(int_ratio),
                            inten=na.formatNA(inten),
                            inth=na.formatNA(inth),
                            intl=na.formatNA(intl)))
                n_written += 1
        info_outs.write("# Wrote {} peptide records\n".format(n_written))
        #outs.write("{seq}\t{begin}\t{end}\t{ratio}\t{ratio_n}\n".format(
        #	seq=pep.sequence, begin=pos+1, end=pos+len(pep.sequence), ratio=na.formatNA(ratio_stats.median), ratio_n=na.formatNA(ratio_stats.n)))