Example #1
0
def question2():
    align_human = "HSGVNQLGGVFVNGRPLPDSTRQKIVELAHSGARPCDISRILQVSNGCVSKILGRYYETGSIRPRAIGGSKPRVATPEVVSKIAQYKRECPSIFAWEIRDRLLSEGVCTNDNIPSVSSINRVLRNLASEK-QQ".replace("-","")
    align_fruitfly = "HSGVNQLGGVFVGGRPLPDSTRQKIVELAHSGARPCDISRILQVSNGCVSKILGRYYETGSIRPRAIGGSKPRVATAEVVSKISQYKRECPSIFAWEIRDRLLQENVCTNDNIPSVSSINRVLRNLAAQKEQQ"
    
    consensus = read_protein(CONSENSUS_PAX_URL)
    
    scoring_matrix = read_scoring_matrix(PAM50_URL)
    
    alignment_matrix = compute_alignment_matrix(align_human, consensus, scoring_matrix, True)
    (score, align_human_consensus, align_consensus) = compute_global_alignment(align_human, consensus, scoring_matrix, alignment_matrix)
    
    print compare_sequence(align_human_consensus, align_consensus)
    print align_human_consensus
    print align_consensus
    
    print (score - 51.956) / 7.169
    
    
    alignment_matrix = compute_alignment_matrix(align_fruitfly, consensus, scoring_matrix, True)
    (score, align_fruitfly_consensus, align_consensus) = compute_global_alignment(align_fruitfly, consensus, scoring_matrix, alignment_matrix)
    
    print compare_sequence(align_fruitfly_consensus, align_consensus)
    print align_fruitfly_consensus
    print align_consensus
    
    print (score - 51.956) / 7.169
Example #2
0
def calculate_distance(checked_word, word, scoring_matrix):
    
    
    alignment_matrix = compute_alignment_matrix(checked_word, word, scoring_matrix, True)
    (score, _, _) = compute_global_alignment(checked_word, word, scoring_matrix, alignment_matrix)
    
    return len(checked_word) + len(word) - score
Example #3
0
 def test01(self):
     alphabet= "ACTG"
     matrix = build_scoring_matrix(alphabet, 10,4,-2)
     
     S = compute_alignment_matrix("AA", "TAAT", matrix, True)
     
     (score,x,y) = compute_global_alignment("AA", "TAAT", matrix, S)
     
     self.assertEqual(score,16)
     self.assertEquals(x,"-AA-")
     self.assertEquals(y,"TAAT")
Example #4
0
    def test01(self):
        alphabet = "ACTG"
        matrix = build_scoring_matrix(alphabet, 10, 4, -2)

        S = compute_alignment_matrix("AA", "TAAT", matrix, True)

        (score, x, y) = compute_global_alignment("AA", "TAAT", matrix, S)

        self.assertEqual(score, 16)
        self.assertEquals(x, "-AA-")
        self.assertEquals(y, "TAAT")
score_mat = seq_align.build_scoring_matrix(set(["A", "T", "G", "C"]), 10, -10, 0)


# In[33]:

seq_recs = SeqIO.parse("/Users/richard/Downloads/rosalind_lcsq.txt", "fasta")
seq_x, seq_y = [str(seq.seq) for seq in seq_recs]


# In[34]:

align_mat = seq_align.compute_alignment_matrix(seq_x, seq_y, score_mat, True)


# In[35]:

_, align1, align2 = seq_align.compute_global_alignment(seq_x, seq_y, score_mat, align_mat)
print align1
print align2


# In[36]:

res = "".join([align1[i] for i in range(len(align1)) if align1[i] != "-" and align2[i] != "-"])


# In[37]:

with open("/Users/richard/Downloads/output", "w") as file:
    file.write(res)