Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 计算.maf文件中发生突变的次数_Java_Python_Bioinformatics - Fatal编程技术网

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

Java 计算.maf文件中发生突变的次数,java,python,bioinformatics,Java,Python,Bioinformatics,我在计算MAF文件中的突变数。我最初是用python编写这段代码的,它工作得非常好,但当我将其翻译成Java时,它就停止了工作。在输出文件中,突变数始终为一。我做错了什么 package dev.suns.bioinformatics; import java.io.BufferedReader; import java.io.FileReader; import java.io.PrintWriter; public class Main { static String file

我在计算MAF文件中的突变数。我最初是用python编写这段代码的,它工作得非常好,但当我将其翻译成Java时,它就停止了工作。在输出文件中,突变数始终为一。我做错了什么

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

A2M1

A2M1

A2ML1

A4Alt 1

AADAC 1

AADACL3 1

AAED1

AAGAB 1

AAGAB 1

AARD 1

AARS21

AARS21


AARS21在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中,需要使用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()函数。

如果有效,请接受答案。单击向下箭头下方的右按钮。所以大家都很清楚这个问题已经得到了回答。哦,对不起,我是StackOverflow的新手。如果答案有效,请接受。单击向下箭头下方的右按钮。所以大家都很清楚这个问题已经得到了回答。对不起,我是新来的