public static String buildQuery(SequenceI seq)
{
- String query = seq.getName();
- StringBuilder queryBuilder = new StringBuilder();
- int count = 0;
+ HashSet<String> seqRefs = new LinkedHashSet<String>();
+ String seqName = seq.getName();
+ String[] names = seqName.toLowerCase().split("\\|");
+ for (String name : names)
+ {
+ System.out.println("Found name : " + name);
+ name.trim();
+ if (isValidSeqName(name))
+ {
+ seqRefs.add(name);
+ }
+ }
if (seq.getPDBId() != null)
{
for (PDBEntry entry : seq.getPDBId())
{
- queryBuilder.append("text:").append(entry.getId()).append(" OR ");
+ seqRefs.add(entry.getId());
}
}
if (seq.getDBRef() != null && seq.getDBRef().length != 0)
{
+ int count = 0;
for (DBRefEntry dbRef : seq.getDBRef())
{
- queryBuilder.append("text:")
- .append(dbRef.getAccessionId().replaceAll("GO:", ""))
- .append(" OR ");
+ seqRefs.add(getDBRefId(dbRef));
++count;
if (count > 10)
{
break;
}
}
- int endIndex = queryBuilder.lastIndexOf(" OR ");
- query = queryBuilder.toString().substring(5, endIndex);
}
+
+ StringBuilder queryBuilder = new StringBuilder();
+ for (String seqRef : seqRefs)
+ {
+ queryBuilder.append("text:").append(seqRef).append(" OR ");
+ }
+ int endIndex = queryBuilder.lastIndexOf(" OR ");
+ String query = queryBuilder.toString().substring(5, endIndex);
return query;
}
/**
+ * Ensures sequence ref names are not less than 3 characters and does not
+ * contain a database name
+ *
+ * @param seqName
+ * @return
+ */
+ public static boolean isValidSeqName(String seqName)
+ {
+ String ignoreList = "pdb,uniprot";
+ if (seqName.length() < 3)
+ {
+ return false;
+ }
+ for (String ignoredEntry : ignoreList.split(","))
+ {
+ if (seqName.equalsIgnoreCase(ignoredEntry))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static String getDBRefId(DBRefEntry dbRef)
+ {
+ String ref = dbRef.getAccessionId().replaceAll("GO:", "");
+ return ref;
+ }
+
+ /**
* Filters a given list of discovered structures based on supplied argument
*
* @param fieldToFilterBy
@Before
public void setUp() throws Exception
{
- seq = new Sequence("Test_Seq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, 26);
+ seq = new Sequence("PDB|4kqy|4KQY|A", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1,
+ 26);
seq.setDatasetSequence(seq);
for (int x = 1; x < 5; x++)
{
@Test
public void buildQueryTest()
{
+ String query = StructureChooser.buildQuery(seq);
+ System.out.println(">>>>>>>>>> query : " + query);
assertEquals(
- "1tim OR text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4",
- StructureChooser.buildQuery(seq));
+ "4kqy OR text:1tim OR text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4",
+ query);
}
@Test
null);
sc.populateFilterComboBox();
int optionsSize = sc.getCmbFilterOption().getItemCount();
- assertEquals(2, optionsSize); // if structures are not discovered then don't
+ assertEquals(3, optionsSize); // if structures are not discovered then don't
// populate filter options
sc.setStructuresDiscovered(true);
sc.populateFilterComboBox();
optionsSize = sc.getCmbFilterOption().getItemCount();
- assertTrue(optionsSize > 2); // if structures are found, filter options
+ assertTrue(optionsSize > 3); // if structures are found, filter options
// should be populated
}