Ejemplo n.º 1
0
 def test_distance_pep_google(self):
     vector = bbc.create_vectors(self.pep_records, 10, utils.ALPHABET_PEP)
     dist = bbc.Distance(vector, 'google')
     matrix = distmatrix.create(self.pep_records.id_list, dist)
     exp = [
         "   4", "seq1       0.0000000 862.9400129 912.1886801 233.2058119",
         "seq2       862.9400129 0.0000000 694.9729647 237.9720958",
         "seq3       912.1886801 694.9729647 0.0000000 225.2262758",
         "seq4       233.2058119 237.9720958 225.2262758 0.0000000"
     ]
     self.assertEqual(matrix.format(), "\n".join(exp))
Ejemplo n.º 2
0
def main():
    parser = get_parser()
    args = validate_args(parser)

    seq_records = seqrecords.read_fasta(args.fasta)
    vector = bbc.create_vectors(seq_records, args.k, alphabet=args.alphabet)
    dist = bbc.Distance(vector)
    matrix = distmatrix.create(seq_records.id_list, dist)

    if args.out:
        oh = open(args.out, 'w')
        matrix.write_to_file(oh, args.outfmt)
        oh.close()
    else:
        matrix.display(args.outfmt)
Ejemplo n.º 3
0
if len(sys.argv) > 4:
    sys.stderr.write("Too many arguments\n")
    exit(1)
else:
    method = sys.argv[1]
    infile = sys.argv[2]
    outfile = sys.argv[3]

input_file = open(infile, 'r')
seq_records = seqrecords.read_fasta(input_file)
input_file.close()

#choose one method to compute distance matrix
if method == "bbc":
    alphabet = seqcontent.get_alphabet('protein')
    vector = bbc.create_vectors(seq_records, 10, alphabet)
    dist = bbc.Distance(vector)
    matrix = distmatrix.create(seq_records.id_list, dist)
    matrix.display()

elif method == "ncd":
    dist = ncd.Distance(seq_records)
    matrix = distmatrix.create(seq_records.id_list, dist)
    matrix.display()

elif method == "wmetric":
    matrix = subsmat.get('blosum62')
    dist = wmetric.Distance(seq_records, matrix)
    matrix = distmatrix.create(seq_records.id_list, dist)
    matrix.display()
Ejemplo n.º 4
0
 def test_create_vectors_on_pep_k1(self):
     vec = bbc.create_vectors(self.pep_records, 1, utils.ALPHABET_PEP)
     md5 = utils.calc_md5(vec)
     self.assertEqual(vec.shape, (4, 400))
     self.assertEqual(md5, 'd901d93d0d71102d0727633a67fc14a3')
Ejemplo n.º 5
0
 def test_create_vectors_on_dna_k1(self):
     vec = bbc.create_vectors(self.dna_records, 1, utils.ALPHABET_DNA)
     md5 = utils.calc_md5(vec)
     self.assertEqual(vec.shape, (3, 16))
     self.assertEqual(md5, 'e99bc40356b00e04fd858a665af597ec')
Ejemplo n.º 6
0
 def __init__(self, *args, **kwargs):
     super(DistanceTest, self).__init__(*args, **kwargs)
     utils.ModulesCommonTest.set_test_data()
     self.vector = bbc.create_vectors(self.dna_records, 10,
                                      utils.ALPHABET_DNA)
Ejemplo n.º 7
0
 def test_create_vectors_throws_exception(self):
     with self.assertRaises(Exception) as context:
         bbc.create_vectors(self.dna_records, 60, utils.ALPHABET_DNA)
     self.assertIn('Sequence too short', str(context.exception))