def trim(run):
    # (re) create the trim status file
    run.trim_status_file_h = open(run.trim_status_file_name, "w")
    # do the trim work
    mytrim = TrimRun(run)        
    # pass True to write out the straight fasta file of all trimmed non-deleted seqs
    # Remember: this is before chimera checking
    trim_codes = mytrim.trimrun(True)
    trim_results_dict = {}
    if trim_codes[0] == 'SUCCESS':
        # setup to write the status
        new_lane_keys = trim_codes[2]
        trim_results_dict['status'] = "success"
        trim_results_dict['new_lane_keys'] = new_lane_keys
        logger.debug("Trimming finished successfully")
        # write the data files
        mytrim.write_data_files(new_lane_keys)
        run.trim_status_file_h.write(json.dumps(trim_results_dict))
        run.trim_status_file_h.close()
    else:
        logger.debug("Trimming finished ERROR")
        trim_results_dict['status'] = "error"
        trim_results_dict['code1'] = trim_codes[1]
        trim_results_dict['code2'] = trim_codes[2]
        run.trim_status_file_h.write(json.dumps(trim_results_dict))
        run.trim_status_file_h.close()
        sys.exit()
示例#2
0
class TestTrimFunctions(unittest.TestCase):

    def setUp(self):
        """

        set up data used in the tests.

        setUp is called before each test function execution.

        """
        
        args = unittestargs()
        run = Run('./unittesting/unittest10.ini')
        self.unittest_trimrun = TrimRun(run,'./unittesting',args)
        trim_code = self.unittest_trimrun.trimrun()
        self.id1 = 'GFADN4I02JYSYM' 
        self.seq1 = 'CGTGATGGGCGTAAAGTGGGTTTAAAGGGTGCGTAGGCGGATTTATAAGTCAGTGGTGAAAGCCTGCGGCTCAACCGTAG\
AATTGCCATTGATACTGTAGATCTTGAGTGCAATCGAGGTGGTTGGAATACGTAGTGTAGCTGTGAAATGCATAGATATTACGTAGAACACC\
AATTGCGAAGGCAGATCACTAGATTGTAACTGACGCTGAGGCACGAAAGCGTGGGGAGCGAACAGGATTAGATACCCTGGTAGTCCACGCCG\
TAAACGATGGATACTAGGTGTTCGGGATAATTGAGTCCTGAGTGCCCAAGCGAAAGCGATAAGTATCCCACCTGGGGAGTACGTCCGCAAGG\
ATGAAACTCAAAGGAATTGACGGGGGCCCGCACAAGCGGTGGAGCATGTGGTTTAATTCGATGATACGCGAGGAACCTTACCTGGGCTAAAT\
GTTAGTGACGTACCGTGAAAGCGGTATTTCTTCGGACACGAAACA'
        self.trim_info1 = self.unittest_trimrun.do_trim(self.id1,self.seq1)
        
        # proximal deleted:
        self.id2 = 'GFADN4I02HD8KF'
        self.seq2 = 'TGGGCCAACGCGAAAAACCTTACCTCGGAGGTTACCCCCTTCGGTGCCGCAGCTAACGCATTAAGTACTCCG\
CCTGGGGAGTACGCACGCAAGTGTGAAACTCAAAGGAATTGACGGGGACCCGCACAAGTAGCGGAGCATGTGGTTTAATTCGAAGCAACGCGAA\
GAACCTTACCTAGGCTTGACATCCTTCTGACCGAGGATTAATCTCCTCAGGTGGTGCATGGGCTGTCG'
        self.trim_info2 = self.unittest_trimrun.do_trim(self.id2,self.seq2)
        
        # deleted for key:
        self.id3 = 'GFADN4I02HD8KF'
        self.seq3 = 'TGGCCAACGCGAAAAACCTTACCTCGGAGGTTACCCCCTTCGGTGCCGCAGCTAACGCATTAAGTACTCCG\
CCTGGGGAGTACGCACGCAAGTGTGAAACTCAAAGGAATTGACGGGGACCCGCACAAGTAGCGGAGCATGTGGTTTAATTCGAAGCAACGCGAA\
GAACCTTACCTAGGCTTGACATCCTTCTGACCGAGGATTAATCTCCTCAGGTGGTGCATGGGCTGTCG'
        self.trim_info3 = self.unittest_trimrun.do_trim(self.id3,self.seq3)
        
        # deleted for N:
        self.id4 = 'GFADN4I02JYSYM'
        self.seq4 = 'CGTGATGGGCGTAAAGTGGGTTTAAAGGGTGCGTAGGCGGATTTATAAGTCAGTGGTGAAAGCCTGCGGCTCAACCGTAG\
AATTGCCATTGATACTGTAGATCTTGAGTGCAATCGAGGTGGTTGGAATACGTAGTGTAGCTGTGAAATGCATAGATATTACGTAGAACACC\
AATTGCGAAGGCAGATCACTAGATTGTAACTGACGCTGAGGCACGAAAGCGTGGGGAGCGAACAGGATTAGATACCCTGGTAGTCCACGCCG\
TAAACGATGGATACTAGGTGTTCGGGATAATTGAGTCCNTGAGTGCCCAAGCGAAAGCGATAAGTATCCCACCTGGGGAGTACGTCCGCAAGG\
ATGAAACTCAAAGGAATTGACGGGGGCCCGCACAAGCGGTGGAGCATGTGGTTTAATTCGATGATACGCGAGGAACCTTACCTGGGCTAAAT\
GTTAGTGACGTACCGTGAAAGCGGTATTTCTTCGGACACGAAACA'
        self.trim_info4 = self.unittest_trimrun.do_trim(self.id4,self.seq4)
        
        # deleted for distal:
        self.id5 = 'GFADN4I02I64C9'
        self.seq5 = 'TGGGCTGGGCGTAAAGCGAAGGGTGCGTAGGCGGATTTATAAGTCAGTGGTGAAAGCCTGCGGCTCAACCGTAGAATTG\
CCATTGATACTGTAGATCTTGAGTGCAATCGAGGTTTTGGTTGGAATACGTAGTGTAGCGGTGAAATGCATAGATATTACGTAGAACACCAATTGCGAAGGCA\
GATCACTAGATTGTAACTGACGCTGAGGCACGAAAGCGTGGGGAGCGAACAGGATTAGATACCCTGGTAGTCCACGCCGTAAACGATGGATACTAGGTGT\
TCGGGATAATTGAGTCCTGAGTGCCCAAGCGAAAGCGATAAGTATCCCACCTGGGGAGTACGTCCGCAAGGATGAAACTCAAAGGAATTGACGGGGGCCC\
GCACAAGCGGTGGAGCATGTGGTTTAATTCGATGATACGCGAGGAACCTTACCTGGGCTAAATGTTAGT'
        self.trim_info5 = self.unittest_trimrun.do_trim(self.id5,self.seq5)
        
        
        
    def test_lane_key(self):        
        self.assertEqual(self.trim_info1['lane_key'],'1_CGTGA')
    
    def test_primer_name(self):        
        self.assertEqual(self.trim_info1['primer_name'],'565F')
        
    def test_eaxct_right(self):        
        self.assertEqual(self.trim_info1['exact_right'],'AGGTGGT')
        
    def test_exact_left(self):        
        self.assertEqual(self.trim_info1['exact_left'],'TGGGCGTAAAG')
        
    def test_deleted(self):        
        self.assertEqual(self.trim_info1['deleted'],False)  
        
    def test_orientation(self):        
        self.assertEqual(self.trim_info1['orientation'],'+')     
    
    ####################################################################
    def test_deleted_proximal(self):        
        self.assertEqual(self.trim_info2['deleted'],True)  
        self.assertEqual(self.trim_info2['delete_reason'],'proximal')
        
    def test_deleted_key(self):        
        self.assertEqual(self.trim_info3['deleted'],True)  
        self.assertEqual(self.trim_info3['delete_reason'],'runkey')   
        
    def test_deleted_N(self):        
        self.assertEqual(self.trim_info4['deleted'],True)  
        self.assertEqual(self.trim_info4['delete_reason'],'N')
        
    def test_deleted_distal(self):    
        print self.trim_info5
        self.assertEqual(self.trim_info5['deleted'],True)  
        self.assertEqual(self.trim_info5['delete_reason'],'distal')