1A3B:H|PDBID|CHAIN|SEQUENCE IVEGSDAEIGMSPWQVMLFRKSPQELLCGASLISDRWVLTAAHCLLYPPWDKNFTENDLLVRIGKHSRTRYERNIEKISM LEKIYIHPRYNWRENLDRDIALMKLKKPVAFSDYIHPVCLPDRETAASLLQAGYKGRVTGWGNLKETWTANVGKGQPSVL QVVNLPIVERPVCKDSTRIRITDNMFCAGYKPDEGKRGDACEGDSGGPFVMKSPFNNRWYQMGIVSWGEGCDRDGKYGFY THVFRLKKWIQKVIDQFGE 1A3B:I|PDBID|CHAIN|SEQUENCE GGQSHNDGDFEEIPEEYL 1A3B:L|PDBID|CHAIN|SEQUENCE TFGSGEADCGLRPLFEKKSLEDKTERELLESYIDGR
This is the data which is stored in a text file. How do i go about extracting the fasta sequence strictly between
">1A3B:I|PDBID|CHAIN|SEQUENCE" and ">1A3B:L|PDBID|CHAIN|SEQUENCE", when only
">1A3B:I|PDBID|CHAIN|SEQUENCE" is known to us.
Also, in this given example though the sequence to be retrieved is only of one line, it can vary upto many lines too. So far, i tried writing the entire content of the file to a string variable and using substring, but that logic seems to be flawed as the ending delimiter's index is unknown. Please help
import java.io.*;
public class ReadingChainSpecificFastaSequence {
public static void main(String[] args) {
File file = new File("1A3B.fasta.txt");
BufferedInputStream bin = null;
try
{
FileInputStream fin = new FileInputStream(file);
bin = new BufferedInputStream(fin);
byte[] contents = new byte[1024];
int bytesRead=0;
String strFileContents=null;
while( (bytesRead = bin.read(contents)) != -1){
strFileContents = new String(contents, 0, bytesRead);
}
// System.out.print(strFileContents);
String search = ">1A3B:I|PDBID|CHAIN|SEQUENCE";
int start = (strFileContents.indexOf(search))+30;
String search2= ">1A3B:L|PDBID|CHAIN|SEQUENCE";
int end= (strFileContents.indexOf(search2));
String result = strFileContents.substring(start,end);
}
catch(FileNotFoundException e)
{
System.out.println("File not found" + e);
}
catch(IOException ioe)
{
System.out.println("Exception while reading the file "+ ioe);
}
finally
{
try{
if(bin != null)
bin.close();
}catch(IOException ioe)
{
System.out.println("Error while closing thestream:"+ioe);
}
}
}
}
0 answers
No answers yet.
Log in to answer this question.
This looks like a homework question, especial as two similar questions posted by different accounts. Nice try! You deserved your downvote! I can't downvote? Great I close!