java - 计算 .maf 文件中发生突变的次数

标签 java python bioinformatics

我正在尝试计算 MAF 文件中的突变数量。我最初用 python 编写了这段代码,它工作得很好,但是当我将它翻译成 Java 时,它停止工作了。在输出文件中,突变数始终为 1。我在这里做错了什么?

package dev.suns.bioinformatics;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintWriter;

public class Main {

    static String filePath = "C:/Users/Matthew/Bioinformatics/Data Files/DLBC.maf";
    static String fileName = "DLBC_Info.txt";

public static void main(String[] args){
    createFile(filePath, fileName);
}

public static void createFile(String filePath, String fileName){
    BufferedReader br = null;
    String line = "";
    String delimiter = "\t";

    String geneSymbol = "";
    String newGene = "";
    int count;

    try {

        PrintWriter writer = new PrintWriter(fileName);
        br = new BufferedReader(new FileReader(filePath));

        writer.println("Gene" + "\t" + "Mutations" + "\n");

        br.readLine();

        while ((line = br.readLine()) != null){

            String[] splitFile = line.split(delimiter);
            newGene = splitFile[0];

            if(geneSymbol == ""){
                geneSymbol = newGene;   
            }

            else if(newGene == geneSymbol){
                #This is here I am having trouble. I have this if-statement to check if the gene appears more than once in the .maf file, but nothing is ever entering this.
                count++;
            }
            else{
                count++;
                writer.println(geneSymbol + "\t" + count + "\n");
                geneSymbol = newGene;
                count=0;
            }

        }
        writer.close();
    }catch(Exception e){
        e.printStackTrace();
    }
  }
}

这是文件的前几行内容

基因突变

A1CF 1

A2M 1

A2M 1

A2ML1 1

A4GALT 1

AADAC 1

AADACL3 1

AAED1 1

AAGAB 1

AAGAB 1

AARD 1

AARS2 1

AARS2 1

AARS2 1

最佳答案

在java中,您需要使用equals函数来比较字符串。这应该有效-

else if(newGene.equals(geneSymbol)){
            #This is here I am having trouble. I have this if-statement to check if the gene appears more than once in the .maf file, but nothing is ever entering this.
            count++;
        }

“==”检查引用。它们是否是相同的字符串对象。为了比较字符串的值,您需要使用 equals() 函数。

关于java - 计算 .maf 文件中发生突变的次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37770736/

相关文章:

python - 如何使用 python 或 R 将三个字母的氨基酸代码转换为一个字母的代码?

java - 当从每个循环内部删除 ArrayList 的一个元素时。它打破了循环

python - 列列表 X 整个数据框之间的 Pandas 相关性

java - JavaSE 有 WebSocket 消息监听器吗?

python - 在 C++ 中返回 vector 中元素的第一个索引

python - 减去列表中的当前项和上一项

linux - 在linux中将tab转换为fasta格式

python - 对于从 Python 向网站发送请求有什么建议吗?

java - 为什么我的 GUI 无法显示(通过 NetBeans 运行)

java - 单击单选按钮时如何显示时间选择器对话框?