Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f0772e

Browse files
authored
Merge pull request biojava#13 from roland-ewald/patch-1
Fix code snippet layout
2 parents 98816b9 + ce64bd1 commit 0f0772e

File tree

1 file changed

+49
-59
lines changed

1 file changed

+49
-59
lines changed

_wiki/BioJava_CookBook_Core_Overview.md

Lines changed: 49 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ We really want to make it easy to create a sequence and what could be
7272
easier than using a String.
7373

7474
```java
75-
76-
`           ProteinSequence proteinSequence = new ProteinSequence("ARNDCEQGHILKMFPSTWYVBZJX");`
77-
`           DNASequence dnaSequence = new DNASequence("ATCG");`
78-
75+
           ProteinSequence proteinSequence = new ProteinSequence("ARNDCEQGHILKMFPSTWYVBZJX");
76+
          DNASequence dnaSequence = new DNASequence("ATCG");
7977
```
8078

8179
The storage of the sequence data is defined by the Sequence interface
@@ -110,8 +108,8 @@ some level of api changes as we improve the overall design.
110108

111109
```java
112110

113-
`           UniprotProxySequenceReader`<AminoAcidCompound>` uniprotSequence = new UniprotProxySequenceReader`<AminoAcidCompound>`("YA745_GIBZE"AminoAcidCompoundSet.getAminoAcidCompoundSet());`
114-
`           ProteinSequence proteinSequence = new ProteinSequence(uniprotSequence);`
111+
           UniprotProxySequenceReader<AminoAcidCompound> uniprotSequence = new UniprotProxySequenceReader<AminoAcidCompound>("YA745_GIBZE"AminoAcidCompoundSet.getAminoAcidCompoundSet());
112+
           ProteinSequence proteinSequence = new ProteinSequence(uniprotSequence);
115113

116114
```
117115

@@ -124,17 +122,15 @@ but is very specific to learning the location of the sequence data in
124122
the file.
125123

126124
```java
127-
128-
`           File file = new File(inputFile);`
129-
`           FastaReader`<ProteinSequence,AminoAcidCompound>` fastaProxyReader = new FastaReader`<ProteinSequence,AminoAcidCompound>`(file, new GenericFastaHeaderParser`<ProteinSequence,AminoAcidCompound>`(), new FileProxyProteinSequenceCreator(file, AminoAcidCompoundSet.getAminoAcidCompoundSet()));`
130-
`           LinkedHashMap`<String,ProteinSequence>` proteinProxySequences = fastaProxyReader.process();`
131-
132-
`           for(String key : proteinProxySequences.keySet()){`
133-
`               ProteinSequence proteinSequence = proteinProxySequences.get(key);`
134-
`               System.out.println(key);`
135-
`               System.out.println(proteinSequence.toString());`
136-
`           }`
137-
125+
           File file = new File(inputFile);
126+
           FastaReader<ProteinSequence,AminoAcidCompound> fastaProxyReader = new FastaReader<ProteinSequence,AminoAcidCompound>(file, new GenericFastaHeaderParser<ProteinSequence,AminoAcidCompound>(), new FileProxyProteinSequenceCreator(file, AminoAcidCompoundSet.getAminoAcidCompoundSet()));
127+
           LinkedHashMap<String,ProteinSequence> proteinProxySequences = fastaProxyReader.process();
128+
129+
           for(String key : proteinProxySequences.keySet()){
130+
               ProteinSequence proteinSequence = proteinProxySequences.get(key);
131+
               System.out.println(key);
132+
               System.out.println(proteinSequence.toString());
133+
           }
138134
```
139135

140136
In the above example a FastaReader class is created where we abstract
@@ -171,10 +167,8 @@ code. The following code shows the use of FastaReaderHelper and
171167
FastaWriterHelper.
172168

173169
```java
174-
175-
`       LinkedHashMap`<String, DNASequence>` dnaSequences = FastaReaderHelper.readFastaDNASequence(new File("454Scaffolds.fna"));`
176-
`       FastaWriterHelper.writeNucleotideSequence(new File("454Scaffolds-1.fna"),dnaSequences.values());`
177-
170+
       LinkedHashMap<String, DNASequence> dnaSequences = FastaReaderHelper.readFastaDNASequence(new File("454Scaffolds.fna"));
171+
       FastaWriterHelper.writeNucleotideSequence(new File("454Scaffolds-1.fna"),dnaSequences.values());
178172
```
179173

180174
Working with Sequence Objects
@@ -204,17 +198,18 @@ Avoid using any kind of String method to do this since String operations
204198
are costly in BioJava (due to the String conversion that must be
205199
applied). Here is an example on how to do it for any Sequence object.
206200

207-
```java List<Sequence<AminoAcidCompound>\> translations =
201+
```java
202+
List<Sequence<AminoAcidCompound>> translations =
208203
populateFromSomewhere(); Collections.sort(translations, new
209-
Comparator<Sequence<? extends Compound>\>() {
210-
211-
`public int compare(Sequence`<? extends Compound>` o1Sequence`<? extends Compound>` o2) {`
212-
`  Integer o1Length = o1.getLength();`
213-
`  Integer o2Length = o2.getLength();`
214-
`  return o1Length.compareTo(o2Length);`
215-
`}`
216-
217-
}); ```
204+
Comparator<Sequence<? extends Compound>>() {
205+
206+
public int compare(Sequence<? extends Compound> o1Sequence<? extends Compound> o2) {
207+
  Integer o1Length = o1.getLength();
208+
  Integer o2Length = o2.getLength();
209+
  return o1Length.compareTo(o2Length);
210+
}
211+
});
212+
```
218213

219214
Note our usage of the generic type to capture Sequence objects of any
220215
type since the assessment of length is something which can be applied to
@@ -241,9 +236,7 @@ non-ambiguity CompoundSets with Codon table 1 in Frame 1 in the forward
241236
orientation.
242237

243238
```java
244-
245-
ProteinSequence protein = new DNASequence("ATG").getRNASequence().getProteinSequence();`
246-
239+
ProteinSequence protein = new DNASequence("ATG").getRNASequence().getProteinSequence();
247240
```
248241

249242
### Translating in a Different Frame
@@ -257,11 +250,9 @@ object when we request the RNA. Multiple frames of translations are
257250
possible but see later on.
258251

259252
```java
260-
261-
DNASequence dna = new DNASequence("AATG");`
262-
RNASequence rna = dna.getRNASequence(Frame.TWO);`
263-
ProteinSequence protein = rna.getProteinSequence();`
264-
253+
DNASequence dna = new DNASequence("AATG");
254+
RNASequence rna = dna.getRNASequence(Frame.TWO);
255+
ProteinSequence protein = rna.getProteinSequence();
265256
```
266257

267258
### Translating in Multiple Frames
@@ -273,10 +264,11 @@ translation in. The following example attempts to translate a sequence
273264
in all three forward frames. The code returns a map of the results keyed
274265
by their frame.
275266

276-
```java TranscriptionEngine te = TranscriptionEngine.getDefault();
267+
```java
268+
TranscriptionEngine te = TranscriptionEngine.getDefault();
277269
Frame[] frames = Frame.getForwardFrames();
278-
Map<Frame, Sequence<AminoAcidCompound>\> results =
279-
te.multipleFrameTranslation(dna, frames); ```
270+
Map<Frame, Sequence<AminoAcidCompound>> results = te.multipleFrameTranslation(dna, frames);
271+
```
280272

281273
Using this we can replicate the functionality found in EMBOSS' transeq
282274
package.
@@ -295,34 +287,32 @@ will build an engine to
295287
- Convert any initiating amino acid which is not methionine into one
296288
- Trim stops
297289

298-
```java TranscriptionEngine.Builder b = new
299-
TranscriptionEngine.Builder(); b.table(11).initMet(true).trimStop(true);
300-
TranscriptionEngine engine = b.build(); ```
290+
```java
291+
TranscriptionEngine.Builder b = new TranscriptionEngine.Builder();
292+
b.table(11).initMet(true).trimStop(true);
293+
TranscriptionEngine engine = b.build();
294+
```
301295

302296
This can be handed to the translation methods like so:
303297

304298
```java
305-
306-
` DNASequence dna = new DNASequence("ATG");`
307-
` RNASequence rna = dna.getRNASequence(engine);`
308-
` ProteinSequence protein = rna.getProteinSequence(engine);`
309-
299+
DNASequence dna = new DNASequence("ATG");
300+
RNASequence rna = dna.getRNASequence(engine);
301+
ProteinSequence protein = rna.getProteinSequence(engine);
310302
```
311303

312304
The translation can be started from the TranscriptionEngine directly
313305
except this results in more general objects (you will get back objects
314306
which implement the Sequence interface and not the true object type).
315307

316308
```java
317-
318-
` DNASequence dna = new DNASequence("ATG");`
319-
` TranscriptionEngine engine = TranscriptionEngine.getDefault(); //Get the default engine`
320-
` Sequence`<NucleotideCompound>` rna = engine.getDnaRnaTranslator().createSequence(dna);`
321-
` Sequence`<AminoAcidCompound>` protein = engine.getRnaAminoAcidTranslator().createSequence(rna);`
322-
` `
323-
` //Or to jump to it straight away use this method (coming soon)`
324-
` Sequence`<AminoAcidCompound>` protein = engine.translate(dna);`
325-
309+
DNASequence dna = new DNASequence("ATG");
310+
TranscriptionEngine engine = TranscriptionEngine.getDefault(); //Get the default engine
311+
Sequence<NucleotideCompound> rna = engine.getDnaRnaTranslator().createSequence(dna);
312+
Sequence<AminoAcidCompound> protein = engine.getRnaAminoAcidTranslator().createSequence(rna);
313+
314+
//Or to jump to it straight away use this method (coming soon)
315+
Sequence<AminoAcidCompound> protein = engine.translate(dna);
326316
```
327317

328318
### Codon Tables

0 commit comments

Comments
 (0)