>1A3B:H|PDBID|CHAIN|SEQUENCE
IVEGSDAEIGMSPWQVMLFRKSPQELLCGASLISDRWVLTAAHCLLYPPWDKNFTENDLLVRIGKHSRTRYERNIEKISM
LEKIYIHPRYNWRENLDRDIALMKLKKPVAFSDYIHPVCLPDRETAASLLQAGYKGRVTGWGNLKETWTANVGKGQPSVL
QVVNLPIVERPVCKDSTRIRITDNMFCAGYKPDEGKRGDACEGDSGGPFVMKSPFNNRWYQMGIVSWGEGCDRDGKYGFY
THVFRLKKWIQKVIDQFGE
>1A3B:I|PDBID|CHAIN|SEQUENCE
GGQSHNDGDFEEIPEEYL
>1A3B:L|PDBID|CHAIN|SEQUENCE
TFGSGEADCGLRPLFEKKSLEDKTERELLESYIDGR
这是存储在文本文件中的数据。我如何去提取数据严格间从JAVA文件中提取特定数据
">1A3B:I|PDBID|CHAIN|SEQUENCE" and ">1A3B:L|PDBID|CHAIN|SEQUENCE",
当只有
">1A3B:I|PDBID|CHAIN|SEQUENCE"
我们所知。
此外,在这个给出的例子中,虽然要检索的数据只有一行,但它也可以变化多达几行。 到目前为止,我尝试将文件的全部内容写入字符串变量并使用子字符串,但由于末尾索引未知,该逻辑似乎有缺陷。请帮忙
import 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); } } } }
请在问题中包含您的代码。 –
正则表达式是你的朋友 – Mark
什么意思_when只有'> 1A3B:I | PDBID | CHAIN | SEQUENCE'是我们所知道的._?你的意思是说你不知道结尾分隔符是什么?这部分没有意义。或者,您的意思是要提取的数据在''''下一行开始处结束? –