Loading data: Difference between revisions

From Jstacs
Jump to navigationJump to search
(New page: '''Loading DNA-sequences from a plain text file:''' <source lang="java"> //create a DNA-alphabet AlphabetContainer container = new AlphabetContainer( new DNAAlphabet() ); //create a Sam...)
 
No edit summary
 
(4 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">
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() );
//create a Sample using the alphabet from above in FastA-format
data = new Sample( container, new SparseStringExtractor( home+"myfile.fa", StringExtractor.FASTA ));
</source>
'''Loading DNA-sequences from a plain text file:'''
'''Loading DNA-sequences from a plain text file:'''
<source lang="java">
<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
Sample data = new Sample( container, new StringExtractor( new File("myfile.txt"), 100 )
data = new Sample( container, new SparseStringExtractor( home+"myfile.txt" ));
</source>
</source>


<hr />
'''Loading DNA-sequences from a FastA file:'''
<source lang="java">
//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 )
</source>


<hr />
'''Creating a Sample from a BioJava SequenceIterator:'''
'''Creating a Sample from a BioJava SequenceIterator:'''
<source lang="java">
<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>

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 );