Example #1
0
def main():

  print ps3a.countSubStringMatch(target, key)
  print ps3a.countSubStringMatchRecursive(target, key)
  print ps3b.subStringMatchExact(target,key)
  
  # for testing constrainedMatchPair(firstMatch, secondMatch, length)
  print ps3c.subStringMatchOneSub(key,target)
  
  print ps3d.subStringMatchExactlyOneSub(target,key)
Example #2
0
def subStringMatchOneSub(target, key):

    allmatches = ()

    for i in range(0,len(key)):
        keyone = key[:i]
        keytwo = key[i+1:]
        #print('\nRompiendo la key: ', key, 'en key1 = ', keyone, 'y key2 = ', keytwo)
        matchone = subStringMatchExact(target, keyone)
        matchtwo = subStringMatchExact(target, keytwo)
        #print('El primer match: ',matchone)
        #print('El segundo match: ',matchtwo)
        validmatch = constrainedMatchPair(matchone, matchtwo, len(keyone))
        allmatches = allmatches + validmatch
        #print('Posibles matches para sustituir', validmatch)

    return allmatches

#print('Las posibles sustituciones son en: ', subStringMatchOneSub('ATGACATGCACAAGTATGCAT','ATG'))
def subStringMatchExactlyOneSub(target, key):
    """ return a tuple of all starting points of matches of the key to the target, such that at exactly one element of the key is incorrectly matched to the target. """
    substring_match_exact = subStringMatchExact(target, key)
    substring_match_one_sub = subStringMatchOneSub(key, target)
    substring_match_exactly_one_sub = ()
    print substring_match_exact
    print substring_match_one_sub
    for index in substring_match_one_sub:
        if index not in substring_match_exact:
            substring_match_exactly_one_sub += (index, )
    return substring_match_exactly_one_sub
def subStringMatchExactlyOneSub(target, key):
    """ return a tuple of all starting points of matches of the key to the target, such that at exactly one element of the key is incorrectly matched to the target. """
    substring_match_exact = subStringMatchExact(target, key)
    substring_match_one_sub = subStringMatchOneSub(key, target)
    substring_match_exactly_one_sub = ()
    print substring_match_exact
    print substring_match_one_sub
    for index in substring_match_one_sub:
        if index not in substring_match_exact:
            substring_match_exactly_one_sub += (index,)
    return substring_match_exactly_one_sub
Example #5
0
def subStringMatchExactlyOneSub(target,key):
	exactMatch = subStringMatchExact(target, key)
	oneSub = subStringMatchOneSub(key,target)
	solution = ()
	for i in range(0, len(oneSub)):
		foundelement = False
		for j in range(0, len(exactMatch)):
			if exactMatch[j] == oneSub[i]: foundelement = True
		if foundelement == False:
			solution += (oneSub[i],)
	return solution
Example #6
0
def subStringMatchOneSub(key, target):
    """search for all locations of key in target, with one substitution"""
    allAnswers = ()
    for miss in range(0, len(key)):
        # miss picks location for missing element
        # key1 and key2 are substrings to match
        key1 = key[:miss]
        key2 = key[miss + 1:]
        ### print 'breaking key "%s" into "%s", "%s"' % (key, key1, key2)
        # match1 and match2 are tuples of locations of start of matches
        # for each substring in target
        match1 = subStringMatchExact(target, key1)
        match2 = subStringMatchExact(target, key2)
        # when we get here, we have two tuples of start points
        # need to filter pairs to decide which are correct
        filtered = constrainedMatchPair(match1, match2, len(key1))
        allAnswers = allAnswers + filtered
        ### print 'match1:', match1
        ### print 'match2:', match2
        ### print 'possible matches for "%s", "%s" start at:' % (key1, key2), filtered
    return allAnswers
def subStringMatchOneSub(key,target):
    """search for all locations of key in target, with one substitution"""
    allAnswers = ()
    for miss in range(0,len(key)):
        # miss picks location for missing element
        # key1 and key2 are substrings to match
        key1 = key[:miss]
        key2 = key[miss+1:]
        ### print 'breaking key "%s" into "%s", "%s"' % (key, key1, key2)
        # match1 and match2 are tuples of locations of start of matches
        # for each substring in target
        match1 = subStringMatchExact(target,key1)
        match2 = subStringMatchExact(target,key2)
        # when we get here, we have two tuples of start points
        # need to filter pairs to decide which are correct
        filtered = constrainedMatchPair(match1,match2,len(key1))
        allAnswers = allAnswers + filtered
        ### print 'match1:', match1
        ### print 'match2:', match2
        ### print 'possible matches for "%s", "%s" start at:' % (key1, key2), filtered
    return allAnswers
Example #8
0
def subStringMatchExactlyOneSub(target,key):
  
  exactMatch = ps3b.subStringMatchExact(target, key)
  allAnswers = ()
  for miss in range(0,len(key)):
    key1 = key[:miss]
    key2 = key[miss+1:]
    match1 = ps3b.subStringMatchExact(target,key1)
    match2 = ps3b.subStringMatchExact(target,key2)
    filtered = ps3c.constrainedMatchPair(match1,match2,len(key1))
    
    n = 0
    for i in filtered:
      for j in exactMatch:
        if i == j:
          filtered = filtered[:n] + filtered[n+1:]
          n -= 1
      n += 1
      
    allAnswers = allAnswers + filtered
  return allAnswers
Example #9
0
def subStringMatchOneSub(key, target):
    """search for all locations of key in target, with one substitution"""
    allAnswers = ()
    for miss in range(0, len(key)):
        # miss picks location for missing element
        # key1 and key2 are substrings to match
        key1 = key[:miss]
        key2 = key[miss + 1:]
        print('breaking key', key, 'into', key1, key2)
        # match1 and match2 are tuples of locations of start of matches
        # for each substring in target
        match1 = subStringMatchExact(target, key1)
        match2 = subStringMatchExact(target, key2)
        # when we get here, we have two tuples of start points
        # need to filter pairs to decide which are correct
        filtered = constrainedMatchPair(match1, match2, len(key1))
        allAnswers = allAnswers + (filtered, )
        print(target)
        print('match1', match1)
        print('match2', match2)
        print('possible matches for', key1, key2, 'start at', filtered)
    return allAnswers
Example #10
0
def subStringMatchExactlyOneSub(target,key):

    onesubstitution = ()
    perfectmatch = subStringMatchExact(target,key)
    #print(perfectmatch)
    possiblesubstitution = subStringMatchOneSub(target,key)
    #print(possiblesubstitution)


    for onesub in possiblesubstitution:
        if onesub in perfectmatch:
            pass
        else:
            onesubstitution = onesubstitution + (onesub,)

    return onesubstitution
Example #11
0
def subStringMatchExactlyOneSub(target, key):
    """ find those matched and with only substitution in target 
        return:
                a tuple contains the starting positions of substring in target, which can
                matchs the key string except for exactly one char
    """
    tuple_pairs = subStringMatchOneSub(key, target)
    print "all pairs: ", tuple_pairs
    fully_matched_pos = subStringMatchExact(target, key)
    print "matched_pos:", fully_matched_pos
    answer = ()
    for tuple_pair in tuple_pairs:
        start = list(tuple_pair).pop(0)
        if start in fully_matched_pos: 
            pass
        else:
            answer = answer + (start,)

    return answer