0
点赞
收藏
分享

微信扫一扫

Rosalind Java| Counting Point Mutations

是归人不是过客 2022-02-13 阅读 54

Rosalind编程问题之计数核酸序列突变数。

Counting Point Mutations

Problem
Given two strings s and t of equal length, the Hamming distance between s and t, denoted dH(s,t), is the number of corresponding symbols that differ in s and t. See Figure 2.

Figure 2
Figure 2. The Hamming distance between these two strings is 7. Mismatched symbols are colored red.

Given: Two DNA strings s and t of equal length (not exceeding 1 kbp).
Sample input

Return: The Hamming distance dH(s,t).

题目引入了一个名词——汉明距离。汉明距离是以理查德·卫斯里·汉明的名字命名的,表示两个相同长度字符对应位不同的数量,通常以d(x,y)表示两个字x,y之间的汉明距离。而针对本题而言,两个序列的汉明距离就是对应位置碱基不同的位置个数。因此我们计算两个核苷酸数量相等的序列中,相同位置处碱基不同的位置个数。

整体思路比较简单:逐一比对两个序列中相同位置的字符,如若不等则累计一个突变数mutation,最终输出计数总数。

import java.util.Scanner;

public class Counting_Point_Mutations {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入核酸序列1:");
        String line1 = sc.nextLine();//将序列1存储到字符串类型对象line1中。

        Scanner cs = new Scanner(System.in);
        System.out.println("请输入核酸序列2:");
        String line2 = cs.nextLine();//将序列2存储到字符串类型对象line2中。
        System.out.println(countMut(line1,line2));

    }
	
	//定义计数突变数的方法:输入数据为两个字符串类型的核酸序列,返回整数型突变数。
    public static int countMut(String line1, String line2){
        int mutation = 0;
        for (int n =0; n< line1.length();n++){
            if (line1.charAt(n)!=line2.charAt(n)){//遍历文本字符并逐一比较。
                mutation++;
            }
        }
        return mutation;
    }
}

举报

相关推荐

0 条评论