>1A3B:H|PDBID|CHAIN|SEQUENCE
IVEGSDAEIGMSPWQVMLFRKSPQELLCGASLISDRWVLTAAHCLLYPPWDKNFTENDLLVRIGKHSRTRYERNIEKISM
LEKIYIHPRYNWRENLDRDIALMKLKKPVAFSDYIHPVCLPDRETAASLLQAGYKGRVTGWGNLKETWTANVGKGQPSVL
QVVNLPIVERPVCKDSTRIRITDNMFCAGYKPDEGKRGDACEGDSGGPFVMKSPFNNRWYQMGIVSWGEGCDRDGKYGFY
THVFRLKKWIQKVIDQFGE
>1A3B:I|PDBID|CHAIN|SEQUENCE
GGQSHNDGDFEEIPEEYL
>1A3B:L|PDBID|CHAIN|SEQUENCE
TFGSGEADCGLRPLFEKKSLEDKTERELLESYIDGR
这是存储在文本文件中的数据。我如何去严格地提取数据之间
">1A3B:I|PDBID|CHAIN|SEQUENCE" and ">1A3B:L|PDBID|CHAIN|SEQUENCE",
当只有
">1A3B:I|PDBID|CHAIN|SEQUENCE"
我们都知道。
此外,在这个给定的示例中,虽然要检索的数据只有一行,但它也可以变化到多行。到目前为止,我尝试将文件的全部内容写入字符串变量并使用子字符串,但由于最终索引未知,该逻辑似乎存在缺陷。请帮忙
导入java.io.*;公共类 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); } } } }