UniProtFastaLoaderTask extends FastaLoaderTask { @Override protected Organism getOrganism(ProteinSequence bioJavaSequence) throws ObjectStoreException { String header = bioJavaSequence.getOriginalHeader(); final String regexp = "OS\\=(\\w+(\\s)*)*"; Pattern p = Pattern.compile(regexp); Matcher m = p.matcher(header); if (m.find()) { header = m.group(); header = cleanHeader(header); String[] bits = header.split("="); if (bits.length != 2) { return null; } String taxonId = getTaxonId(bits[1]); if (taxonId == null) { return null; } Organism org = organisms.get(taxonId); if (org == null) { org = getDirectDataLoader().createObject(Organism.class); org.setTaxonId(taxonId); getDirectDataLoader().store(org); organisms.put(taxonId, org); } return org; } return null; }    }
@Test public void testFastaLoad() throws Exception { UniProtFastaLoaderTask flt = new UniProtFastaLoaderTask(); flt.setTaxonId("7227"); flt.setIgnoreDuplicates(true); flt.setSequenceType("protein"); flt.setClassName("org.intermine.model.bio.Protein"); flt.setIntegrationWriterAlias("integration.bio-test"); flt.setSourceName("fasta-test"); flt.setDataSetTitle(dataSetTitle); flt.setDataSourceName(dataSourceName); flt.setClassAttribute("primaryAccession"); flt.setLicence(LICENCE); File[] files = new File[1]; files[0] = File.createTempFile("UniProtFastaLoaderTaskTest", "tmp"); FileWriter fw = new FileWriter(files[0]); InputStream is = getClass().getClassLoader().getResourceAsStream("uniprot.fasta"); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; while ((line = br.readLine()) != null) { fw.write(line + "\n"); } fw.close(); files[0].deleteOnExit(); flt.setFileArray(files); flt.execute(); flt.close(); ObjectStore os = osw.getObjectStore(); Query q = new Query(); QueryClass queryClass = new QueryClass(Protein.class); QueryClass seqQueryClass = new QueryClass(Sequence.class); q.addToSelect(queryClass); q.addToSelect(seqQueryClass); q.addFrom(queryClass); q.addFrom(seqQueryClass); QueryObjectReference qor = new QueryObjectReference(queryClass, "sequence"); ContainsConstraint cc = new ContainsConstraint(qor, ConstraintOp.CONTAINS, seqQueryClass); q.setConstraint(cc); Results r = os.execute(q); assertEquals(1, r.size()); Protein protein = (Protein) ((List) r.get(0)).get(0); assertEquals("Q9V8R9-2", protein.getPrimaryAccession()); "7227".equals(protein.getOrganism().getTaxonId()); DataSet dataSet = protein.getDataSets().iterator().next(); assertEquals(dataSetTitle, dataSet.getName()); assertEquals(dataSourceName, dataSet.getDataSource().getName()); assertEquals(LICENCE, dataSet.getLicence()); assertEquals("MPAEIKPSAPAEPETPTKSKPKSSSSSHGKPALARVTLLDGSLLDVSIDRKAIGRDVINS" + "ICAGLNLIEKDYFGLTYETPTDPRTWLDLEKPVSKFFRTDTWPLTFAVKFYPPEPSQLKE" + "DITRYHLCLQVRNDILEGRLPCTFVTHALLGSYLVQSEMGDYDAEEMPTRAYLKDFKIAP" + "NQTAELEDKVMDLHKTHKGQSPAEAELHYLENAKKLAMYGVDLHPAKDSEGVDIMLGVCA" + "SGLLVYRDKLRINRFAWPKILKISYKRHHFYIKIRPGEFEQYESTIGFKLANHRAAKKLW" + "KSCVEHHTFFRLMTPEPVSKSKMFPVFGSTYRYKGRTQAESTNTPVDRTPPKFNRTLSGA" + "RLTSRSMDALALAEKEKVARKSSTLDHRGDRNADGDAHSRSPIKNKKEKSSTGTASASSQ" + "SSLEGDYETNLEIEAIEAEPPVQDADKEAKLREKKQKEKEEKERKEREKRELEEKKKAEK" + "AAKAALAAGAAAGAAVNGNDELNDSNKSDKSSGRRVDPNDPRFAGARTTVTHTMTLTGEI" + "DPVTGRIKSEYGDIDPNTGDIDPATAVTDPVTGKLILNYAQIDPSHFGKQAQVQTTTETV" + "PITRQQFFDGVKHISKGALRRDSEGSSDDDMTAQYGADQVNEILIGSPAGQAGGKLGKPV" + "STPTVVKTTTKQVLTKNIDGVTHNVEEEVRNLGTGEVTYSTQEHKADATPTDLSGAYVTA" + "TAVTTRTATTHEDLGKNAKTEQLEEKTVATTRTHDPNKQQQRVVTQEVKTTATVTSGDQK" + "SPLFTTSATTGPHVESTRVVLGEDTPGFSGHGEIISTQTGGGGGGI", protein.getSequence().getResidues().toString()); }