Skip to content

Commit eb1c523

Browse files
committed
Included new module org.biojava.nbio.core.search.io files
1 parent 154edb7 commit eb1c523

File tree

15 files changed

+1135
-0
lines changed

15 files changed

+1135
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package org.biojava.nbio.core.search.io;
7+
8+
import org.biojava.nbio.core.search.io.blast.BlastXMLQuery;
9+
import java.io.File;
10+
import java.util.ArrayList;
11+
import java.util.LinkedHashMap;
12+
13+
/**
14+
*
15+
* @author pavanpa
16+
*/
17+
public class Examples {
18+
public static void main(String[] args) throws Exception {
19+
BlastXMLQuery blastXMLQuery = new BlastXMLQuery("E:\\output1668840459198813616tmp");
20+
LinkedHashMap<String, ArrayList<String>> hitsQueryDef = blastXMLQuery.getHitsQueryDef(1E-100);
21+
22+
System.out.println("SearchIO test.");
23+
ResultFactory blastResultFactory = new BlastXMLQuery();
24+
SearchIO reader = new SearchIO(new File("E:\\output1668840459198813616tmp"), blastResultFactory, 1E-100);
25+
26+
for (Result result: reader){
27+
System.out.println(result.getQueryDef()+"("+ result.getQueryID()+")");
28+
for (Hit hit: result){
29+
System.out.print(hit.getHitDef());
30+
System.out.print("(");
31+
for (Hsp hsp: hit){
32+
System.out.print(hsp.getHspEvalue()+",");
33+
}
34+
System.out.println(")");
35+
}
36+
37+
}
38+
}
39+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package org.biojava.nbio.core.search.io;
8+
9+
import java.util.ArrayList;
10+
import java.util.Iterator;
11+
import org.biojava.nbio.core.sequence.template.Sequence;
12+
13+
/**
14+
*
15+
* @author pavanpa
16+
*/
17+
public class Hit implements Iterable<Hsp>{
18+
private final int hitNum;
19+
private final String hitId;
20+
private final String hitDef;
21+
private final String hitAccession;
22+
private final int hitLen;
23+
private final ArrayList<Hsp> hsps;
24+
private Sequence hitSequence;
25+
26+
27+
28+
public Hit(int hitNum, String hitId, String hitDef, String hitAccession, int hitLen, ArrayList<Hsp> hsps, Sequence hitSequence) {
29+
this.hitNum = hitNum;
30+
this.hitId = hitId;
31+
this.hitDef = hitDef;
32+
this.hitAccession = hitAccession;
33+
this.hitLen = hitLen;
34+
this.hsps = hsps;
35+
this.hitSequence = hitSequence;
36+
}
37+
38+
public int getHitNum() {
39+
return hitNum;
40+
}
41+
42+
public String getHitId() {
43+
return hitId;
44+
}
45+
46+
public String getHitDef() {
47+
return hitDef;
48+
}
49+
50+
public String getHitAccession() {
51+
return hitAccession;
52+
}
53+
54+
public int getHitLen() {
55+
return hitLen;
56+
}
57+
58+
/**
59+
* returns the reference to the original and whole sequence hit in the database.
60+
* Available only if the ResultFactory implements setHitReferences and
61+
* it was used before the parsing with SearchIO
62+
* @return Sequence object
63+
*/
64+
public Sequence getHitSequence() {
65+
return hitSequence;
66+
}
67+
68+
@Override
69+
public Iterator<Hsp> iterator() {
70+
return new Iterator<Hsp>() {
71+
int current = 0;
72+
@Override
73+
public boolean hasNext() {
74+
return current < hsps.size();
75+
}
76+
77+
@Override
78+
public Hsp next() {
79+
return hsps.get(current++);
80+
}
81+
82+
@Override
83+
public void remove() {
84+
throw new UnsupportedOperationException("The remove operation is not supported by this iterator");
85+
}
86+
};
87+
}
88+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package org.biojava.nbio.core.search.io;
8+
9+
/**
10+
*
11+
* @author pavanpa
12+
*/
13+
public abstract class Hsp {
14+
private final int hspNum;
15+
private final double hspBitScore;
16+
private final int hspScore;
17+
private final double hspEvalue;
18+
private final int hspQueryFrom;
19+
private final int hspQueryTo;
20+
private final int hspHitFrom;
21+
private final int hspHitTo;
22+
23+
public int getHspNum() {
24+
return hspNum;
25+
}
26+
27+
public double getHspBitScore() {
28+
return hspBitScore;
29+
}
30+
31+
public int getHspScore() {
32+
return hspScore;
33+
}
34+
35+
public double getHspEvalue() {
36+
return hspEvalue;
37+
}
38+
39+
public int getHspQueryFrom() {
40+
return hspQueryFrom;
41+
}
42+
43+
public int getHspQueryTo() {
44+
return hspQueryTo;
45+
}
46+
47+
public int getHspHitFrom() {
48+
return hspHitFrom;
49+
}
50+
51+
public int getHspHitTo() {
52+
return hspHitTo;
53+
}
54+
55+
public int getHspQueryFrame() {
56+
return hspQueryFrame;
57+
}
58+
59+
public int getHspHitFrame() {
60+
return hspHitFrame;
61+
}
62+
63+
public int getHspIdentity() {
64+
return hspIdentity;
65+
}
66+
67+
public int getHspPositive() {
68+
return hspPositive;
69+
}
70+
71+
public int getHspGaps() {
72+
return hspGaps;
73+
}
74+
75+
public int getHspAlignLen() {
76+
return hspAlignLen;
77+
}
78+
/**
79+
* HSP aligned query sequence string
80+
* @return
81+
*/
82+
public String getHspQseq() {
83+
return hspQseq;
84+
}
85+
/**
86+
* HSP aligned hit sequence string
87+
* @return
88+
*/
89+
public String getHspHseq() {
90+
return hspHseq;
91+
}
92+
/**
93+
* Identity string representing correspondence between aligned residues
94+
* @return
95+
*/
96+
public String getHspIdentityString() {
97+
return hspIdentityString;
98+
}
99+
100+
101+
102+
public Hsp(int hspNum, double hspBitScore, int hspScore, double hspEvalue, int hspQueryFrom, int hspQueryTo, int hspHitFrom, int hspHitTo, int hspQueryFrame, int hspHitFrame, int hspIdentity, int hspPositive, int hspGaps, int hspAlignLen, String hspQseq, String hspHseq, String hspIdentityString) {
103+
this.hspNum = hspNum;
104+
this.hspBitScore = hspBitScore;
105+
this.hspScore = hspScore;
106+
this.hspEvalue = hspEvalue;
107+
this.hspQueryFrom = hspQueryFrom;
108+
this.hspQueryTo = hspQueryTo;
109+
this.hspHitFrom = hspHitFrom;
110+
this.hspHitTo = hspHitTo;
111+
this.hspQueryFrame = hspQueryFrame;
112+
this.hspHitFrame = hspHitFrame;
113+
this.hspIdentity = hspIdentity;
114+
this.hspPositive = hspPositive;
115+
this.hspGaps = hspGaps;
116+
this.hspAlignLen = hspAlignLen;
117+
this.hspQseq = hspQseq;
118+
this.hspHseq = hspHseq;
119+
this.hspIdentityString = hspIdentityString;
120+
}
121+
private int hspQueryFrame;
122+
private int hspHitFrame;
123+
private int hspIdentity;
124+
private int hspPositive;
125+
private int hspGaps;
126+
private int hspAlignLen;
127+
private String hspQseq;
128+
private String hspHseq;
129+
private String hspIdentityString;
130+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package org.biojava.nbio.core.search.io;
8+
9+
import java.io.Serializable;
10+
import java.util.ArrayList;
11+
import java.util.HashMap;
12+
import java.util.Iterator;
13+
import java.util.Set;
14+
import org.biojava.nbio.core.sequence.template.Sequence;
15+
16+
/**
17+
* This class models a search result.
18+
* You will find one of this for every query sequence specified in the run.
19+
* @author pavanpa
20+
*/
21+
public abstract class Result implements Iterable<Hit>{
22+
private String program;
23+
private String version;
24+
private String reference;
25+
private String dbFile;
26+
27+
private HashMap<String,String> programSpecificParameters;
28+
29+
private int iterationNumber;
30+
private String queryID;
31+
private String queryDef;
32+
private int queryLength;
33+
private Sequence querySequence;
34+
private ArrayList<Hit> hits;
35+
private int hitCounter = -1;
36+
37+
/*
38+
public Hit nextHit() {
39+
return(hits.get(hitCounter++));
40+
}
41+
*/
42+
43+
public Result(String program, String version, String reference, String dbFile, HashMap<String, String> programSpecificParameters, int iterationNumber, String queryID, String queryDef, int queryLength, ArrayList<Hit> hits, Sequence querySequence) {
44+
this.program = program;
45+
this.version = version;
46+
this.reference = reference;
47+
this.dbFile = dbFile;
48+
this.programSpecificParameters = programSpecificParameters;
49+
this.iterationNumber = iterationNumber;
50+
this.queryID = queryID;
51+
this.queryDef = queryDef;
52+
this.queryLength = queryLength;
53+
this.hits = hits;
54+
this.querySequence = querySequence;
55+
}
56+
57+
public int getIterationNumber() {
58+
return iterationNumber;
59+
}
60+
61+
public String getQueryID() {
62+
return queryID;
63+
}
64+
65+
public String getQueryDef() {
66+
return queryDef;
67+
}
68+
69+
public int getQueryLength() {
70+
return queryLength;
71+
}
72+
73+
public int getHitCounter() {
74+
return hitCounter;
75+
}
76+
77+
public String getProgram() {
78+
return program;
79+
}
80+
81+
public String getVersion() {
82+
return version;
83+
}
84+
85+
public String getReference() {
86+
return reference;
87+
}
88+
89+
public String getDbFile() {
90+
return dbFile;
91+
}
92+
93+
public Set<String> getProgramSpecificParametersList() {
94+
return programSpecificParameters.keySet();
95+
}
96+
97+
public String getProgramSpecificParameter(String key) {
98+
return programSpecificParameters.get(key);
99+
}
100+
/**
101+
* returns the reference th the original and whole sequence used to query the database.
102+
* Available only if the ResultFactory implements setQueryReferences and
103+
* it was used before the parsing with SearchIO
104+
* @return Sequence object
105+
*/
106+
public Sequence getQuerySequence() {
107+
return querySequence;
108+
}
109+
110+
@Override
111+
public Iterator<Hit> iterator() {
112+
return new Iterator<Hit>() {
113+
int currentResult = 0;
114+
@Override
115+
public boolean hasNext() {
116+
return currentResult < hits.size();
117+
}
118+
119+
@Override
120+
public Hit next() {
121+
return hits.get(currentResult++);
122+
}
123+
124+
@Override
125+
public void remove() {
126+
throw new UnsupportedOperationException("The remove operation is not supported by this iterator");
127+
}
128+
};
129+
}
130+
}

0 commit comments

Comments
 (0)