2 package org.forester.application;
4 import java.io.FileInputStream;
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import java.util.HashSet;
11 import org.forester.io.parsers.FastaParser;
12 import org.forester.msa.Msa;
13 import org.forester.sequence.BasicSequence;
14 import org.forester.sequence.Sequence;
15 import org.forester.util.ForesterUtil;
19 public static void main( final String args[] ) {
21 System.out.println( "STARTING..." );
22 final List<Sequence> orig = FastaParser
23 .parse( new FileInputStream( "C:\\Users\\zma\\Desktop\\RRMa_domains_ext_20.fasta" ) );
24 final Msa msa = FastaParser.parseMsa( new FileInputStream( "C:\\Users\\zma\\Desktop\\test3_sorted.fasta" ) );
25 final Set<Sequence> all_found_seqs = new HashSet<Sequence>();
26 for( int i = 0; i < msa.getNumberOfSequences(); ++i ) {
27 final String id = msa.getIdentifier( i );
28 final String id_ = id.substring( 0, id.indexOf( "_" ) );
29 final String range = id.substring( id.indexOf( "[" ) + 1, id.indexOf( "]" ) );
30 //System.out.println( i + ": " + id + "=>" + id_ + " " + range );
31 if ( ForesterUtil.isEmpty( id_ ) ) {
32 System.out.println( "ERROR: id is empty for: " + id );
35 if ( ForesterUtil.isEmpty( range ) ) {
36 System.out.println( "ERROR: range is empty for: " + id );
40 final List<Sequence> found_seqs = new ArrayList<Sequence>();
41 for( final Sequence orig_seq : orig ) {
42 final String orig_seq_id = orig_seq.getIdentifier();
43 if ( ( orig_seq_id.indexOf( id_ ) >= 0 ) && ( orig_seq_id.indexOf( "[" + range + "]" ) >= 0 ) ) {
45 found_seqs.add( orig_seq );
49 for( final Sequence found_seq : found_seqs ) {
50 if ( found_seq.getLength() >= 85 ) {
51 all_found_seqs.add( BasicSequence.createAaSequence( id, found_seq
52 .getMolecularSequenceAsString() ) );
56 System.out.println( i + ": " + id + "=>" + id_ + " " + range );
57 System.out.println( " found: " + found );
58 for( final Sequence found_seq : found_seqs ) {
59 System.out.println( found_seq.toString() );
64 System.out.println( "ERROR: not found: " + id );
68 final String fasta_ary[] = new String[ all_found_seqs.size() ];
70 for( final Sequence sequence : all_found_seqs ) {
71 fasta_ary[ i ] = ">" + sequence.getIdentifier() + "\n" + sequence.getMolecularSequenceAsString();
72 System.out.println( sequence );
75 Arrays.sort( fasta_ary );
76 for( final String element : fasta_ary ) {
77 System.out.println( element );
79 System.out.println( "DONE." );
81 catch ( final Exception e ) {