public void process ( String uniprotDatFileName , String fastaFileName ) throws Exception { FileReader fr = new FileReader ( uniprotDatFileName ) ; BufferedReader br = new BufferedReader ( fr ) ; String line = br . readLine ( ) ; String id = "" ; StringBuffer sequence = new StringBuffer ( ) ; ArrayList < ProteinSequence > seqCodingRegionsList = new ArrayList < ProteinSequence > ( ) ; int count = 0 ; HashMap < String , String > uniqueGenes = new HashMap < String , String > ( ) ; HashMap < String , String > uniqueSpecies = new HashMap < String , String > ( ) ; while ( line != null ) { if ( line . startsWith ( "ID" ) ) { String [ ] data = line . split ( " " ) ; id = data [ 3 ] ; } else if ( line . startsWith ( "SQ" ) ) { line = br . readLine ( ) ; while ( ! line . startsWith ( "//" ) ) { for ( int i = 0 ; i < line . length ( ) ; i ++ ) { char aa = line . charAt ( i ) ; if ( ( aa >= ' ' && aa <= ' ' ) || ( aa >= ' ' && aa <= ' ' ) ) { sequence . append ( aa ) ; } } line = br . readLine ( ) ; } // System.out.println(">" + id); // System.out.println(sequence.toString()); ProteinSequence seq = new ProteinSequence ( sequence . toString ( ) ) ; seq . setAccession ( new AccessionID ( id ) ) ; seqCodingRegionsList . add ( seq ) ; sequence = new StringBuffer ( ) ; count ++ ; if ( count % 100 == 0 ) logger . info ( "Count: " , count ) ; String [ ] parts = id . split ( "_" ) ; uniqueGenes . put ( parts [ 0 ] , "" ) ; uniqueSpecies . put ( parts [ 1 ] , "" ) ; } line = br . readLine ( ) ; } // System.out.println("Unique Genes=" + uniqueGenes.size()); // System.out.println("Unique Species=" + uniqueSpecies.size()); // System.out.println("Total sequences=" + seqCodingRegionsList.size()); FastaWriterHelper . writeProteinSequence ( new File ( fastaFileName ) , seqCodingRegionsList ) ; br . close ( ) ; fr . close ( ) ; // System.out.println(uniqueGenes.keySet()); // System.out.println("===================="); // System.out.println(uniqueSpecies.keySet()); }
Convert a Uniprot sequence file to a fasta file . Allows you to download all sequence data for a species and convert to fasta to be used in a blast database