コード例 #1
0
ファイル: MotifScan.py プロジェクト: bbcf/bsPlugins
    def __call__(self, **kw):
        fasta_file = kw.get('fastafile')
        background = kw.get('background') or None
        assembly_id = kw.get('assembly') or None
        regions_file = kw.get('regions') or None
        motifs_list = kw.get('motifs')
        motif_add = kw.get('customMotif')
        threshold = float(kw.get('threshold') or 0)

        if motifs_list is None: motifs_list = []
        if isinstance(motifs_list, basestring): motifs_list = motifs_list.split("|")
        if not isinstance(motifs_list, list): motifs_list = [motifs_list]

        if background is None and assembly_id is None:
            background = self.temporary_path(fname='background.txt')
            stats = {'A': 0.25,'C': 0.25, 'G': 0.25, 'T': 0.25}
            if fasta_file:
                fasta_file = os.path.abspath(fasta_file)
                with execution(None) as ex:
                    stats = fasta_composition(ex,fasta_file,frequency=True)
            with open(background,"w") as bgr:
                bgr.write(" ".join(["1"]+[str(stats[n]) for n in 'ACGT']))
        if assembly_id is not None:
            assembly = genrep.Assembly(assembly_id)
        else:
            if regions_file is not None:
                raise ValueError("Please specify an assembly if you specify regions.")
            regions_file = os.path.abspath(regions_file)
            assembly = None

        motifs = {}
        if motif_add is not None:
            mname = os.path.basename(os.path.splitext(motif_add)[0])
            if mname: motifs[mname] = os.path.abspath(motif_add)
        for mot in motifs_list:
            gid, mname = mot.split(' ')
            pwmfile = self.temporary_path()
            g.get_motif_PWM(int(gid), mname, output=pwmfile)
            motifs[mname] = pwmfile

        if len(motifs) == 0:
            raise ValueError("Please give at least one motif to scan for")

        track_output = self.temporary_path(fname='motif_scan', ext="bed")
        with execution(None) as ex:
            save_motif_profile( ex, motifs, assembly, regions_file, fasta_file,
                                background=background, threshold=threshold,
                                output=track_output,
                                description=None, via='local' )
        self.new_file(track_output, 'motif_track')
        return self.display_time()
コード例 #2
0
    def __call__(self, **kw):
        fasta_file = kw.get('fastafile')
        background = kw.get('background') or None
        assembly_id = kw.get('assembly') or None
        regions_file = kw.get('regions') or None
        motifs_list = kw.get('motifs')
        motif_add = kw.get('customMotif')
        threshold = float(kw.get('threshold') or 0)

        if motifs_list is None: motifs_list = []
        if isinstance(motifs_list, basestring): motifs_list = motifs_list.split("|")
        if not isinstance(motifs_list, list): motifs_list = [motifs_list]

        if background is None and assembly_id is None:
            background = self.temporary_path(fname='background.txt')
            stats = {'A': 0.25,'C': 0.25, 'G': 0.25, 'T': 0.25}
            if fasta_file:
                with execution(None) as ex:
                    stats = fasta_composition(ex,fasta_file,frequency=True)
            with open(background,"w") as bgr:
                bgr.write(" ".join(["1"]+[str(stats[n]) for n in 'ACGT']))
        if assembly_id is not None:
            assembly = genrep.Assembly(assembly_id)
        else:
            if regions_file is not None:
                raise ValueError("Please specify an assembly if you specify regions.")
            regions_file = os.path.abspath(regions_file)
            assembly = None

        motifs = {}
        if motif_add is not None:
            mname = os.path.basename(os.path.splitext(motif_add)[0])
            if mname: motifs[mname] = os.path.abspath(motif_add)
        for mot in motifs_list:
            gid, mname = mot.split(' ')
            pwmfile = self.temporary_path()
            g.get_motif_PWM(int(gid), mname, output=pwmfile)
            motifs[mname] = pwmfile

        if len(motifs) == 0:
            raise ValueError("Please give at least one motif to scan for")

        track_output = self.temporary_path(fname='motif_scan', ext="bed")
        with execution(None) as ex:
            save_motif_profile( ex, motifs, assembly, regions_file, fasta_file,
                                background=background, threshold=threshold,
                                output=track_output,
                                description=None, via='local' )
        self.new_file(track_output, 'motif_track')
        return self.display_time()
コード例 #3
0
ファイル: dnaseseq.py プロジェクト: JoseEspinosa/bbcflib
def motif_scan( ex, bedlist, assembly, groups, via, logfile ):
    logfile.write("Scanning motifs\n");logfile.flush()
    motifbeds = {}
    supdir = os.path.split(ex.remote_working_directory)[0]
    for gid,bedfile in bedlist.iteritems():
        logfile.write("\n%i: "%gid);logfile.flush()
        group = groups[gid]
        motifs = {}
        for mot in group.get('motif',[]):
            if os.path.exists(mot):
                mname = os.path.basename(os.path.splitext(mot)[0])
                motifs[mname] = mot
            elif os.path.exists(os.path.join(supdir,mot)):
                mname = os.path.basename(os.path.splitext(mot)[0])
                motifs[mname] = os.path.join(supdir,mot)
            else:
                _gnid, mname = mot.split(' ')
                motifs[mname] = _gnrp.get_motif_PWM(int(_gnid), mname, output=unique_filename_in())
            logfile.write(mname+", ");logfile.flush()
        _descr = set_file_descr(group['name']+'_motifs.bed',
                                type='bed', ucsc='1', step='motifs', groupId=gid)
        _out = unique_filename_in()
        _hd = "track name='%s_motifs'" %group['name']
        motifbeds[gid] = save_motif_profile( ex, motifs, assembly, bedfile,
                                             keep_max_only=True, output=_out,
                                             header=_hd, description=_descr, via=via )
    return motifbeds
コード例 #4
0
ファイル: dnaseseq.py プロジェクト: MolbioUnige/bbcflib
def motif_scan(ex, bedlist, assembly, groups, via, logfile):
    logfile.write("Scanning motifs\n")
    logfile.flush()
    motifbeds = {}
    supdir = os.path.split(ex.remote_working_directory)[0]
    for gid, bedfile in bedlist.iteritems():
        logfile.write("\n%i: " % gid)
        logfile.flush()
        group = groups[gid]
        motifs = {}
        for mot in group.get('motif', []):
            if os.path.exists(mot):
                mname = os.path.basename(os.path.splitext(mot)[0])
                motifs[mname] = mot
            elif os.path.exists(os.path.join(supdir, mot)):
                mname = os.path.basename(os.path.splitext(mot)[0])
                motifs[mname] = os.path.join(supdir, mot)
            else:
                _gnid, mname = mot.split(' ')
                motifs[mname] = _gnrp.get_motif_PWM(
                    int(_gnid), mname, output=unique_filename_in())
            logfile.write(mname + ", ")
            logfile.flush()
        _descr = set_file_descr(group['name'] + '_motifs.bed',
                                type='bed',
                                ucsc='1',
                                step='motifs',
                                groupId=gid)
        _out = unique_filename_in()
        _hd = "track name='%s_motifs'" % group['name']
        motifbeds[gid] = save_motif_profile(ex,
                                            motifs,
                                            assembly,
                                            bedfile,
                                            keep_max_only=True,
                                            output=_out,
                                            header=_hd,
                                            description=_descr,
                                            via=via)
    return motifbeds