Skip to content

Commit ce2c56f

Browse files
committed
More manual fixes
1 parent 23e9d32 commit ce2c56f

File tree

1 file changed

+86
-78
lines changed

1 file changed

+86
-78
lines changed

_wikis/BioJava:CookBook3:Stockholm.md

Lines changed: 86 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -14,97 +14,105 @@ multiple structure objects file, or an InputStream.
1414

1515
### To read a single object from a file, you can simply write
1616

17-
```java public static void main(String[] args){
18-
19-
`   try {`
20-
`       StockholmFileParser parser = new StockholmFileParser();`
21-
`       String pathName= "stockholmFilePathAndName";`
22-
`       StockholmStructure structure = parser.parse(pathName);`
23-
`           `
24-
`       //use read structures`
25-
`           `
26-
`   } catch (IOException e) {`
27-
`       e.printStackTrace();`
28-
`   } catch (Exception e) {`
29-
`       e.printStackTrace();`
30-
`   }`
31-
32-
} ```
17+
```java
18+
public static void main(String[] args){
19+
20+
   try {
21+
       StockholmFileParser parser = new StockholmFileParser();
22+
       String pathName= "stockholmFilePathAndName";
23+
       StockholmStructure structure = parser.parse(pathName);
24+
           
25+
       //use read structures
26+
           
27+
   } catch (IOException e) {
28+
       e.printStackTrace();
29+
   } catch (Exception e) {
30+
       e.printStackTrace();
31+
   }
32+
33+
}
34+
```
3335

3436
### Also you can read multiple alignments within the same file as follows
3537

36-
```java public static void main(String[] args){
37-
38-
`   try {`
39-
`       StockholmFileParser parser = new StockholmFileParser();`
40-
`       String sourcePath=settingsManager.getSourcePath();`
41-
`       String fileName= settingsManager.getFileName();`
42-
`       FileInputStream inStream = new FileInputStream(new File(sourcePath,fileName));`
43-
`       String outputPath=settingsManager.getOutputPath();`
44-
`       parser.parse(inStream,STRUCTURES_TO_SKIP);//if you don't want to start from first structure`
45-
`       do {`
46-
`           structures = parser.parse(inStream, MAX_PER_ITERATION);`
47-
`           for (int i = 0; i < structures.size(); i++) {`
48-
`               StockholmStructure structure = structures.get(i);`
49-
`               List`<AbstractSequence<? extends AbstractCompound>`> sequences = structure.getBioSequences(true);`
50-
`               final String accessionNumber = structure.getFileAnnotation().getAccessionNumber();`
51-
`               final String identification = structure.getFileAnnotation().getIdentification().toString();`
52-
`               manageRelatedSequences(accessionNumber, identification,sequences);`
53-
`           }`
54-
`       } while (structures.size()== MAX_PER_ITERATION);`
55-
`   } catch (FileNotFoundException e) {`
56-
`       e.printStackTrace();`
57-
`   } catch (IOException e) {`
58-
`       e.printStackTrace();`
59-
`   } catch (Exception e) {`
60-
`       e.printStackTrace();`
61-
`   }`
62-
63-
} ```
38+
```java
39+
public static void main(String[] args){
40+
41+
   try {
42+
       StockholmFileParser parser = new StockholmFileParser();
43+
       String sourcePath=settingsManager.getSourcePath();
44+
       String fileName= settingsManager.getFileName();
45+
       FileInputStream inStream = new FileInputStream(new File(sourcePath,fileName));
46+
       String outputPath=settingsManager.getOutputPath();
47+
       parser.parse(inStream,STRUCTURES_TO_SKIP);//if you don't want to start from first structure
48+
       do {
49+
           structures = parser.parse(inStream, MAX_PER_ITERATION);
50+
           for (int i = 0; i < structures.size(); i++) {
51+
               StockholmStructure structure = structures.get(i);
52+
               List<AbstractSequence<? extends AbstractCompound>> sequences = structure.getBioSequences(true);
53+
               final String accessionNumber = structure.getFileAnnotation().getAccessionNumber();
54+
               final String identification = structure.getFileAnnotation().getIdentification().toString();
55+
               manageRelatedSequences(accessionNumber, identification,sequences);
56+
           }
57+
       } while (structures.size()== MAX_PER_ITERATION);
58+
   } catch (FileNotFoundException e) {
59+
       e.printStackTrace();
60+
   } catch (IOException e) {
61+
       e.printStackTrace();
62+
   } catch (Exception e) {
63+
       e.printStackTrace();
64+
   }
65+
66+
}
67+
```
6468

6569
### Some times you don't have a reference to the file or input stream
6670

6771
Some times you use the parser in a place other than where it was
6872
created.
6973

70-
For example, you can create a StockholmFileParser in a function ```java
74+
For example, you can create a StockholmFileParser in a function
75+
76+
```java
7177

72-
`   public StockholmFileParser getStockholmFileParser(String filePathName) {`
73-
`       StockholmFileParser parser = new StockholmFileParser();`
74-
`       try {`
75-
`           parser.parse(filePathName, 0);`
76-
`       } catch (ParserException e) {`
77-
`           e.printStackTrace();`
78-
`       } catch (IOException e) {`
79-
`           e.printStackTrace();`
80-
`       }`
81-
`       return parser;`
82-
`   }`
78+
   public StockholmFileParser getStockholmFileParser(String filePathName) {
79+
       StockholmFileParser parser = new StockholmFileParser();
80+
       try {
81+
           parser.parse(filePathName, 0);
82+
       } catch (ParserException e) {
83+
           e.printStackTrace();
84+
       } catch (IOException e) {
85+
           e.printStackTrace();
86+
       }
87+
       return parser;
88+
   }
8389

8490
```
8591

8692
Then you use the created parser in another function, where you don't
87-
have a reference to its underling data source ```java
88-
89-
`   public void useParser(StockholmFileParser parser) {`
90-
`       final int MAX_PER_ITTERATION = 10;`
91-
`       List`<StockholmStructure>` structures;`
92-
`       long count= 0;`
93-
`       int successfullyRead = 0;`
94-
`       do {`
95-
`           try {`
96-
`               structures = parser.parseNext(MAX_PER_ITTERATION);`
97-
`               successfullyRead = structures.size();`
98-
`           } catch (IOException e) {`
99-
`               e.printStackTrace();`
100-
`           }`
101-
`           count += successfullyRead;`
102-
`           System.out.println("reached "+count);`
103-
`           `
104-
`           //use read structures`
105-
`           `
106-
`       } while (successfullyRead== MAX_PER_ITTERATION);`
107-
`       System.out.println("TOTAL COUNT = "+count);`
108-
`   }`
93+
have a reference to its underling data source
94+
95+
```java
96+
97+
   public void useParser(StockholmFileParser parser) {
98+
       final int MAX_PER_ITTERATION = 10;
99+
       List<StockholmStructure> structures;
100+
       long count= 0;
101+
       int successfullyRead = 0;
102+
       do {
103+
           try {
104+
               structures = parser.parseNext(MAX_PER_ITTERATION);
105+
               successfullyRead = structures.size();
106+
           } catch (IOException e) {
107+
               e.printStackTrace();
108+
           }
109+
           count += successfullyRead;
110+
           System.out.println("reached "+count);
111+
           
112+
           //use read structures
113+
           
114+
       } while (successfullyRead== MAX_PER_ITTERATION);
115+
       System.out.println("TOTAL COUNT = "+count);
116+
   }
109117

110118
```

0 commit comments

Comments
 (0)