Exemplo n.º 1
0
Arquivo: mcm.py Projeto: bsmithers/hpf
 def report(self, string):
     """Append a string to the report file"""
     if not self.report_file:
         from hpf.utilities.paths import ensure
         ensure(self.job)
         self.report_file = open(os.path.join(self.job,"report.txt"), "a")
     print >>self.report_file, string
Exemplo n.º 2
0
def gather():
    util.debug("Gathering result")
    job_results = results
    paths.ensure(job_results)

    #aazj00103_05.075_v1_3.bz2  zj001.fasta    zj001.psipred_ss2
    #aazj00109_05.075_v1_3.bz2  zj001.psipred
    aa_pattern = "aa" + name + "(03|09)\_05\.075\_v1\_3$"
    patterns = [aa_pattern]
    for suf in [".fasta", ".psipred", ".psipred_ss2"]:
        patterns.append(name + suf)

    try:
        for pattern in patterns:
            print "Pattern ", pattern
            match = paths.find(pattern, scr_job)
            if not match:
                raise "Missing file"
            for path in match:
                if pattern == aa_pattern:
                    print "Filtering Columns %s" % path
                    for line in fileinput.input(path, inplace=1):
                        print " " + line[:47].strip()
                    fileinput.close()
                print "Path ", path
                file = paths.getFile(path)
                dest = paths.join(job_results, file)
                util.copy(path, job_results)
                if pattern == aa_pattern:
                    util.system("bzip2 %s" % dest)
    except:
        paths.removerf(job_results)
        raise
Exemplo n.º 3
0
def gather():
    util.debug("Gathering result")
    job_results = results
    paths.ensure(job_results)
    
    
    #aazj00103_05.075_v1_3.bz2  zj001.fasta    zj001.psipred_ss2
    #aazj00109_05.075_v1_3.bz2  zj001.psipred
    aa_pattern = "aa"+name+"(03|09)\_05\.075\_v1\_3$"
    patterns = [aa_pattern]
    for suf in [".fasta", ".psipred", ".psipred_ss2"]:
        patterns.append(name+suf)
    
    try:
        for pattern in patterns:
            print "Pattern ",pattern
            match = paths.find(pattern, scr_job)
            if not match:
                raise "Missing file"
            for path in match:
                if pattern == aa_pattern:
                    print "Filtering Columns %s" % path
                    for line in fileinput.input(path, inplace=1):
                        print " "+line[:47].strip()
                    fileinput.close()
                print "Path ", path
                file = paths.getFile(path)
                dest = paths.join(job_results, file)
                util.copy(path, job_results)
                if pattern == aa_pattern:
                    util.system("bzip2 %s"  % dest)
    except:
        paths.removerf(job_results)
        raise
Exemplo n.º 4
0
 def __enter__(self):
     from hpf.utilities.paths import ensure
     ensure(self.scratch)
     self.session = Session()
     runtime().debug("Loading outfile")
     self.filesystem_outfile = self.session.query(FilesystemOutfile).filter(FilesystemOutfile.prediction_code==self.prediction_code).first()
     runtime().debug("Loading sequence")
     self.sequence = self.session.query(Sequence).get(self.filesystem_outfile.sequence_key)
     debug(self.prediction_code,self.filesystem_outfile,self.sequence)
     return self
Exemplo n.º 5
0
Arquivo: mcm.py Projeto: bsmithers/hpf
 def _replicate(self):
     """Copy input files to the job directory ins scratch"""
     global scr_job
     from hpf.utilities.paths import ensure
     ensure(self.job)
     self.decoy_file = self._extract(self.decoy_file)
     if not self.decoy_file.endswith(".out"):
         destination = self.decoy_file+".out"
         shutil.move(self.decoy_file, destination)
         self.decoy_file = destination
     self.psipred_file = self._extract(self.psipred_file)
Exemplo n.º 6
0
def gather():
    global code, task_id

    utilities.debug("Gathering result")
    paths.ensure(results_dir)
    
    # Contents of results directory (3' library, 9' library, fasta, psipred, and psipred_ss2 files). EG:
    #aazj00103_05.075_v1_3.bz2  zj001.fasta    zj001.psipred_ss2
    #aazj00109_05.075_v1_3.bz2  zj001.psipred
    
    # Set "patterns" for results files.
    aa_pattern = "aa"+code+task_id+"(03|09)\_05\.075\_v1\_3$"
    patterns = [aa_pattern]
    for suf in [".fasta", ".psipred", ".psipred_ss2"]:
        patterns.append(code+task_id+suf)
    
    try:
        for pattern in patterns:
            print "Pattern ",pattern
            
            # Find the results file in scr_job_dir
            match = paths.find(pattern, scr_job_dir)
            
            # If a results file matching pattern is not found in the scr_jobs_dir, raise exception.
            if not match:
                raise "Missing file"
            
            # Copy all results files in scr_job_dir to results_dir. 
            for path in match:
                # If the results file is a frag library, format the frag library file.
                if pattern == aa_pattern:
                    print "Filtering Columns of file %s" % path
                    # fileinput.input opens a file for iteration. Defining inplace=1 allows to given file to be
                    # altered "in place": file is backed up, and stdout is then directed to the file. 
                    # Filters the file: writes " " + first 47 chars of the line. (Specific formatting).
                    for line in fileinput.input(path, inplace=1):
                        print " "+line[:47].strip()
                    fileinput.close()
                print "Path ", path
                
                # Copy the result file to results_dir.
                utilities.copy(path, results_dir)
                
                # If the results file is a frag library, bzip it in the results_dir.
                if pattern == aa_pattern:
                    dest = paths.join(results_dir, paths.getFile(path))
                    utilities.system("bzip2 %s"  % dest)
                    
    # If gathering the results files fails, delete the results_dir and exit.
    except:
        paths.removerf(results_dir)
        raise
Exemplo n.º 7
0
def gather():
    global code, task_id

    utilities.debug("Gathering result")
    paths.ensure(results_dir)

    # Contents of results directory (3' library, 9' library, fasta, psipred, and psipred_ss2 files). EG:
    #aazj00103_05.075_v1_3.bz2  zj001.fasta    zj001.psipred_ss2
    #aazj00109_05.075_v1_3.bz2  zj001.psipred

    # Set "patterns" for results files.
    aa_pattern = "aa" + code + task_id + "(03|09)\_05\.075\_v1\_3$"
    patterns = [aa_pattern]
    for suf in [".fasta", ".psipred", ".psipred_ss2"]:
        patterns.append(code + task_id + suf)

    try:
        for pattern in patterns:
            print "Pattern ", pattern

            # Find the results file in scr_job_dir
            match = paths.find(pattern, scr_job_dir)

            # If a results file matching pattern is not found in the scr_jobs_dir, raise exception.
            if not match:
                raise "Missing file"

            # Copy all results files in scr_job_dir to results_dir.
            for path in match:
                # If the results file is a frag library, format the frag library file.
                if pattern == aa_pattern:
                    print "Filtering Columns of file %s" % path
                    # fileinput.input opens a file for iteration. Defining inplace=1 allows to given file to be
                    # altered "in place": file is backed up, and stdout is then directed to the file.
                    # Filters the file: writes " " + first 47 chars of the line. (Specific formatting).
                    for line in fileinput.input(path, inplace=1):
                        print " " + line[:47].strip()
                    fileinput.close()
                print "Path ", path

                # Copy the result file to results_dir.
                utilities.copy(path, results_dir)

                # If the results file is a frag library, bzip it in the results_dir.
                if pattern == aa_pattern:
                    dest = paths.join(results_dir, paths.getFile(path))
                    utilities.system("bzip2 %s" % dest)

    # If gathering the results files fails, delete the results_dir and exit.
    except:
        paths.removerf(results_dir)
        raise
Exemplo n.º 8
0
Arquivo: mcm.py Projeto: bsmithers/hpf
 def _gather(self):
     """Gather result files and report text file."""
     from hpf.utilities.paths import ensure, find
     scr_results_dir = self.decoy_file+".p"
     results = os.path.join(self.results,self.job_name)
     ensure(results)
     # Using the full filename will ensure the directory is created.
     shutil.copy(os.path.join(scr_results_dir, "log.xml"), results)
     
     decoys = list(find("decoy\_[0-9]+\.pdb",dir=scr_results_dir))
     assert len(decoys)>0
     for decoy in decoys:
         shutil.copy(decoy, results)
     shutil.copy(os.path.join(self.job, "report.txt"), results)
Exemplo n.º 9
0
    def _dir_setup(self): 
        # Create results and working directories.
        paths.ensure(self.results_dir)
        paths.ensure(self.working_dir)
        
        #try:
        #    os.makedirs(self.results_dir)
        #    os.makedirs(self.working_dir)
        #except OSError as e:
        #    print e.errno, e.strerror
        #    raise

        # Change directory to working directory.
        os.chdir(self.working_dir)
Exemplo n.º 10
0
    def run(self):
        from hpf.utilities.paths import ensure
        
        if self.filesystem_outfile.executable_key==179:
            runtime().debug("HPF1 format",self.filesystem_outfile)
            _format = self.hpf1
        else:
            runtime().debug("HPF2 format",self.filesystem_outfile)
            _format = self.hpf2

        debug("Using decoy format",_format)
        self.decoy = format(_format, self.prediction_code)
        if not os.path.exists(self.decoy):
            debug("NO DECOY FILE",self.prediction_code,self.decoy)
            #return None
        else:
            self.destination = os.path.join(self.scratch,os.path.basename(self.decoy))
            if not os.path.exists(self.destination):
                ensure(os.path.join(self.scratch,self.prediction_code))
                self.decoy = self._decoy()
            else:
                debug("exists",self.destination)
                self.decoy = self.destination
        
        self.psipred = os.path.join(self.scratch,self.prediction_code,self.prediction_code+".psipred")
        if not os.path.exists(self.psipred):
            ensure(os.path.join(self.scratch,self.prediction_code))
            self.psipred = self._ss()
        else:
            debug("exists",self.psipred)

        if all(map(os.path.exists,[self.decoy,self.psipred])):
            runtime().debug("Exported",(self.decoy,self.psipred))
            return (self.decoy,self.psipred)
        else:
            runtime().debug("Failed to export")
            return None
Exemplo n.º 11
0
def replicate():

    # Create scr_job_dir
    paths.ensure(scr_job_dir)
    replicate_fasta()
Exemplo n.º 12
0
def replicate():
    paths.ensure(scr_job)
    replicate_fasta()
Exemplo n.º 13
0
def replicate():
    paths.ensure(scr_job)
    replicate_fasta()
Exemplo n.º 14
0
def replicate():

    # Create scr_job_dir
    paths.ensure(scr_job_dir)
    replicate_fasta()