def setUp(self):
     aligner = PairwiseAligner()
     aligner.internal_open_gap_score = -1
     aligner.internal_extend_gap_score = -0.0
     aligner.match_score = +1
     aligner.mismatch_score = -1
     aligner.mode = "local"
     self.aligner = aligner
Example #2
0
def bioPython_default_local_aligner(a, b):
    aligner = PairwiseAligner()
    aligner.mode = 'local'
    aligner.match_score = 2
    aligner.mismatch_score = -3
    aligner.open_gap_score = -7
    aligner.extend_gap_score = -2

    sequence1 = SeqIO.read('./resource/fasta' + str(a) + '.fasta', 'fasta')
    sequence2 = SeqIO.read('./resource/fasta' + str(b) + '.fasta', 'fasta')
    alignments = aligner.align(sequence1.seq, sequence2.seq)
Example #3
0
def nw_bio(seq1, seq2, cost_table):
    aligner = PairwiseAligner(alphabet=list(set(seq1 + seq2)))
    aligner.match_score = cost_table[0]
    aligner.mismatch_score = cost_table[1]
    aligner.gap_score = cost_table[2]
    alignments = aligner.align(seq1, seq2)
    formated_alignments = []

    for i in range(len(alignments)):
        als = str(alignments[i]).split("\n")
        formated_alignments.append([als[0], als[2], int(alignments[i].score)])

    return formated_alignments
Example #4
0
def create_aligner() -> PairwiseAligner:
    """
    Creates an aligner that can be used to search for proteins.
    """
    aligner = PairwiseAligner(mode="local")

    # By default we want matches and penalize mismatches.
    aligner.mismatch_score = -1
    aligner.match_score = 1

    # left or right gaps shouldn't count negatively due to the local search.
    aligner.query_left_gap_score = 0
    aligner.query_right_gap_score = 0
    aligner.target_right_gap_score = 0
    aligner.target_left_gap_score = 0

    # Gaps in the middle should count negatively to narrow down the search space.
    aligner.query_internal_gap_score = -1
    aligner.target_internal_gap_score = -1

    return aligner
def perform_randomized_tests(n=1000):
    """Perform randomized tests and compare to pslMap.

    Run this function to perform 8 x n mappings for alignments of randomly
    generated sequences, get the alignment in PSL format, and compare the
    result to that of pslMap.
    """
    aligner = PairwiseAligner()
    aligner.internal_open_gap_score = -1
    aligner.internal_extend_gap_score = -0.0
    aligner.match_score = +1
    aligner.mismatch_score = -1
    aligner.mode = "local"
    for i in range(n):
        nBlocks1 = random.randint(1, 10)
        nBlocks2 = random.randint(1, 10)
        test_random(aligner, nBlocks1, nBlocks2, "+", "+")
        test_random(aligner, nBlocks1, nBlocks2, "+", "-")
        test_random(aligner, nBlocks1, nBlocks2, "-", "+")
        test_random(aligner, nBlocks1, nBlocks2, "-", "-")
        test_random_sequences("+", "+")
        test_random_sequences("+", "-")
        test_random_sequences("-", "+")
        test_random_sequences("-", "-")
Example #6
0
                    type=str,
                    required=True)

parser.add_argument('-r',
                    '--reference',
                    help='Reference to be aligned to',
                    type=str,
                    required=True)

parser.add_argument('-n',
                    '--seq_name',
                    help='Name of the aligned sequence',
                    type=str,
                    required=True)

args = parser.parse_args()

aligner = PairwiseAligner()
aligner.mode = 'global'
aligner.match_score = 1
aligner.mismatch_score = 0
aligner.open_gap_score = -2
aligner.extend_gap_score = -1

ref = SeqIO.read(args.reference, "fasta")
ref.seq = str(ref.seq.upper()).replace('-', 'N')
cons = SeqIO.read(args.infile, "fasta")
aln = aligner.align(ref.seq, cons.seq)
with open(args.outfile, 'w') as out:
    print(">", args.seq_name, file=out)
    print(str(aln[0]).strip().split('\n')[2], file=out)