Ejemplo n.º 1
0
def qq_rt(secondr):
    wstr0 = 'trans2_' if secondr else 'trans_'
    QQ_rt = collections.defaultdict(list)
    for trans in t_list:
        trans_file = os.path.join(
            miscdir,
            commonfn.format_filename(wstr0 + '{}Q1_{:.1f}Q3_{:.1f}.txt'.format(
                trans.name, trans.q1, trans.q3)))
        if os.path.isfile(trans_file):
            fo = open(trans_file)
            next(fo)
            while fo.readline():
                next(fo)
                feat0 = fo.readline().strip()
                feat_l = []
                while feat0:
                    feat_l.append([float(x) for x in feat0.split('\t')[:2]])
                    feat0 = fo.readline().strip()
                QQ_rt[trans].append(feat_l)
    return dict(QQ_rt)
Ejemplo n.º 2
0
mzML_files = []
for x in param_dict["mzML_files"].split('\t'):
    mzML_files.extend(glob.glob(x))
mzML_files.sort()
print(len(mzML_files), 'mzML files')

miscdir = 'trans'
if os.path.exists(miscdir):
    print('rerun?')
    input('Press Enter/Return to continue')
else:
    os.mkdir(miscdir)
trans2filename = {
    trans: os.path.join(
        miscdir,
        commonfn.format_filename('trans_{}Q1_{:.1f}Q3_{:.1f}.txt'.format(
            trans.name, trans.q1, trans.q3)))
    for trans in t_list
}

peak_w = [int(x) for x in param_dict["length_of_ion_chromatogram"].split()]
wave_scales = [x / 2 for x in list(range(peak_w[1] + 2, peak_w[0] - 3, -2))]
wave_scales = [2, 2.5] + list(range(3, 20)) + [20 * 1.05**i for i in range(20)]
ws0 = bisect_left(wave_scales, peak_w[0] / 2)
ws1 = bisect_left(wave_scales, peak_w[1] / 2)

wave_scales = wave_scales[:ws1 + 1 + 1]  #[::-1]
wave_sqrt = [math.sqrt(x) for x in wave_scales]
findridge = partial(MRMcwt.findridge0, wave_scales, wave_sqrt, False)
findridge2 = partial(MRMcwt.findridge0, wave_scales, wave_sqrt, True)

for trans in t_list:
Ejemplo n.º 3
0
t_list=[x for x in t_list if x.istd in istd_dict]

mzML_files=[]
for x in param_dict["mzML_files"].split():
    mzML_files.extend(glob.glob(x))
mzML_files.sort()
mzML_files=mzML_files[:]
print(len(mzML_files),'mzML files')

miscdir='trans'
if os.path.exists(miscdir):
    print('rerun?')
    input('Press Enter/Return to continue')
else:
    os.mkdir(miscdir)
trans2filename={trans:os.path.join(miscdir,commonfn.format_filename('trans_{}Q1_{:.1f}Q3_{:.1f}.txt'.format(trans.name,trans.q1,trans.q3))) for trans in t_list}

peak_w=[int(x) for x in param_dict["length_of_ion_chromatogram"].split()]
wave_scales=[x/2 for x in list(range(peak_w[1]+2,peak_w[0]-3,-2))]
wave_scales=[2,2.5]+list(range(3,20))+[20*1.05**i for i in range(20)]
ws0=bisect_left(wave_scales,peak_w[0]/2)
ws1=bisect_left(wave_scales,peak_w[1]/2)

wave_scales=wave_scales[:ws1+1+1]#[::-1]
wave_sqrt=[math.sqrt(x) for x in wave_scales]
findridge=partial(MRMcwt.findridge0,wave_scales,wave_sqrt,False)
findridge2=partial(MRMcwt.findridge0,wave_scales,wave_sqrt,True)


for trans in t_list:
    open(trans2filename[trans],'w').write('{}\n'.format(trans.name))
Ejemplo n.º 4
0
                pdf0.savefig()
                plt.close()
            ii += 1
    if ii % 4 != 0:
        pdf0.savefig()
        plt.close()

with open(ppfile, 'w') as usersRT:
    usersRT.write(
        'class\tname\tQ1\tQ3\t%CoV(TQC)\t%CoV(BQC)\texpectedRT\tdetectedRT\tusersRT\n'
    )
    for (cpd, q1, q3, rt), npeak in sorted(npeaks.items()):
        with open(
                os.path.join(
                    miscdir,
                    commonfn.format_filename('trans2_{}Q1_{}Q3_{}.txt'.format(
                        cpd, q1, q3)))) as trans2:
            next(trans2)
            rt_l = trans2.readline().split('\t')
            minRT, maxRT = float(rt_l[0]), float(rt_l[-1])
            qlen = (maxRT - minRT) / 4
            q25, q75 = minRT + qlen, maxRT - qlen

        class0 = t_list[bisect_left([x.name for x in t_list], cpd)].lclass
        itc = class_intercept.get(class0, 0)
        pred = min(npeak, key=lambda x: abs(itc + float(rt) - float(x)))
        if not q25 < float(pred) < q75:
            pred = ''
        usersRT.write('{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n'.format(
            class0, cpd, q1, q3, ', '.join(CoVTQC[(cpd, q1, q3)]),
            ', '.join(CoVBQC[(cpd, q1, q3)]), rt, ', '.join(npeak), pred))
Ejemplo n.º 5
0
            if ii%4==3:
                pdf0.savefig()
                plt.close()
            ii+=1
    if ii%4!=0:
        pdf0.savefig()
        plt.close()


if os.path.isfile(ppfile):
    print(ppfile+' exists, will not be overwriten')
    sys.exit()

with open(ppfile,'w') as usersRT:
    usersRT.write('class\tname\tQ1\tQ3\t%CoV(TQC)\t%CoV(BQC)\tD-ratio\texpectedRT\tdetectedRT\tusersRT\n')
    for (cpd,q1,q3,rt),npeak in sorted(npeaks.items()):
        with open(os.path.join(miscdir,commonfn.format_filename('trans2_{}Q1_{}Q3_{}.txt'.format(cpd,q1,q3)))) as trans2:
            next(trans2)
            rt_l=trans2.readline().split('\t')
            minRT,maxRT=float(rt_l[0]),float(rt_l[-1])
            qlen=(maxRT-minRT)/4
            q25,q75=minRT+qlen,maxRT-qlen

        class0=t_list[bisect_left([x.name for x in t_list],cpd)].lclass
        itc=class_intercept.get(class0,0)
        pred=min(npeak,key=lambda x:abs(itc+float(rt)-float(x)))
        if not q25<float(pred)<q75:
            pred=''
        usersRT.write('{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n'.format(class0,cpd,q1,q3,', '.join(CoVTQC[(cpd,q1,q3)]),', '.join(CoVBQC[(cpd,q1,q3)]),', '.join(Dratio[(cpd,q1,q3)]),rt,', '.join(npeak),pred))