Loading data: Difference between revisions
From Jstacs
Jump to navigationJump to search
No edit summary |
No edit summary |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
''' | '''Most simple way for loading DNA-sequences from a FastA file:''' | ||
<source lang="java5"> | <source lang="java5"> | ||
//create a DNA-alphabet | Sample data = new DNASample( home+"myfile.fa" ); | ||
</source> | |||
'''Loading DNA-sequences from a FastA file:''' | |||
<source lang="java5">//create a DNA-alphabet | |||
AlphabetContainer container = new AlphabetContainer( new DNAAlphabet() ); | AlphabetContainer container = new AlphabetContainer( new DNAAlphabet() ); | ||
//create a Sample using the alphabet from above | //create a Sample using the alphabet from above in FastA-format | ||
data = new Sample( container, new SparseStringExtractor( home+"myfile.fa", StringExtractor.FASTA )); | |||
</source> | </source> | ||
'''Loading DNA-sequences from a plain text file:''' | |||
'''Loading DNA-sequences from a | |||
<source lang="java5"> | <source lang="java5"> | ||
//create a DNA-alphabet | //create a DNA-alphabet | ||
AlphabetContainer container = new AlphabetContainer( new DNAAlphabet() ); | AlphabetContainer container = new AlphabetContainer( new DNAAlphabet() ); | ||
//create a Sample using the alphabet from above | //create a Sample using the alphabet from above | ||
data = new Sample( container, new SparseStringExtractor( home+"myfile.txt" )); | |||
</source> | </source> | ||
Line 22: | Line 25: | ||
<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: | ||
GenbankRichSequenceDB db = new GenbankRichSequenceDB(); | |||
SimpleSequenceIterator it = new SimpleSequenceIterator( | |||
db.getRichSequence( "NC_001284.2" ), | |||
db.getRichSequence( "NC_000932.1" ) | |||
); | |||
//conversion to Jstacs Sample | //conversion to Jstacs Sample | ||
Sample data = BioJavaAdapter.sequenceIteratorToSample( it, null ); | Sample data = BioJavaAdapter.sequenceIteratorToSample( it, null ); | ||
</source> | </source> |
Latest revision as of 13:46, 2 December 2009
Most simple way for loading DNA-sequences from a FastA file:
Sample data = new DNASample( home+"myfile.fa" );
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
data = new Sample( container, new SparseStringExtractor( home+"myfile.fa", StringExtractor.FASTA ));
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
data = new Sample( container, new SparseStringExtractor( home+"myfile.txt" ));
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 );