Hallo,
folgendes Problem:
Ich nutze in 2 verschiedenen Programmen split, verstehe aber nicht wo im Quelltext der Unterschied ist, dass ich ein unterschiedliches Ergebnis kriege...
Eingelesen wird ein FASTA-File der Art:
>seq
AGTGGG
>andereseq
GTAGTGA
Hier sehen die Einträge so aus:
>seq
ATGGTT
Hier sehen die Einträge so aus:
seq
ATGGG
Es fehlt also das führende ">" wodurch mein indexOf nicht mehr funktioniert. Ich könnte es einfach auf 0 setzen weil es ja das erste Zeichen ist, aber ich würde eben gerne verstehen warum da was unterschiedliches bei rauskommt???
Ich habe auch testweise genau die gleichen Files eingelesen, es liegt also nicht an der Eingabe.
Die Einleseroutine habe ich aus dem ersten Programm fürs zweite kopiert, auch hier sind also keine Unterschiede...
folgendes Problem:
Ich nutze in 2 verschiedenen Programmen split, verstehe aber nicht wo im Quelltext der Unterschied ist, dass ich ein unterschiedliches Ergebnis kriege...
Eingelesen wird ein FASTA-File der Art:
>seq
AGTGGG
>andereseq
GTAGTGA
Java:
/*Spliting the single entrys*/
final String NAMESTART_SYMBOL = ">"; /*The greater as symbol is in front of each
* name so substring can find the name using this*/
final String WHITESPACE = " "; //The first whitespace in the file is at the end of the name
String []entrys = file.split(NAMESTART_SYMBOL); //The arrayfield which will contain the entrys which where splited at the >
/*Gets the names of the sequences and puts them in the array seq_names*/
int number_of_entrys = entrys.length; /*Each field of the array contains
* one entry so the number of fields == number of entrys*/
//TODO: Container???
int wildtype_seq_position = use_of_mut_sides ? 0 : 1;
if(number_of_entrys < wildtype_seq_position+2) //Less than 2/3 (if no/there is mut_side_seq) sequences/entries are not legal as you need at least a wildtype and another for comparison
{
throw new IllegalArgumentException("Found too less sequences");
}
number_of_entrys--; /* split() fabricates a entry which only contains a newline.
* This one isn't used but is count so the arraybounds will set wrong without the -1*/
seq_names = new String[number_of_entrys]; //the field (seq_names) which gets the names
for(int i=1; i<=number_of_entrys;i++) //The entry[0] dosn't exist so the counter starts at 1
{
int start = entrys[i].indexOf(NAMESTART_SYMBOL); //Get the start of the name which contains ">"
//TODO: ERROR: No namestart_symbol found
int end = entrys[i].indexOf(WHITESPACE); //Get the end of the name which is at the first whitespace
//TODO: ERROR: No end of name/whitespace found
if(end <= -1) //If there was no whitespace for the end of entry found or an unlegal number comes up
{
throw new IllegalArgumentException("Found no entry-end");
}
seq_names[i-1] = entrys[i].substring(start+1, end); //Saves the name of the sequence
}
>seq
ATGGTT
Java:
final String NAMESTART_SYMBOL = ">";
String[] entries = file.split(NAMESTART_SYMBOL); //The arrayfield which will contain the entrys which where splited at the >
System.out.println(entries[1] + " " + entries[2]);
for(int i=1; i < entries.length; i++) {
int start = entries[i].indexOf(NAMESTART_SYMBOL); //Get the start of the name which contains ">"
int end = entries[i].indexOf(" "); //Get the end of the name which is at the first whitespace
System.out.println(start + " " + end);
// System.out.println(entries[i].substring(start, end));
}
}
seq
ATGGG
Es fehlt also das führende ">" wodurch mein indexOf nicht mehr funktioniert. Ich könnte es einfach auf 0 setzen weil es ja das erste Zeichen ist, aber ich würde eben gerne verstehen warum da was unterschiedliches bei rauskommt???
Ich habe auch testweise genau die gleichen Files eingelesen, es liegt also nicht an der Eingabe.
Die Einleseroutine habe ich aus dem ersten Programm fürs zweite kopiert, auch hier sind also keine Unterschiede...
Java:
/* Reading from the file*/
String file = null; //Will get the file
StringBuffer input = new StringBuffer();
String line = null; //Will get a single line of the file
try {
BufferedReader buffreader = new BufferedReader(new FileReader(file_name));
while ((line = buffreader.readLine()) != null) //read
file = (input.append(System.getProperty("line.separator")).append(line)).toString(); //and put it in the input
} catch (FileNotFoundException ex) {
System.err.println(ex);
ex.printStackTrace();
System.exit(-1);
} catch (IOException ex) {
System.err.println(ex);
ex.printStackTrace();
System.exit(-1);
}