示例#1
0
 def test_get_projects(self):
     """Test that getting the projects from a flowcell works
     """
     # Assert that an empty file returns an empty list
     fh, ssheet = tempfile.mkstemp(dir=self.rootdir, suffix=".csv")
     os.close(fh)
     self.assertListEqual([],sq.get_projects(ssheet),
                          "The list of projects for an empty file is not empty")
     
     # Generate artificial samplesheet data
     data = td.generate_samplesheet_data()
     projects = {}
     for d in data:
         projects[d[-1]] = 1
     
     # Write the data to a samplesheet
     td._write_samplesheet(data,ssheet)
      
     # Assert that the list of projects returned is the same that we generated
     self.assertListEqual(sorted(projects.keys()),sorted(sq.get_projects(ssheet)),
                          "The list of projects does not match the original list")
     
     # Assert that the list of projects returned is filtered as specified
     self.assertListEqual([projects.keys()[-1]],sq.get_projects(ssheet,projects.keys()[-1]),
                          "The filtered list of projects does not match the expected")
示例#2
0
 def test_parse_samplesheet(self):
     """Write and parse a csv-file
     """
     
     # Assert non-existing file raises exception
     with self.assertRaises(IOError):
         HiSeqRun.parse_samplesheet(os.path.join(self.rootdir,'non-existing-samplesheet'))
         
     # Write a csv file with some bogus values
     sdata = td.generate_samplesheet_data()
     samplesheet = os.path.join(self.rootdir,'SampleSheet.csv')
     HiSeqRun.write_samplesheet(sdata,samplesheet)
     
     # Assert that the written data corresponds to the generated data
     with open(samplesheet) as fh:
         # Assert that header is correct
         self.assertListEqual(HiSeqRun._samplesheet_header(),
                              fh.next().strip().split(","),
                              "Written header does not match expected header")
         for entry in sdata:
             # Assert that all rows have the correct values in the correct columns
             self.assertListEqual([str(e) for e in entry],
                                  fh.next().strip().split(","),
                                  "Written data row does not match entry in generated samplesheet")
         
         # Assert that all rows from samplesheet has been consumed
         with self.assertRaises(StopIteration):
             fh.next()
     
     # Assert that the parsed data matches the generated data
     data = HiSeqRun.parse_samplesheet(samplesheet)
     self.assertEqual(len(sdata),
                      len(data),
                      "Number of parsed entries does not match number of generated entries")
     for d in data:
         self.assertListEqual([str(e) for e in sdata.pop(0)],
                              [d[col] for col in HiSeqRun._samplesheet_header()],
                              "Parsed data row does not match entry in generated samplesheet")
         
     # Assert that filtering on lane returns expected output
     lanes = list(set([d["Lane"] for d in data]))
     obs_lane_data = HiSeqRun.parse_samplesheet(samplesheet,lane=lanes[-1])
     exp_lane_data = [d for d in data if str(d["Lane"]) == str(lanes[-1])]
     self.assertListEqual(sorted(obs_lane_data),
                          sorted(exp_lane_data),
                          "Parsed data row does not match entry in generated samplesheet")
示例#3
0
 def test_get_project_names(self):
     """Get the projects from a samplesheet
     """
     # Assert that an empty file returns an empty list
     fh, ssheet = tempfile.mkstemp(dir=self.rootdir, suffix=".csv")
     os.close(fh)
     self.assertListEqual([],HiSeqRun.get_project_names(ssheet),
                          "The list of projects for an empty file is not empty")
     
     # Generate artificial samplesheet data
     data = td.generate_samplesheet_data()
     projects = {}
     for d in data:
         projects[d[-1]] = 1
     
     # Write the data to a samplesheet
     td._write_samplesheet(data,ssheet)
      
     # Assert that the list of projects returned is the same that we generated
     self.assertListEqual(sorted(projects.keys()),sorted(HiSeqRun.get_project_names(ssheet)),
                          "The list of projects does not match the original list")
示例#4
0
 def test_get_project_samples(self):
     """Test that getting the project samples from a samplesheet behaves as expected
     """
     
     # Generate artificial samplesheet data
     data = td.generate_samplesheet_data()
     fh, ssheet = tempfile.mkstemp(dir=self.rootdir, suffix=".csv")
     os.close(fh)
     td._write_samplesheet(data,ssheet)
      
     # Assert that getting samples for a non-existing project returns an empty list
     self.assertListEqual([],sq.get_project_samples(ssheet,td.generate_project()),
                          "Getting samples for a non-existing project returned unexpected output")
     
     # Iterate over the projects and assert that the returned samples are correct
     samples = {}
     for row in data:
         if row[9] not in samples:
             samples[row[9]] = []
         samples[row[9]].append(row[2])
     
     for proj, sample in samples.items():
         self.assertListEqual(sorted(sample),sorted(sq.get_project_samples(ssheet,proj)),
                              "The returned list of samples did not match the original")