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;
10 import java.util.TreeSet;
12 import org.forester.io.parsers.FastaParser;
13 import org.forester.msa.Msa;
14 import org.forester.sequence.BasicSequence;
15 import org.forester.sequence.Sequence;
16 import org.forester.util.ForesterUtil;
20 public static void main( final String args[] ) {
22 System.out.println( "STARTING..." );
23 final List<Sequence> orig = FastaParser
24 .parse( new FileInputStream( "C:\\Users\\zma\\Desktop\\RRMa_domains_ext_20.fasta" ) );
25 final Msa msa = FastaParser.parseMsa( new FileInputStream( "C:\\Users\\zma\\Desktop\\test3_sorted.fasta" ) );
26 final Set<Sequence> all_found_seqs = new HashSet<Sequence>();
27 for( int i = 0; i < msa.getNumberOfSequences(); ++i ) {
28 final String id = msa.getIdentifier( i );
29 final String id_ = id.substring( 0, id.indexOf( "_" ) );
30 final String range = id.substring( id.indexOf( "[" ) + 1, id.indexOf( "]" ) );
31 //System.out.println( i + ": " + id + "=>" + id_ + " " + range );
32 if ( ForesterUtil.isEmpty( id_ ) ) {
33 System.out.println( "ERROR: id is empty for: " + id );
36 if ( ForesterUtil.isEmpty( range ) ) {
37 System.out.println( "ERROR: range is empty for: " + id );
41 final List<Sequence> found_seqs = new ArrayList<Sequence>();
42 for( final Sequence orig_seq : orig ) {
43 final String orig_seq_id = orig_seq.getIdentifier();
44 if ( orig_seq_id.indexOf( id_ ) >= 0 && orig_seq_id.indexOf( "[" + range + "]" ) >= 0 ) {
46 found_seqs.add( orig_seq );
50 for( final Sequence found_seq : found_seqs ) {
51 if ( found_seq.getLength() >= 85 ) {
53 all_found_seqs.add( BasicSequence.createAaSequence( id, found_seq.getMolecularSequenceAsString() ) );
57 System.out.println( i + ": " + id + "=>" + id_ + " " + range );
58 System.out.println( " found: " + found );
59 for( final Sequence found_seq : found_seqs ) {
60 System.out.println( found_seq.toString() );
65 System.out.println( "ERROR: not found: " + id );
69 String fasta_ary[] = new String[ all_found_seqs.size() ];
71 for( Sequence sequence : all_found_seqs ) {
72 fasta_ary[ i ] = ">" + sequence.getIdentifier() + "\n" + sequence.getMolecularSequenceAsString();
73 System.out.println( sequence );
76 Arrays.sort( fasta_ary );
78 for( int j = 0; j < fasta_ary.length; ++j ) {
79 System.out.println( fasta_ary[ j ] );
82 System.out.println( "DONE." );
84 catch ( final Exception e ) {