GenericFastaHeaderParser implements FastaHeaderParserInterface<S,C> { public void parseHeader(String header, S sequence) { sequence.setOriginalHeader(header); String[] data = getHeaderValues(header); if (data.length == 1) { sequence.setAccession(new AccessionID(data[0])); } else if (data[0].equalsIgnoreCase("sp") || data[0].equalsIgnoreCase("tr")) { if (data[0].equalsIgnoreCase("sp")) { sequence.setAnnotationType(AnnotationType.CURATED); } else { sequence.setAnnotationType(AnnotationType.PREDICTED); } sequence.setAccession(new AccessionID(data[1], DataSource.UNIPROT)); if (data.length > 1) { sequence.setDescription(data[2]); } } else if (data[0].equalsIgnoreCase("gi")) { DataSource giSource = DataSource.UNKNOWN; if (data.length >= 3) { if (data[2].equalsIgnoreCase("gb")) { giSource = DataSource.GENBANK; } else if (data[2].equalsIgnoreCase("emb")) { giSource = DataSource.ENA; } else if (data[2].equalsIgnoreCase("dbj")) { giSource = DataSource.DDBJ; } sequence.setAccession(new AccessionID(data[3], giSource)); } else { sequence.setAccession(new AccessionID(header, giSource)); } } else if (data[0].equalsIgnoreCase("pir")) { sequence.setAccession(new AccessionID(data[2], DataSource.NBRF)); } else if (data[0].equalsIgnoreCase("prf")) { sequence.setAccession(new AccessionID(data[2], DataSource.PRF)); } else if (data[0].equalsIgnoreCase("pdb")) { sequence.setAccession(new AccessionID(data[1] + ":" + data[2], DataSource.PDB1)); } else if (data[0].startsWith("PDB")) { String[] pdbe = data[0].split(" "); String[] pdbaccession = pdbe[0].split(":"); sequence.setAccession(new AccessionID(pdbaccession[1], DataSource.PDBe)); } else if (data[0].indexOf(":") != -1 && data.length > 1 && data[1].equals("PDBID")) { sequence.setAccession(new AccessionID(data[0], DataSource.PDB2)); } else if (data[0].equalsIgnoreCase("pat")) { sequence.setAccession(new AccessionID(data[2], DataSource.PATENTS)); } else if (data[0].equalsIgnoreCase("bbs")) { sequence.setAccession(new AccessionID(data[1], DataSource.GENINFO)); } else if (data[0].equalsIgnoreCase("gnl")) { sequence.setAccession(new AccessionID(data[2], DataSource.GENERAL)); } else if (data[0].equalsIgnoreCase("ref")) { sequence.setAccession(new AccessionID(data[1], DataSource.NCBI)); } else if (data[0].equalsIgnoreCase("lcl")) { sequence.setAccession(new AccessionID(data[1], DataSource.LOCAL)); } else { sequence.setAccession(new AccessionID(data[0])); } }  void parseHeader(String header, S sequence); static void main(String[] args);  }
@Test public void testParseHeader() { System.out.println("parseHeader"); String header = ""; ProteinSequence sequence = new ProteinSequence(""); GenericFastaHeaderParser<ProteinSequence,AminoAcidCompound> instance = new GenericFastaHeaderParser<ProteinSequence,AminoAcidCompound>(); header = "gi|gi-number|gb|accession|locus"; instance.parseHeader(header, sequence); assertEquals("accession", sequence.getAccession().getID()); assertEquals(sequence.getAccession().getDataSource(), DataSource.GENBANK); header = "gi|gi-number|emb|accession|locus"; instance.parseHeader(header, sequence); assertEquals("accession", sequence.getAccession().getID()); assertEquals(sequence.getAccession().getDataSource(), DataSource.ENA); header = "gi|gi-number|dbj|accession|locus"; instance.parseHeader(header, sequence); assertEquals("accession", sequence.getAccession().getID()); assertEquals(sequence.getAccession().getDataSource(), DataSource.DDBJ); header = "pir||entry"; instance.parseHeader(header, sequence); assertEquals("entry", sequence.getAccession().getID()); assertEquals(sequence.getAccession().getDataSource(), DataSource.NBRF); header = "prf||name"; instance.parseHeader(header, sequence); assertEquals("name", sequence.getAccession().getID()); assertEquals(sequence.getAccession().getDataSource(), DataSource.PRF); header = "sp|accession|name"; instance.parseHeader(header, sequence); assertEquals("accession", sequence.getAccession().getID()); assertEquals(sequence.getAccession().getDataSource(), DataSource.UNIPROT); header = "pdb|entry|chain"; instance.parseHeader(header, sequence); assertEquals("entry:chain", sequence.getAccession().getID()); assertEquals(sequence.getAccession().getDataSource(), DataSource.PDB1); header = "entry:chain|PDBID|CHAIN|SEQUENCE"; instance.parseHeader(header, sequence); assertEquals("entry:chain", sequence.getAccession().getID()); assertEquals(sequence.getAccession().getDataSource(), DataSource.PDB2); header = "PDB:1ECY_A mol:protein length:142 ECOTIN"; instance.parseHeader(header, sequence); assertEquals("1ECY_A", sequence.getAccession().getID()); assertEquals(sequence.getAccession().getDataSource(), DataSource.PDBe); header = "pat|country|number"; instance.parseHeader(header, sequence); assertEquals("number", sequence.getAccession().getID()); assertEquals(sequence.getAccession().getDataSource(), DataSource.PATENTS); header = "bbs|number"; instance.parseHeader(header, sequence); assertEquals("number", sequence.getAccession().getID()); assertEquals(sequence.getAccession().getDataSource(), DataSource.GENINFO); header = "gnl|database|identifier"; instance.parseHeader(header, sequence); assertEquals("identifier", sequence.getAccession().getID()); assertEquals(sequence.getAccession().getDataSource(), DataSource.GENERAL); header = "ref|accession|locus"; instance.parseHeader(header, sequence); assertEquals("accession", sequence.getAccession().getID()); assertEquals(sequence.getAccession().getDataSource(), DataSource.NCBI); header = "lcl|identifier"; instance.parseHeader(header, sequence); assertEquals("identifier", sequence.getAccession().getID()); assertEquals(sequence.getAccession().getDataSource(), DataSource.LOCAL); }