Loading data: Difference between revisions

From Jstacs
Jump to navigationJump to search
No edit summary
No edit summary
Line 22: Line 22:
<source lang="java5">
<source lang="java5">
//defining the ids, we want to obtain from NCBI Genbank:
//defining the ids, we want to obtain from NCBI Genbank:
Set<String> ids = new HashSet<String>();
GenbankRichSequenceDB db = new GenbankRichSequenceDB();
ids.add( "NC_003070" );
ids.add( "NC_003071" );
GenbankRichSequenceDB db = new GenbankRichSequenceDB();
SimpleSequenceIterator it = new SimpleSequenceIterator(
RichSequenceDB db2 = db.getRichSequences( ids );
db.getRichSequence( "NC_001284.2" ),
//getting a SequenceIterator
db.getRichSequence( "NC_000932.1" )
SequenceIterator it = db2.sequenceIterator();
);
//conversion to Jstacs Sample
//conversion to Jstacs Sample
Sample data = BioJavaAdapter.sequenceIteratorToSample( it, null );
Sample data = BioJavaAdapter.sequenceIteratorToSample( it, null );
</source>
</source>

Revision as of 09:29, 29 October 2008

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:
GenbankRichSequenceDB db = new GenbankRichSequenceDB();
		
SimpleSequenceIterator it = new SimpleSequenceIterator(
		db.getRichSequence( "NC_001284.2" ),
		db.getRichSequence( "NC_000932.1" )
	);
		
//conversion to Jstacs Sample
Sample data = BioJavaAdapter.sequenceIteratorToSample( it, null );