1
我正在嘗試計算MAF文件中突變的數量。我最初在python中編寫了這段代碼,它工作得很好,但是當我將它轉換爲Java時,它停止工作。在輸出文件中,突變的數量總是一個。我在這裏做錯了什麼?計算突變發生在.maf文件中的次數
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
非常感謝!這工作! –
如果有效,請接受答案。點擊右下方的向下箭頭按鈕。所以人們很清楚這個問題已經得到解答。 – denis
糟糕對不起,我是新來的stackoverflow –