Created
May 17, 2022 19:50
-
-
Save variux/ad8f928990eaefaa09d76bc7c6c50f8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package biojava.biojava_project; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.io.PrintStream; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
import java.util.LinkedHashMap; | |
import java.util.List; | |
import org.biojava.nbio.core.sequence.DNASequence; | |
import org.biojava.nbio.core.sequence.compound.NucleotideCompound; | |
import org.biojava.nbio.core.sequence.features.FeatureInterface; | |
import org.biojava.nbio.core.sequence.io.GenbankReaderHelper; | |
import org.biojava.nbio.core.sequence.template.AbstractSequence; | |
public class SimpleRest { | |
public static void main(String[] args) throws Exception { | |
// Getting the protein ID | |
String [] protein_id = {"NP_414542.1"}; | |
// Defining the polarity of amino acids | |
String polar = "YSTNQCHRDEK"; | |
String Aliphatics = "AVLIPGR"; | |
String nonpolar = "AVLGIMWPF"; | |
String Aromatics ="WYFH"; | |
String Heterocyclics = "WHP"; | |
// Determining the amount of each amino acid | |
int numberpolar = 0; | |
int numberAliphatics = 0; | |
int numbernonpolar = 0; | |
int numberAromatics = 0; | |
int numberHeterocyclics = 0; | |
// Getting the gbff file - E. coli | |
File dnaFile = new File("/Users/andreszuniga/Downloads/ecoli.gbff"); | |
LinkedHashMap<String,DNASequence> dnaSequences = GenbankReaderHelper.readGenbankDNASequence(dnaFile, true); | |
PrintStream out; | |
// Output file with requested information | |
out = new PrintStream("/Users/andreszuniga/Downloads/output_eco.txt"); | |
for (DNASequence sequence : dnaSequences.values()) { | |
numberpolar = 0; | |
numberAliphatics = 0; | |
numbernonpolar = 0; | |
numberAromatics = 0; | |
numberHeterocyclics = 0; | |
int flag = 0; | |
String Protein_id = ""; | |
// Checking the protein inside the genome | |
for (int i = 0; i < protein_id.length; i++) { | |
System.out.println("Protein ID: " +protein_id[i]); | |
System.out.println("Prueba________________"); | |
System.out.println( sequence.getSequenceAsString() ); | |
List<FeatureInterface<AbstractSequence<NucleotideCompound>,NucleotideCompound>> | |
features = sequence.getFeatures(); | |
for (int j = 0; j < features.size(); j++) { | |
if (features.get(j).getDescription().equals("CDS")) { | |
Protein_id = features.get(j).getQualifiers().values().toArray()[3].toString().split("'")[3]; | |
} | |
else { | |
continue; | |
} | |
if (protein_id[i].equals(Protein_id)) { | |
flag = 1; | |
System.out.println("Information of protein: "); | |
System.out.println("____________________________________________"); | |
// Printing the length of protein sequence | |
System.out.println("Length: " + sequence.getLength()); | |
// Printing the description of protein | |
System.out.println("Description: " +features.get(j).getDescription()); | |
// Getting the qualifiers | |
System.out.println("Protein ID: " + features.get(j).getQualifiers().values().toArray()[3].toString().split("'")[3]); | |
String a = features.get(j).getQualifiers().values().toArray()[3].toString().split("'")[3]; | |
String protein = a.split("\\.")[0]; | |
System.out.println(protein); | |
System.out.println("Gen: "+features.get(j).getQualifiers().values().toArray()[4].toString().split("'")[3]); | |
String aminosequence = features.get(j).getQualifiers().values().toArray()[6].toString().split("'")[3]; | |
// Verifying the amino acids inside genome | |
for (int q = 0; q<aminosequence.split("").length; q+=1) { | |
for (int p = 0; p<polar.split("").length;p+=1) { | |
if (aminosequence.split("")[q].equals(polar.split("")[p])) { | |
numberpolar += 1; | |
} | |
} | |
for (int a_a = 0; a_a<Aliphatics.split("").length;a_a+=1) { | |
if (aminosequence.split("")[q].equals(Aliphatics.split("")[a_a])) { | |
numberAliphatics += 1; | |
} | |
} | |
for (int np = 0; np<nonpolar.split("").length;np+=1) { | |
if (aminosequence.split("")[q].equals(nonpolar.split("")[np])) { | |
numbernonpolar += 1; | |
} | |
} | |
for (int ar = 0; ar<Aromatics.split("").length;ar+=1) { | |
if (aminosequence.split("")[q].equals(Aromatics.split("")[ar])) { | |
numberAromatics += 1; | |
} | |
} | |
for (int w = 0; w<Heterocyclics.split("").length;w+=1) { | |
if (aminosequence.split("")[q].equals(Heterocyclics.split("")[w])) { | |
numberHeterocyclics += 1; | |
} | |
} | |
} | |
System.out.println("Information about amino acids: "); | |
System.out.println("____________________________________________"); | |
System.out.println("Amount of Non Polars: "+ numbernonpolar); | |
System.out.println("Amount of Polars: "+ numberpolar); | |
System.out.println("Amount of Aliphatics: "+ numberAliphatics); | |
System.out.println("Amount of Aromatics: "+ numberAromatics); | |
System.out.println("Amount of Heterocyclics: "+ numberHeterocyclics); | |
numberpolar = 0; | |
numberAliphatics = 0; | |
numbernonpolar = 0; | |
numberAromatics = 0; | |
numberHeterocyclics = 0; | |
int pol = numbernonpolar; | |
System.out.println("Val pol: " +pol); | |
int alif = numberAromatics; | |
System.out.println("Val alif: "+ alif); | |
System.out.println("Relation No Polar / Aromatics: "+pol); | |
System.out.println("Relation Aromatics: "+numberAromatics); | |
System.out.println("Relation Heterocyclics: "+numberHeterocyclics); | |
System.out.println("Relation Aromatics / Heterocyclics: "+alif); | |
// Request information in KEGG Database | |
String request = "http://rest.kegg.jp/conv/eco/ncbi-proteinid:"+protein; | |
System.out.println(request); | |
String str =""; | |
try { | |
str = httpGet(request); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
String KEGG_ferment = str.split(" ")[1]; | |
// Requesting in KEGG using the protein ID | |
String request2 = "http://rest.kegg.jp/link/pathway/"+KEGG_ferment; | |
System.out.println(request2); | |
// Getting the amino acids properties from KEGG data base | |
try { | |
out.print(features.get(j).getQualifiers().keySet().toArray()[2]); | |
out.println(" "+features.get(j).getQualifiers().values().toArray()[2].toString().split("'")[3]); | |
out.println(features.get(j).getQualifiers().values().toArray()[4].toString().split("'")[3]); | |
out.println(); | |
out.println("Number of Non Polar Amino Acids: "+numbernonpolar); | |
out.println("Relation No Polar / Aromatics: "+pol); | |
out.println("Number of Aromatics: "+numberAromatics); | |
out.println("Number of Heterocyclics: " +numberHeterocyclics); | |
out.println("Relation Aromatics / Heterocyclics: "+alif); | |
out.println(); | |
out.println("YYYYYYY"); | |
String str2 = httpGet(request2); | |
for (int k = 1; k<str2.split(KEGG_ferment+" ").length; k+=1) { | |
System.out.println(str2.split(KEGG_ferment+" ")[k]); | |
String request3 = "http://rest.kegg.jp/list/" + str2.split(KEGG_ferment+" ")[k]; | |
String str3 = httpGet(request3); | |
System.out.println(str3); | |
out.println(str3); | |
} | |
out.println("______________________________________________________________________________________"); | |
out.println(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
System.out.println(); | |
} | |
} | |
if (flag == 0) { | |
System.out.println("XXXXXXXX"); | |
System.out.println(); | |
} | |
} | |
} | |
out.close(); | |
} | |
public static String httpGet(String urlStr) throws IOException { | |
URL url = new URL(urlStr); | |
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | |
if (conn.getResponseCode() != 200) { | |
throw new IOException(conn.getResponseMessage()); | |
} // Buffer the result into a string | |
BufferedReader rd = new BufferedReader(new InputStreamReader( | |
conn.getInputStream())); | |
StringBuilder sb = new StringBuilder(); | |
String line; | |
while ((line = rd.readLine()) != null) { | |
sb.append(line); | |
} | |
rd.close(); | |
conn.disconnect(); | |
return sb.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment