Esempio n. 1
0
def replicate_fasta():
    
    if not paths.exists(scr_fasta):
        utilities.debug("Replicating fasta file")
        utilities.copy(fasta_file, scr_fasta)
        
    paths.existsOrFail(scr_fasta)
Esempio 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
Esempio 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
Esempio n. 4
0
def replicate_fasta():

    if not paths.exists(scr_fasta):
        utilities.debug("Replicating fasta file")
        utilities.copy(fasta_file, scr_fasta)

    paths.existsOrFail(scr_fasta)
Esempio n. 5
0
def replicate_fasta():
    global scr_fasta
    
    file = paths.getFile(fasta_file)
    scr_fasta = paths.join(scr_job, file)
    if not paths.exists(scr_fasta):
        util.debug("Replicating fasta file")
        util.copy(fasta_file, scr_fasta)
        
    paths.existsOrFail(scr_fasta)
Esempio n. 6
0
def replicate_fasta():
    global scr_fasta

    file = paths.getFile(fasta_file)
    scr_fasta = paths.join(scr_job, file)
    if not paths.exists(scr_fasta):
        util.debug("Replicating fasta file")
        util.copy(fasta_file, scr_fasta)

    paths.existsOrFail(scr_fasta)
Esempio 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
Esempio n. 8
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
Esempio n. 9
0
 def _gather_results(self):
 # Move all results files to results directory and update instance variable values to reflect 
 # new location.
     
     for res in self.results_files:
         copy(res, self.results_dir)
     
     self.frag3_lib = os.path.join(self.results_dir, os.path.basename(self.frag3_lib))
     self.frag9_lib = os.path.join(self.results_dir, os.path.basename(self.frag9_lib))
     self.frag_psipred  = os.path.join(self.results_dir, os.path.basename(self.frag_psipred))
     self.frag_psipred2 = os.path.join(self.results_dir, os.path.basename(self.frag_psipred2))
     self.frag_fasta    = os.path.join(self.results_dir, os.path.basename(self.frag_fasta))
     
     self.results_files = [self.frag3_lib, self.frag9_lib, self.frag_psipred, self.frag_psipred2, self.frag_fasta]
Esempio n. 10
0
 def run(self, nohoms=False, cleanup=True):
     
     try:
         # Populate environment with tool & DB locations (req'ed by make_fragments.local.pl).
         print "Fragmentor - run: set environment"
         self._set_env()
         
         # Create working and results directory structures, and move into working directory.
         print "Fragmentor - run:set directories"
         self._dir_setup()
         
         # Copy fasta file to working directory, set as working_fasta_file.
         print "Fragmentor - run: copy fasta files to working dir"
         copy(self.fasta_file, self.working_dir)
         working_fasta_file = os.path.join(self.working_dir, os.path.basename(self.fasta_file))
         
         # Run make_fragments script (treat as a black box).
         print "Fragmentor - run: run frag script"
         self._run_frag(nohoms, working_fasta_file)
         
         # Check for results files and set results instance variables.
         print "Fragmentor - run: set results variables and structure"
         self._set_results()
         
         # Filter 3' and 9' fragment library results (cut column size, bzip files).
         print "Fragmentor - run: filter fragment libs"
         self._filter_fraglibs()
         
         # Gather results (move all files to results directory).
         print "Fragmentor - run: gather results"
         self._gather_results()
     
     except:
         print "\nFragment picking failed. Exiting.\n"
         raise
     
     finally:    
         if cleanup:
             # Clean up work files and finish.
             self.cleanup()
     
     print "\nFragment picking completed successfully\n"