Exemplo n.º 1
0
 def testLCS(self):
     v = "AACCTTGG"
     w = "ACACTGTGA"
     
     s,b,ret = lcs(v, w)
     out = "AACTGG"
     
     assert  len(ret) == len(out)
Exemplo n.º 2
0
def globalAlign(v,w,sigma=5):
    
    s,backtrack,r =  lcs(v, w, 5, lambda x,y:blosum62[(x,y)])
    
    i = len(v)
    j = len(w)
    
    vv = []
    ww = []
    while i>0 or j >0:
        b = backtrack[i][j]
        print(b)
        if b == 'd':
            i = i-1
            vv.append(v[i])
            ww.append("-")
            
            
           
            
        elif b =='r':
            j = j-1
            ww.append(w[j])
            vv.append("-")
            
            
            
        else:
            i = i-1
            j=j-1
            vv.append(v[i])
            ww.append(w[j])
            
            
            
    return s,''.join(reversed(vv)),''.join(reversed(ww))
Exemplo n.º 3
0
	#------- Inicializa arquivo de entrada -------#
	pathToInput = sys.argv[1]
	inputFile = open(pathToInput, 'r')
	inputName = pathToInput.split('/')[-1]

	#------- leia entradas -------#
	genomeA = inputFile.readline().rstrip('\n').split()
	genomeB = inputFile.readline().rstrip('\n').split()

	#------- driver HYB -------#
	startTime = time.time()
	gatherMatches = []

	#lcs stands for longest common substring
	matchData = lcs(genomeA, genomeB)
	
	aux1, aux2 = genomeA, genomeB
	lisRemoved1, lisRemoved2 = [], []
	while(matchData):		
		aux1, aux2, matches = mark(aux1, aux2, matchData)
		matches = fixMatches(matches, lisRemoved1, lisRemoved2)
		gatherMatches.extend(matches)

		#removeUnmatchable is the key difference between ILCS and HYB
		aux1, aux2, lisRemoved1, lisRemoved2 = removeUnmatchable(aux1, aux2)
		#print '\ng1: %s\ng2: %s\nmatches: %r\n\n' % (aux1, aux2, matches)
		
		matchData = lcs(aux1, aux2)
		if not HYB_Condition(matchData):
			print 'Entrei no hyb_condition'
Exemplo n.º 4
0
if __name__ == '__main__':
    #------- Inicializa arquivo de entrada -------#
    pathToInput = sys.argv[1]
    inputFile = open(pathToInput, 'r')
    inputName = pathToInput.split('/')[-1]

    #------- leia entradas -------#
    genomeA = inputFile.readline().rstrip('\n').split()
    genomeB = inputFile.readline().rstrip('\n').split()

    #------- Processo - ILCS -------#
    startTime = time.time()
    gatherMatches = []

    #lcs stands for longest common substring
    matchData = lcs(genomeA, genomeB)

    auxGenome1, auxGenome2 = genomeA, genomeB
    while (matchData):

        auxGenome1, auxGenome2, matches = mark(auxGenome1, auxGenome2,
                                               matchData)
        #print '\ng1: %s\ng2: %s\nmatches: %r\n\n' % (auxGenome1, auxGenome2, matches)
        gatherMatches.extend(matches)
        matchData = lcs(auxGenome1, auxGenome2)

    # recstrings retorna uma lista de chrs unicos
    # recstrings soh recupera os mapeaveis, logo, exclui imapeaveis
    genomeA, genomeB = recStrings(gatherMatches)  #-> imprime na saida:

    genomeA = [str(ord(item)) for item in genomeA]
Exemplo n.º 5
0
def add_for_palindrome_LCS(string):
    LCS = lcs(string, string[::-1])
    return len(string) - LCS
Exemplo n.º 6
0
def lis(l):
    s1 = ''.join(str(i) for i in l)
    s2 = ''.join(sorted(s1))
    return lcs(s1, s2)