fragments = args.fragments patients = load_patients() for fragment in fragments: if VERBOSE >= 1: print fragment refs = [] for pname, patient in patients.iterrows(): if VERBOSE >= 2: print pname patient = Patient(patient) refs.append(patient.get_reference(fragment)) ali = align_muscle(*refs, sort=True) # Check whether all references are complete (using the longest primers) if VERBOSE >= 2: print 'Check alignment' alim = np.array(ali) if (alim[:, :4] == '-').any(): raise ValueError('Gaps at the beginning of fragment found') elif (alim[:, -4:] == '-').any(): raise ValueError('Gaps at the end of fragment found') if VERBOSE >= 2: print 'Save to file' fn = get_reference_alignment_filename(fragment) AlignIO.write(ali, fn, 'fasta')
patient = Patient(patient) for region in regions: if VERBOSE >= 1: print patient.name, region if VERBOSE >= 2: print 'Get haplotype counts' (hct, ind, seqs) = patient.get_region_count_trajectories(region, VERBOSE=VERBOSE) times = patient.times[ind] if VERBOSE >= 2: print 'Align sequences' ali = align_muscle(*seqs, sort=True) alim = np.array(ali) if VERBOSE >= 2: print 'Get distributions' ds = get_distance_distributions(hct, alim, VERBOSE=VERBOSE) data.append({'pname': pname, 'ds': ds, 't': times, 'region': region}) if use_plot: for pname, patient in patients.iterrows(): patient = Patient(patient) nrows = 1 + (len(regions) - 1) // 3