2016-06-12 6 views
1

MAFファイルの突然変異の数を数えようとしています。私はもともとPythonでこのコードを書いていましたが、それは完璧に機能しましたが、Javaに変換すると機能が停止しました。出力ファイルでは、突然変異の数は常に1です。私はここで間違って何をしていますか?ここで .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

Javaで

AARS2 1

AARS2 1

答えて

0

あなたは等号の機能を使用して文字列を比較する必要があります。これはうまくいくはずです -

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()関数を使用する必要があります。

+0

ありがとうございました!それはうまくいった! –

+0

答えがあれば受け入れてください。下の矢印をクリックしてください。だから、この質問が答えられたことは人々には明らかです。 – denis

+0

申し訳ありません、私は新しいstackoverflowです –

関連する問題