Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/gff/GbffFile.java @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 68:5028fdace37b |
---|---|
1 package gff; | |
2 | |
3 import java.util.ArrayList; | |
4 | |
5 import fileIO.ByteFile; | |
6 import fileIO.ByteStreamWriter; | |
7 import fileIO.FileFormat; | |
8 import shared.Shared; | |
9 import shared.Tools; | |
10 | |
11 public class GbffFile { | |
12 | |
13 public static void main(String[] args){ | |
14 String gbff=args[0]; | |
15 String gff=(args.length>1 ? args[1] : "stdout.gff"); | |
16 | |
17 if(gbff.indexOf('=')>=0){gbff=gbff.split("=")[1];} | |
18 if(gff.indexOf('=')>=0){gff=gff.split("=")[1];} | |
19 | |
20 FileFormat ffin=FileFormat.testInput(gbff, ".gbff", true); | |
21 FileFormat ffout=FileFormat.testOutput(gff, FileFormat.GFF, null, true, true, false, false); | |
22 GbffFile file=new GbffFile(ffin); | |
23 ByteStreamWriter bsw=new ByteStreamWriter(ffout); | |
24 bsw.start(); | |
25 file.toGff(bsw, true); | |
26 bsw.poisonAndWait(); | |
27 } | |
28 | |
29 | |
30 // ##gff-version 3 | |
31 // #!gff-spec-version 1.21 | |
32 // #!processor NCBI annotwriter | |
33 // #!genome-build IMG-taxon 2724679794 annotated assembly | |
34 // #!genome-build-accession NCBI_Assembly:GCF_900182635.1 | |
35 // #!annotation-date 07/14/2019 01:52:19 | |
36 // #!annotation-source NCBI RefSeq | |
37 // ##sequence-region NZ_FXTD01000001.1 1 528269 | |
38 // ##species https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=413815 | |
39 | |
40 public void toGff(ByteStreamWriter bsw, boolean printHeader){ | |
41 if(printHeader){ | |
42 bsw.println("##gff-version 3".getBytes()); | |
43 bsw.println(("#BBTools "+Shared.BBMAP_VERSION_STRING+" GbffToGff").getBytes()); | |
44 bsw.println("#seqid source type start end score strand phase attributes".getBytes()); | |
45 } | |
46 for(GbffLocus locus=nextLocus(); locus!=null; locus=nextLocus()){ | |
47 locus.toGff(bsw); | |
48 } | |
49 } | |
50 | |
51 public GbffFile(FileFormat ff_) { | |
52 ff=ff_; | |
53 assert(ff.format()==FileFormat.GBFF) : ff; | |
54 reset(); | |
55 } | |
56 | |
57 public synchronized void reset(){ | |
58 if(bf!=null){ | |
59 bf.close(); | |
60 bf=null; | |
61 } | |
62 bf=ByteFile.makeByteFile(ff, FileFormat.GBFF); | |
63 line=bf.nextLine(); | |
64 if(line==null){bf.close();}//empty | |
65 } | |
66 | |
67 public GbffLocus nextLocus(){ | |
68 assert(bf!=null); | |
69 if(line==null){return null;} | |
70 assert(Tools.startsWith(line, "LOCUS ")) : "Expecting: 'LOCUS ...'\nGot: '"+new String(line)+"'"; | |
71 ArrayList<byte[]> lines=new ArrayList<byte[]>(); | |
72 lines.add(line); | |
73 boolean sequence=false; | |
74 for(line=bf.nextLine(); line!=null && (line.length==0 || line[0]!='L' || !Tools.startsWith(line, "LOCUS ")); line=bf.nextLine()){ | |
75 if(line.length>0){ | |
76 final byte b=line[0]; | |
77 if(b=='/'){ | |
78 //skip | |
79 }else if(b=='O' && Tools.startsWith(line, "ORIGIN ")){ | |
80 sequence=true; | |
81 }else if(b==' ' && sequence){ | |
82 //do nothing | |
83 }else{ | |
84 sequence=false; | |
85 lines.add(line); | |
86 } | |
87 } | |
88 } | |
89 if(line==null){bf.close();} | |
90 return new GbffLocus(lines); | |
91 } | |
92 | |
93 private final FileFormat ff; | |
94 private ByteFile bf; | |
95 private byte[] line=null; | |
96 | |
97 } |