Ejemplo n.º 1
0
    def test_make_random_contigs(self):
        '''Test make_random_contigs()'''
        # Can't guarantee same results from random (even using same seed), so
        # just check sequence names and lengths
        def files_are_equal(file1, file2):
            seqs1 = {}
            seqs2 = {}
            tasks.file_to_dict(file1, seqs1)
            tasks.file_to_dict(file2, seqs2)
            if len(seqs1) != len(seqs2):
                return False

            for name in seqs1:
                seq1 = seqs1[name]
                seq2 = seqs2[name]
                if seq1.id != seq2.id:
                    return False
                if len(seq1) != len(seq2):
                    return False

            return True

        tmp = 'tmp.random_contigs.fa'
        tasks.make_random_contigs(2, 3, tmp)
        self.assertTrue(files_are_equal(os.path.join(data_dir, 'sequences_test_make_random_contigs.default.fa'), tmp))
        tasks.make_random_contigs(2, 3, tmp, prefix='p')
        self.assertTrue(files_are_equal(os.path.join(data_dir, 'sequences_test_make_random_contigs.prefix-p.fa'), tmp))
        tasks.make_random_contigs(2, 3, tmp, first_number=42)
        self.assertTrue(files_are_equal(os.path.join(data_dir, 'sequences_test_make_random_contigs.first-42.fa'), tmp))
        tasks.make_random_contigs(28, 3, tmp, name_by_letters=True)
        self.assertTrue(files_are_equal(os.path.join(data_dir, 'sequences_test_make_random_contigs.name-by-letters.fa'), tmp))
        os.unlink(tmp)
Ejemplo n.º 2
0
    def test_make_random_contigs(self):
        '''Test make_random_contigs()'''
        # Can't guarantee same results from random (even using same seed), so
        # just check sequence names and lengths
        def files_are_equal(file1, file2):
            seqs1 = {}
            seqs2 = {}
            tasks.file_to_dict(file1, seqs1)
            tasks.file_to_dict(file2, seqs2)
            if len(seqs1) != len(seqs2):
                return False

            for name in seqs1:
                seq1 = seqs1[name]
                seq2 = seqs2[name]
                if seq1.id != seq2.id:
                    return False
                if len(seq1) != len(seq2):
                    return False

            return True

        tmp = 'tmp.random_contigs.fa'
        tasks.make_random_contigs(2, 3, tmp)
        self.assertTrue(files_are_equal(os.path.join(data_dir, 'sequences_test_make_random_contigs.default.fa'), tmp))
        tasks.make_random_contigs(2, 3, tmp, prefix='p')
        self.assertTrue(files_are_equal(os.path.join(data_dir, 'sequences_test_make_random_contigs.prefix-p.fa'), tmp))
        tasks.make_random_contigs(2, 3, tmp, first_number=42)
        self.assertTrue(files_are_equal(os.path.join(data_dir, 'sequences_test_make_random_contigs.first-42.fa'), tmp))
        tasks.make_random_contigs(28, 3, tmp, name_by_letters=True)
        self.assertTrue(files_are_equal(os.path.join(data_dir, 'sequences_test_make_random_contigs.name-by-letters.fa'), tmp))
        os.unlink(tmp)
Ejemplo n.º 3
0
def run(description):
    parser = argparse.ArgumentParser(
        description = 'Makes a multi-FASTA file of random sequences, all of the same length. Each base has equal chance of being A,C,G or T',
        usage = 'fastaq make_random_contigs [options] <contigs> <length> <outfile>')
    parser.add_argument('--first_number', type=int, help='If numbering the sequences, the first sequence gets this number [%(default)s]', default=1)
    parser.add_argument('--name_by_letters', action='store_true', help='Name the contigs A,B,C,... will start at A again if you get to Z')
    parser.add_argument('--prefix', help='Prefix to add to start of every sequence name', default='')
    parser.add_argument('--seed', type=int, help='Seed for random number generator. Default is to use python\'s default', default=None)
    parser.add_argument('contigs', type=int, help='Nunber of contigs to make')
    parser.add_argument('length', type=int, help='Length of each contig')
    parser.add_argument('outfile', help='Name of output file')
    options = parser.parse_args()
    tasks.make_random_contigs(
        options.contigs,
        options.length,
        options.outfile,
        name_by_letters=options.name_by_letters,
        prefix=options.prefix,
        seed=options.seed,
        first_number=options.first_number
    )