Loading data

From Jstacs
Revision as of 12:21, 7 September 2008 by Grau (talk | contribs)
Jump to navigationJump to search

Loading DNA-sequences from a plain text file:

//create a DNA-alphabet
AlphabetContainer container = new AlphabetContainer( new DNAAlphabet() );
		
//create a Sample using the alphabet from above
Sample data = new Sample( container, new StringExtractor( new File("myfile.txt"), 100 )


Loading DNA-sequences from a FastA file:

//create a DNA-alphabet
AlphabetContainer container = new AlphabetContainer( new DNAAlphabet() );
		
//create a Sample using the alphabet from above in FastA-format
Sample data = new Sample( container, new StringExtractor( new File("myfile.txt"), 100, StringExtractor.FASTA )


Creating a Sample from a BioJava SequenceIterator:

//defining the ids, we want to obtain from NCBI Genbank:
Set<String> ids = new HashSet<String>();
ids.add( "NC_003070" );
ids.add( "NC_003071" );
		
GenbankRichSequenceDB db = new GenbankRichSequenceDB();
RichSequenceDB db2 = db.getRichSequences( ids );
//getting a SequenceIterator
SequenceIterator it = db2.sequenceIterator();
		
//conversion to Jstacs Sample
Sample data = BioJavaAdapter.sequenceIteratorToSample( it, null );