本文整理汇总了Python中pyms.Utils.Error.error函数的典型用法代码示例。如果您正苦于以下问题:Python error函数的具体用法?Python error怎么用?Python error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vector_by_step
def vector_by_step(vstart,vstop,vstep):
"""
@summary: generates a list by using start, stop, and step values
@param vstart: Initial value
@type vstart: A number
@param vstop: Max value
@type vstop: A number
@param vstep: Step
@type vstep: A number
@return: A list generated
@rtype: ListType
@author: Vladimir Likic
"""
if not is_number(vstart) or not is_number(vstop) or not is_number(vstep):
error("parameters start, stop, step must be numbers")
v = []
p = vstart
while p < vstop:
v.append(p)
p = p + vstep
return v
示例2: median
def median(v):
"""
@summary: Returns a median of a list or numpy array
@param v: Input list or array
@type v: ListType or numpy.core.ndarray
@return: The median of the input list
@rtype: FloatType
@author: Vladimir Likic
"""
if not is_list(v):
error("argument neither list nor array")
local_data = copy.deepcopy(v)
local_data.sort()
N = len(local_data)
if (N % 2) == 0:
# even number of points
K = N/2 - 1
median = (local_data[K] + local_data[K+1])/2.0
else:
# odd number of points
K = (N - 1)/2 - 1
median = local_data[K+1]
return median
示例3: rmsd
def rmsd(list1, list2):
"""
@summary: Calculates RMSD for the 2 lists
@param list1: First data set
@type list1: ListType, TupleType, or numpy.core.ndarray
@param list2: Second data set
@type list2: ListType, TupleType, or numpy.core.ndarray
@return: RMSD value
@rtype: FloatType
@author: Qiao Wang
@author: Andrew Isaac
@author: Vladimir Likic
"""
if not is_list(list1):
error("argument neither list nor array")
if not is_list(list2):
error("argument neither list nor array")
sum = 0.0
for i in range(len(list1)):
sum = sum + (list1[i] - list2[i]) ** 2
rmsd = math.sqrt(sum / len(list1))
return rmsd
示例4: std
def std(v):
"""
@summary: Calculates standard deviation
@param v: A list or array
@type v: ListType, TupleType, or numpy.core.ndarray
@return: Mean
@rtype: FloatType
@author: Vladimir Likic
"""
if not is_list(v):
error("argument neither list nor array")
v_mean = mean(v)
s = 0.0
for e in v:
d = e - v_mean
s = s + d*d
s_mean = s/float(len(v)-1)
v_std = math.sqrt(s_mean)
return v_std
示例5: MAD
def MAD(v):
"""
@summary: median absolute deviation
@param v: A list or array
@type v: ListType, TupleType, or numpy.core.ndarray
@return: median absolute deviation
@rtype: FloatType
@author: Vladimir Likic
"""
if not is_list(v):
error("argument neither list nor array")
m = median(v)
m_list = []
for xi in v:
d = math.fabs(xi - m)
m_list.append(d)
mad = median(m_list)/0.6745
return mad
示例6: write
def write(self, file_name, minutes=False):
"""
@summary: Writes the ion chromatogram to the specified file
@param file_name: Output file name
@type file_name: StringType
@param minutes: A boolean value indicating whether to write
time in minutes
@type minutes: BooleanType
@return: none
@rtype: NoneType
@author: Lewis Lee
@author: Vladimir Likic
"""
if not is_str(file_name):
error("'file_name' must be a string")
fp = open_for_writing(file_name)
time_list = copy.deepcopy(self.__time_list)
if minutes:
for ii in range(len(time_list)):
time_list[ii] = time_list[ii]/60.0
for ii in range(len(time_list)):
fp.write("%8.4f %#.6e\n" % (time_list[ii], self.__ia[ii]))
close_for_writing(fp)
示例7: exprl2alignment
def exprl2alignment(exprl):
"""
@summary: Converts experiments into alignments
@param exprl: The list of experiments to be converted into an alignment
objects
@type exprl: ListType
@author: Vladimir Likic
"""
if not is_list(exprl):
error("the argument is not a list")
algts = []
for item in exprl:
if not isinstance(item, Experiment):
error("list items must be 'Experiment' instances")
else:
algt = Class.Alignment(item)
algts.append(algt)
return algts
示例8: load_expr
def load_expr(file_name):
"""
@summary: Loads an experiment saved with 'store_expr'
@param file_name: Experiment file name
@type file_name: StringType
@return: The experiment intensity matrix and peak list
@rtype: pyms.Experiment.Class.Experiment
@author: Vladimir Likic
@author: Andrew Isaac
"""
if not is_str(file_name):
error("'file_name' not a string")
fp = open(file_name,'rb')
expr = cPickle.load(fp)
fp.close()
if not isinstance(expr, Experiment):
error("'file_name' is not an Experiment object")
return expr
示例9: __init__
def __init__(self, mass_list, intensity_list):
"""
@summary: Initialize the Scan data
@param mass_list: mass values
@type mass_list: ListType
@param intensity_list: intensity values
@type intensity_list: ListType
@author: Qiao Wang
@author: Andrew Isaac
@author: Vladimir Likic
"""
if not is_list(mass_list) or not is_number(mass_list[0]):
error("'mass_list' must be a list of numbers")
if not is_list(intensity_list) or \
not is_number(intensity_list[0]):
error("'intensity_list' must be a list of numbers")
self.__mass_list = mass_list
self.__intensity_list = intensity_list
self.__min_mass = min(mass_list)
self.__max_mass = max(mass_list)
示例10: get_ic_at_mass
def get_ic_at_mass(self, mass = None):
"""
@summary: Returns the ion chromatogram for the specified mass.
The nearest binned mass to mass is used.
If no mass value is given, the function returns the total
ion chromatogram.
@param mass: Mass value of an ion chromatogram
@type mass: IntType
@return: Ion chromatogram for given mass
@rtype: IonChromatogram
@author: Andrew Isaac
@author: Vladimir Likic
"""
if mass == None:
return self.get_tic()
if mass < self.__min_mass or mass > self.__max_mass:
print "min mass: ", self.__min_mass, "max mass:", self.__max_mass
error("mass is out of range")
ix = self.get_index_of_mass(mass)
return self.get_ic_at_index(ix)
示例11: write_intensities_stream
def write_intensities_stream(self, file_name):
"""
@summary: Writes all intensities to a file
@param file_name: Output file name
@type file_name: StringType
This function loop over all scans, and for each scan
writes intensities to the file, one intenisity per
line. Intensities from different scans are joined
without any delimiters.
@author: Vladimir Likic
"""
if not is_str(file_name):
error("'file_name' must be a string")
N = len(self.__scan_list)
print" -> Writing scans to a file"
fp = open_for_writing(file_name)
for ii in range(len(self.__scan_list)):
scan = self.__scan_list[ii]
intensities = scan.get_intensity_list()
for I in intensities:
fp.write("%8.4f\n" % ( I ) )
close_for_writing(fp)
示例12: __set_time
def __set_time(self, time_list):
"""
@summary: Sets time-related properties of the data
@param time_list: List of retention times
@type time_list: ListType
@author: Vladimir Likic
"""
# calculate the time step, its spreak, and along the way
# check that retention times are increasing
time_diff_list = []
for ii in range(len(time_list)-1):
t1 = time_list[ii]
t2 = time_list[ii+1]
if not t2 > t1:
error("problem with retention times detected")
time_diff = t2 - t1
time_diff_list.append(time_diff)
time_step = mean(time_diff_list)
time_step_std = std(time_diff_list)
self.__time_list = time_list
self.__time_step = time_step
self.__time_step_std = time_step_std
self.__min_rt = min(time_list)
self.__max_rt = max(time_list)
示例13: amin
def amin(v):
"""
@summary: Finds the minimum element in a list or array
@param v: A list or array
@type v: ListType, TupleType, or numpy.core.ndarray
@return: Tuple (maxi, maxv), where maxv is the minimum
element in the list and maxi is its index
@rtype: TupleType
@author: Vladimir Likic
"""
if not is_list(v):
error("argument neither list nor array")
minv = max(v) # built-in max() function
mini = None
for ii in range(len(v)):
if v[ii] < minv:
minv = v[ii]
mini = ii
if mini == None:
error("finding maximum failed")
return mini, minv
示例14: rel_threshold
def rel_threshold(pl, percent=2):
"""
@summary: Remove ions with relative intensities less than the given
relative percentage of the maximum intensity.
@param pl: A list of Peak objects
@type pl: ListType
@param percent: Threshold for relative percentage of intensity (Default 2%)
@type percent: FloatType
@return: A new list of Peak objects with threshold ions
@rtype: ListType
@author: Andrew Isaac
"""
if not is_number(percent) or percent <= 0:
error("'percent' must be a number > 0")
pl_copy = copy.deepcopy(pl)
new_pl = []
for p in pl_copy:
ms = p.get_mass_spectrum()
ia = ms.mass_spec
# assume max(ia) big so /100 1st
cutoff = (max(ia)/100.0)*float(percent)
for i in range(len(ia)):
if ia[i] < cutoff:
ia[i] = 0
ms.mass_spec = ia
p.set_mass_spectrum(ms)
new_pl.append(p)
return new_pl
示例15: plot_peaks
def plot_peaks(self, peak_list, label = "Peaks"):
"""
@summary: Plots the locations of peaks as found
by PyMS.
@param peak_list: List of peaks
@type peak_list: list of pyms.Peak.Class.Peak
@param label: label for plot legend
@type label: StringType
"""
if not isinstance(peak_list, list):
error("peak_list is not a list")
time_list = []
height_list=[]
# Copy to self.__peak_list for onclick event handling
self.__peak_list = peak_list
for peak in peak_list:
time_list.append(peak.get_rt())
height_list.append(sum(peak.get_mass_spectrum().mass_spec))
self.__tic_ic_plots.append(plt.plot(time_list, height_list, 'o',\
label = label))