Exemple #1
0
 def test_rotating_ramifier(self):
     stat_ram = StatisticalRam(31, 100)
     stat_ram.add_kmers_from_file(KMER_TABLE)
     centers = stat_ram.get_centers()
     scales = stat_ram.get_scales()
     rotation = stat_ram.get_rotation()
     rotater = RotatingRamifier(31, 8, rotation, centers, scales)
     rft = rotater.ramify('ATCGATCGATCGATCGATCGATCGATCGATC')
     self.assertTrue(rft.shape == (8, ))
Exemple #2
0
def calculate_pca_rotation(kmer_len, num_kmers, outfile, kmer_table):
    """Calculate a PCA rotation from a set of k-mers."""
    stat_ram = StatisticalRam(kmer_len, num_kmers)
    stat_ram.add_kmers_from_file(kmer_table)
    out = {
        'k': kmer_len,
        'center': stat_ram.get_centers().tolist(),
        'scale': stat_ram.get_scales().tolist(),
        'rotation': stat_ram.get_rotation().tolist(),
    }
    outfile.write(dumps(out))
Exemple #3
0
 def __init__(self, queries, targets, **kwargs):
     self.k = kwargs['k']
     self.sub_ks = kwargs['sub_ks']
     self.rft_dims = kwargs['rft_dims']
     stat_ram = StatisticalRam(self.k, len(targets))
     stat_ram.bulk_add_kmers(targets)
     self.rotation = {
         'center': stat_ram.get_centers(),
         'scale': stat_ram.get_scales(),
         'rotation': stat_ram.get_rotation(),
     }
     self.queries = queries
     self.targets = targets
Exemple #4
0
def calculate_pca_rotation_fasta(kmer_len, dropout, num_kmers, outfile,
                                 fasta_list):
    """Calculate a PCA rotation from a set of k-mers."""
    stat_ram = StatisticalRam(kmer_len, num_kmers)
    fasta_list = [line.strip() for line in fasta_list]
    with click.progressbar(fasta_list) as fastas:
        for fasta_filename in fastas:
            try:
                stat_ram.fast_add_kmers_from_fasta(fasta_filename,
                                                   dropout=dropout)
            except IndexError:
                break
    out = {
        'k': kmer_len,
        'center': stat_ram.get_centers().tolist(),
        'scale': stat_ram.get_scales().tolist(),
        'rotation': stat_ram.get_rotation().tolist(),
        'num_kmers': stat_ram.num_kmers_added,
    }
    click.echo(f'Built rotation with {stat_ram.num_kmers_added:,} k-mers.',
               err=True)
    outfile.write(dumps(out))
Exemple #5
0
 def test_rotation(self):
     stat_ram = StatisticalRam(31, 100)
     stat_ram.add_kmers_from_file(KMER_TABLE)
     rotation = stat_ram.get_rotation()
     self.assertTrue(rotation.shape == (4 * 31, 4 * 31))
Exemple #6
0
 def test_scales(self):
     stat_ram = StatisticalRam(31, 100)
     stat_ram.add_kmers_from_file(KMER_TABLE)
     scales = stat_ram.get_scales()
     self.assertTrue(scales.shape == (4 * 31, ))