Skip to content

Commit 5b1e359

Browse files
committed
[crypto][picocli]reworking the intermediate structures (step 1)
1 parent b572219 commit 5b1e359

File tree

15 files changed

+384
-204
lines changed

15 files changed

+384
-204
lines changed

biosilico-crypto/src/main/java/gabywald/crypto/data/BiologicalUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ public static String generateLocationOfSequence() {
245245

246246
public static GeneticTranslator getGenericCrypto(int file) {
247247
/** String fileName = (file == 0)?"genericCryptoASCIIJavaCPlus.txt":"genericCryptoAlphanumeric.txt"; */
248+
if (file < 0) { throw new ArrayIndexOutOfBoundsException("Negative Index !"); }
248249
GenericDataFile genericCryptoFile = (file == 0)? GenericDataFile.getCryptoASCIIJavaCPlus()
249250
:
250251
GenericDataFile.getCryptoAlphaNumeric();

biosilico-crypto/src/main/java/gabywald/crypto/model/GenBankFileReader.java renamed to biosilico-crypto/src/main/java/gabywald/crypto/data/composition/GenBankFileReader.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
package gabywald.crypto.model;
1+
package gabywald.crypto.data.composition;
22

33
import java.util.List;
44

55
import gabywald.crypto.data.BiologicalUtils;
66
import gabywald.crypto.data.GenBankFormat;
77
import gabywald.crypto.data.composition.FeaturesListe;
8+
import gabywald.crypto.model.GeneticTranslator;
89
import gabywald.global.data.StringUtils;
910

11+
/**
12+
* Aim of this class is to generate a GenBank file with encrypted data, from a file to read.
13+
* <br>Data is encrypted when included (content and path of file, respectively as proteomic and nucleotidic data).
14+
* <br>Encryption according to current "genetic encryption".
15+
* @author Gabriel Chandesris (2011, 2020, 2022, 2026)
16+
*/
1017
public class GenBankFileReader {
1118
private static final GeneticTranslator forFileContent = BiologicalUtils.getGenericCrypto(0);
1219
private static final GeneticTranslator forPathDirName = BiologicalUtils.getGenericCrypto(1);
@@ -15,7 +22,6 @@ public class GenBankFileReader {
1522
private String decodedPath;
1623
private String decodedContent;
1724

18-
1925
public GenBankFileReader()
2026
{ this.setContent(""); }
2127

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package gabywald.crypto.data.ioput;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import gabywald.crypto.data.BiologicalUtils;
7+
import gabywald.crypto.model.GeneticTranslator;
8+
9+
public abstract class AFileCryptoCreator implements IFileCryptoCreator {
10+
11+
protected GeneticTranslator forFileContent = BiologicalUtils.getGenericCrypto(0);
12+
protected GeneticTranslator forPathDirName = BiologicalUtils.getGenericCrypto(1);
13+
14+
private List<String> encodedPath;
15+
private List<String> encodedContent;
16+
17+
protected AFileCryptoCreator() {
18+
this.encodedPath = new ArrayList<String>();
19+
this.encodedContent = new ArrayList<String>();
20+
}
21+
22+
protected AFileCryptoCreator(String path, String content) {
23+
this();
24+
this.addPathAndContent(path, content);
25+
}
26+
27+
@Override
28+
public void addPathAndContent(String path, String content) {
29+
// this.encodedPath.add(path);
30+
// this.encodedContent.add(content);
31+
this.encodedPath.add( path.equals("") ? "" : this.forPathDirName.encode(path, 1) );
32+
this.encodedContent.add( content.equals("") ? "" : this.forFileContent.encode(content, 1));
33+
}
34+
35+
@Override
36+
public void setPathAndContent(String path, String content) {
37+
this.emptyPathAndContent();
38+
this.addPathAndContent(path, content);
39+
}
40+
41+
@Override
42+
public void emptyPathAndContent() {
43+
this.encodedPath = new ArrayList<String>();
44+
this.encodedContent = new ArrayList<String>();
45+
}
46+
47+
@Override
48+
public List<String> getEncodedPath() { return this.encodedPath; }
49+
50+
@Override
51+
public List<String> getEncodedCont() { return this.encodedContent; }
52+
53+
}
Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
package gabywald.crypto.data.ioput;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
5-
63
import gabywald.crypto.data.BiologicalFormat;
74

85
/**
96
*
10-
* @author Gabriel Chandesris (2020, 2022)
7+
* @author Gabriel Chandesris (2020, 2022, 2026)
118
*/
12-
public abstract class BiologicalFileCreator {
9+
public abstract class BiologicalFileCreator extends AFileCryptoCreator {
1310

1411
protected BiologicalFormat bioFormat;
1512

16-
protected List<String> encodedPath = new ArrayList<String>();
17-
protected List<String> encodedContent = new ArrayList<String>();
18-
1913
/**
2014
* Constructor with given path and content.
2115
* @param path
2216
* @param content
2317
*/
24-
protected BiologicalFileCreator(String path, String content) {
25-
if ( (path != null) && (! path.equals("")) )
26-
{ this.setPath(path); }
27-
if ( (content != null) && (! content.equals("")) )
28-
{ this.setContent(content); }
29-
}
18+
protected BiologicalFileCreator(String path, String content)
19+
{ super(path, content); }
3020

3121
/** Encryption takes place here ! */
3222
protected abstract void initialize();
@@ -36,37 +26,4 @@ public String getFullEncryption() {
3626
return this.bioFormat.toString();
3727
}
3828

39-
public List<String> getEncodedPath() { return this.encodedPath; }
40-
public List<String> getEncodedCont() { return this.encodedContent; }
41-
42-
public void setPathAndContent(String path, String content) {
43-
this.setPath(path);
44-
this.setContent(content);
45-
}
46-
47-
protected String setPath(String path) {
48-
this.encodedPath = new ArrayList<String>();
49-
return this.addPath(path);
50-
}
51-
52-
protected String setContent(String content) {
53-
this.encodedContent = new ArrayList<String>();
54-
return this.addContent(content);
55-
}
56-
57-
public void addPathAndContent(String path, String content) {
58-
this.addPath(path);
59-
this.addContent(content);
60-
}
61-
62-
private String addPath(String path) {
63-
this.encodedPath.add(path.equals("") ? "" : BiologicalFileCreatorHelper.forPathDirName.encode(path, 1) );
64-
return this.encodedPath.get(this.encodedPath.size() - 1);
65-
}
66-
67-
private String addContent(String content) {
68-
this.encodedContent.add(content.equals("") ? "" : BiologicalFileCreatorHelper.forFileContent.encode(content, 1) );
69-
return this.encodedContent.get(this.encodedContent.size() - 1);
70-
}
71-
7229
}

biosilico-crypto/src/main/java/gabywald/crypto/data/ioput/EmblFileCreator.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ protected void initialize() {
3838
this.bioFormat.setIdentification(identification);
3939

4040
int basePairNumber = 0;
41-
for (int i = 0 ; i < this.encodedContent.size() ; i++)
42-
{ basePairNumber += this.encodedContent.get(i).length(); }
41+
for (int i = 0 ; i < this.getEncodedCont().size() ; i++)
42+
{ basePairNumber += this.getEncodedCont().get(i).length(); }
4343
this.bioFormat.setBasePairNumber(""+basePairNumber);
4444

4545
String primaryType = BiologicalFileCreatorHelper.PRIMARY_TYPE
@@ -71,24 +71,24 @@ protected void initialize() {
7171

7272
/** References PART. */
7373
int numberOfRefs = StringUtils.randomValue(10)+1;
74-
for (int i = 0 ; (i < numberOfRefs) && (this.encodedContent.size() > 0) ; i++) {
75-
int selectCont = StringUtils.randomValue(this.encodedContent.size());
74+
for (int i = 0 ; (i < numberOfRefs) && (this.getEncodedCont().size() > 0) ; i++) {
75+
int selectCont = StringUtils.randomValue(this.getEncodedCont().size());
7676
int start = 0;
77-
int stopp = this.encodedContent.get(selectCont).length();
77+
int stopp = this.getEncodedCont().get(selectCont).length();
7878
for (int j = 0 ; j < selectCont ; j++)
79-
{ start += this.encodedContent.get(j).length(); }
79+
{ start += this.getEncodedCont().get(j).length(); }
8080

8181
this.bioFormat.addReference(BiologicalFileCreatorHelper.createReference(i, year, start, stopp));
8282
}
8383

8484
/** Sequence and Features PART. */
8585
String sequenceToRecord = new String("");
8686
int start = 0;
87-
for (int i = 0 ; i < this.encodedContent.size() ; i++) {
87+
for (int i = 0 ; i < this.getEncodedCont().size() ; i++) {
8888
/** Append... */
89-
sequenceToRecord += this.encodedContent.get(i);
89+
sequenceToRecord += this.getEncodedCont().get(i);
9090

91-
int length = this.encodedContent.get(i).length();
91+
int length = this.getEncodedCont().get(i).length();
9292
String pos = (start + 1)+".."+( start + 1 + length );
9393
// if (this.encodedPath.size() > 0) {
9494
// FeatureDefinition cds = FeatureDefinition.getFromFactory("CDS");

biosilico-crypto/src/main/java/gabywald/crypto/data/ioput/FastaFileCreator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ protected void initialize() {
3030
this.bioFormat.setAccession(identification);
3131

3232
int basePairNumber = 0;
33-
for (int i = 0 ; i < this.encodedContent.size() ; i++)
34-
{ basePairNumber += this.encodedContent.get(i).length(); }
33+
for (int i = 0 ; i < this.getEncodedCont().size() ; i++)
34+
{ basePairNumber += this.getEncodedCont().get(i).length(); }
3535
this.bioFormat.setBasePairNumber(""+basePairNumber);
3636

3737
String sequenceToRecord = new String("");
38-
for (int i = 0 ; i < this.encodedContent.size() ; i++) {
38+
for (int i = 0 ; i < this.getEncodedCont().size() ; i++) {
3939
/** Append... */
40-
sequenceToRecord += this.encodedContent.get(i);
40+
sequenceToRecord += this.getEncodedCont().get(i);
4141
}
4242
this.bioFormat.setSequence(new Sequence("", sequenceToRecord));
4343

biosilico-crypto/src/main/java/gabywald/crypto/data/ioput/GenBankFileCreator.java

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,32 @@
1414

1515
/**
1616
* Aim of this class is to generate a GenBank file with encrypted data.
17-
* <br>Data is encrypted when included (content and path of file, respectively as nucleotidic and proteomic data).
17+
* <br>Data is encrypted when included (content and path of file, respectively as proteomic and nucleotidic data).
1818
* <br>Encryption according to current "genetic encryption".
19-
* @author Gabriel Chandesris (2011, 2020)
19+
* @author Gabriel Chandesris (2011, 2020, 2022, 2026)
2020
*/
2121
public class GenBankFileCreator extends BiologicalFileCreator {
2222

23-
public GenBankFileCreator() {
24-
this("", "");
25-
}
26-
27-
public GenBankFileCreator(String string) {
28-
this("", string);
29-
}
23+
public GenBankFileCreator()
24+
{ this("", ""); }
3025

31-
/**
32-
* Constructor with given path and content.
33-
* @param path Path to a file.
34-
* @param content Content of a file.
35-
*/
36-
public GenBankFileCreator(String path, String content) {
26+
public GenBankFileCreator(String content)
27+
{ this("", content); }
28+
29+
public GenBankFileCreator(String path, String content) {
3730
super(path, content);
38-
this.bioFormat = new GenBankFormat();
31+
this.bioFormat = new GenBankFormat();
3932
}
40-
41-
@Override
33+
4234
protected void initialize() {
43-
4435
String identification = BiologicalUtils.generateIdentifier();
4536

4637
/** LOCUS PART. */
4738
this.bioFormat.setIdentification(identification);
4839

4940
int basePairNumber = 0;
50-
for (int i = 0 ; i < this.encodedContent.size() ; i++)
51-
{ basePairNumber += this.encodedContent.get(i).length(); }
41+
for (int i = 0 ; i < this.getEncodedCont().size() ; i++)
42+
{ basePairNumber += this.getEncodedCont().get(i).length(); }
5243
this.bioFormat.setBasePairNumber(""+basePairNumber);
5344

5445
String primaryType = BiologicalFileCreatorHelper.PRIMARY_TYPE
@@ -80,35 +71,35 @@ protected void initialize() {
8071

8172
/** References PART. */
8273
int numberOfRefs = StringUtils.randomValue(10)+1;
83-
for (int i = 0 ; (i < numberOfRefs) && (this.encodedContent.size() > 0) ; i++) {
84-
int selectCont = StringUtils.randomValue(this.encodedContent.size());
74+
for (int i = 0 ; (i < numberOfRefs) && (this.getEncodedCont().size() > 0) ; i++) {
75+
int selectCont = StringUtils.randomValue(this.getEncodedCont().size());
8576
int start = 0;
86-
int stopp = this.encodedContent.get(selectCont).length();
77+
int stopp = this.getEncodedCont().get(selectCont).length();
8778
for (int j = 0 ; j < selectCont ; j++)
88-
{ start += this.encodedContent.get(j).length(); }
79+
{ start += this.getEncodedCont().get(j).length(); }
8980

9081
this.bioFormat.addReference(BiologicalFileCreatorHelper.createReference(i, year, start, stopp));
9182
}
9283

9384
/** Sequence and Features PART. */
9485
String sequenceToRecord = new String("");
9586
int start = 0;
96-
for (int i = 0 ; i < this.encodedContent.size() ; i++) {
87+
for (int i = 0 ; i < this.getEncodedCont().size() ; i++) {
9788
/** Append... */
98-
sequenceToRecord += this.encodedContent.get(i);
89+
sequenceToRecord += this.getEncodedCont().get(i);
9990

100-
int length = this.encodedContent.get(i).length();
91+
int length = this.getEncodedCont().get(i).length();
10192
String pos = (start + 1)+".."+( start + 1 + length );
102-
if (this.encodedPath.size() > 0) {
93+
if (this.getEncodedPath().size() > 0) {
10394
FeatureDefinition cds = FeatureDefinition.getFromFactory("CDS");
10495
Feature featToAdd = new Feature(cds, pos);
10596
featToAdd.addQualifier("codon_start", (start + 1)+"");
10697
featToAdd.addQualifier("gene", location);
10798
featToAdd.addQualifier("product", "*****"); /** XXX !! */
108-
if (this.encodedPath.get(i).length() != 0)
109-
{ featToAdd.addQualifier("translation", this.encodedPath.get(i)); }
99+
if (this.getEncodedPath().get(i).length() != 0)
100+
{ featToAdd.addQualifier("translation", this.getEncodedPath().get(i)); }
110101
this.bioFormat.addFeature(featToAdd);
111-
} // END "if (this.encodedPath.size() > 0)"
102+
} // END "if (this.getEncodedPath().size() > 0)"
112103
start += length;
113104
FeatureDefinition src = FeatureDefinition.getFromFactory("source");
114105
Feature srcToAdd = new Feature(src, pos);
@@ -144,4 +135,10 @@ protected void initialize() {
144135
this.bioFormat.setBasesCountsAndNames(basesCounts, basesNames);
145136
}
146137

138+
public String getFullEncryption() {
139+
this.initialize();
140+
// this.bioFormat.setSequence(new Sequence("", this.encodedContent));
141+
return this.bioFormat.toString();
142+
}
143+
147144
}

biosilico-crypto/src/main/java/gabywald/crypto/data/ioput/GenBankFileReader.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@
22

33
import java.util.List;
44

5+
import gabywald.crypto.data.BiologicalUtils;
56
import gabywald.crypto.data.GenBankFormat;
67
import gabywald.crypto.data.composition.FeaturesListe;
8+
import gabywald.crypto.model.GeneticTranslator;
79
import gabywald.global.data.StringUtils;
810

911
/**
10-
*
11-
* @author Gabriel Chandesris (2011, 2020)
12+
* Aim of this class is to generate a GenBank file with encrypted data, from a file to read.
13+
* <br>Data is encrypted when included (content and path of file, respectively as proteomic and nucleotidic data).
14+
* <br>Encryption according to current "genetic encryption".
15+
* @author Gabriel Chandesris (2011, 2020, 2022, 2026)
1216
*/
1317
public class GenBankFileReader {
18+
private static final GeneticTranslator forFileContent = BiologicalUtils.getGenericCrypto(0);
19+
private static final GeneticTranslator forPathDirName = BiologicalUtils.getGenericCrypto(1);
20+
1421
private List<GenBankFormat> genBank;
1522
private String decodedPath;
1623
private String decodedContent;
1724

18-
1925
public GenBankFileReader()
2026
{ this.setContent(""); }
2127

@@ -33,13 +39,13 @@ public void setContent(String content) {
3339
FeaturesListe fl = currentGB.getFeatures().getFeaturesWith("CDS");
3440
for (int j = 0 ; j < fl.size() ; j++) {
3541
String encodedPath = fl.get(i).get("translation");
36-
this.decodedPath += BiologicalFileCreatorHelper.forPathDirName
42+
this.decodedPath += GenBankFileReader.forPathDirName
3743
.decodeWithStartStopCodons(encodedPath, 0, 0)+separator;
3844
}
3945

4046
String encodedContent = currentGB.getOrigin().getContent();
4147

42-
this.decodedContent += BiologicalFileCreatorHelper.forFileContent
48+
this.decodedContent += GenBankFileReader.forFileContent
4349
.decodeWithStartStopCodons(encodedContent, 0, 0)+separator;
4450
}
4551
}

0 commit comments

Comments
 (0)