patient = Patient(patient)

        # Make maps for all annotations if not explicit
        if regions is None:
            patseqann = patient.get_reference('genomewide', format='gb')
            regionspat = map(attrgetter('id'), patseqann.features) + ['genomewide']
        else:
            regionspat = regions

        for region in regionspat:
            if VERBOSE >= 1:
                print pname, region

            refseq = load_custom_reference(refname, format='gb', region=region)
            patseq = patient.get_reference(region)

            mapco = build_coordinate_map(refseq, patseq, VERBOSE=VERBOSE)
            mapco = np.array(mapco, int)
            shift_mapco(mapco, refname, region)

            maps_coord[(region, pname)] = mapco 

            if save_to_file:
                out_fn = get_coordinate_map_filename(pname, region, refname=refname)
                np.savetxt(out_fn, mapco, fmt='%d',
                           delimiter='\t',
                           header=refname+'\t'+pname+'_'+region)
                if VERBOSE:
                    print 'Saved to file:', pname, region

Beispiel #2
0
 def get_map_coordinates_reference_filename(self, fragment, refname='HXB2'):
     '''Get the filename of the coordinate map to an external reference'''
     from hivwholeseq.patients.filenames import get_coordinate_map_filename
     return get_coordinate_map_filename(self.name,
                                        fragment,
                                        refname=refname)
Beispiel #3
0
 def get_map_coordinates_reference_filename(self, fragment, refname='HXB2'):
     '''Get the filename of the coordinate map to an external reference'''
     from hivwholeseq.patients.filenames import get_coordinate_map_filename
     return get_coordinate_map_filename(self.name, fragment, refname=refname)
Beispiel #4
0
            patseqann = patient.get_reference('genomewide', format='gb')
            regionspat = map(attrgetter('id'),
                             patseqann.features) + ['genomewide']
        else:
            regionspat = regions

        for region in regionspat:
            if VERBOSE >= 1:
                print pname, region

            refseq = load_custom_reference(refname, format='gb', region=region)
            patseq = patient.get_reference(region)

            mapco = build_coordinate_map(refseq, patseq, VERBOSE=VERBOSE)
            mapco = np.array(mapco, int)
            shift_mapco(mapco, refname, region)

            maps_coord[(region, pname)] = mapco

            if save_to_file:
                out_fn = get_coordinate_map_filename(pname,
                                                     region,
                                                     refname=refname)
                np.savetxt(out_fn,
                           mapco,
                           fmt='%d',
                           delimiter='\t',
                           header=refname + '\t' + pname + '_' + region)
                if VERBOSE:
                    print 'Saved to file:', pname, region
Beispiel #5
0
    if pnames is None:
        patients = [p for p in patients_all]
    else:
        patients = [p for p in patients_all if p.id in pnames]    
    if not len(patients):
        raise ValueError('No patients found!')

    if VERBOSE >= 3:
        print 'patients', map(attrgetter('id'), patients)

    for patient in patients:
        pname = patient.id

        found = False
        for fragment in ['F'+str(i+1) for i in xrange(7)] + ['genomewide']:
            map_fn = get_coordinate_map_filename(pname, fragment, refname=refname)
            mapco = np.loadtxt(map_fn, dtype=int, unpack=True)
            frag_start = mapco[0, 0]
            frag_end = mapco[0, -1] + 1

            if (frag_start <= coords[0]) and (frag_end + 1 >= coords[1]):
                found = True
                break

        if not found:
            raise ValueError('Window not found in any fragment or genomewide')

        if coords[0] in mapco[0]:
            win_start_init = mapco[1, mapco[0] == coords[0]][0]
        else:
            found = False