Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2XB3FinalProject
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christopher Schankula
2XB3FinalProject
Commits
829eb44f
Commit
829eb44f
authored
7 years ago
by
Christopher Schankula
Browse files
Options
Downloads
Patches
Plain Diff
first draft of BioTree building function (processTaxonId)
parent
8b18b933
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/biotree/BioTree.java
+50
-8
50 additions, 8 deletions
src/biotree/BioTree.java
with
50 additions
and
8 deletions
src/biotree/BioTree.java
+
50
−
8
View file @
829eb44f
...
...
@@ -2,18 +2,36 @@ package biotree;
import
java.io.IOException
;
import
org.json.simple.parser.ParseException
;
import
search.BST
;
public
class
BioTree
{
private
static
BST
<
Integer
,
TaxonNode
>
nodes
;
private
static
int
n
;
public
static
void
main
(
String
[]
args
)
{
init
();
processRecord
(
125125
);
processRecord
(
125125
);
processRecord
(
125123
);
processRecord
(
125122
);
processRecord
(
125392
);
processRecord
(
125391
);
System
.
out
.
println
(
nodes
.
size
());
System
.
out
.
println
(
nodes
.
get
(
123207
));
Iterable
<
Integer
>
keys
=
nodes
.
keys
();
for
(
Integer
i:
keys
)
{
System
.
out
.
println
(
nodes
.
get
(
i
));
//System.out.println(String.format("%-26s %s", nodes.get(i).getName(), nodes.get(i).getTaxonType()));
}
printTree
(
nodes
.
get
(
2
),
0
);
}
/**
* Initialize species abstract object
*/
public
static
void
init
()
{
nodes
=
new
BST
<
Integer
,
TaxonNode
>();
n
=
0
;
}
/**
...
...
@@ -67,17 +85,34 @@ public class BioTree {
* @param taxonId
*/
private
static
void
processTaxonId
(
int
taxonId
)
{
TaxonNode
[]
newNodes
=
WormsAPI
.
idToClassification
(
taxonId
);
for
(
int
i
=
newNodes
.
length
-
1
;
i
>
0
;
i
--)
{
TaxonNode
tx
=
newNodes
[
i
];
TaxonNode
[]
newNodes
=
null
;
try
{
newNodes
=
WormsAPI
.
idToClassification
(
taxonId
);
}
catch
(
IOException
|
ParseException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
TaxonNode
tx
=
nodes
.
get
(
newNodes
[
newNodes
.
length
-
1
].
getTaxonId
());
if
(
tx
!=
null
)
{
tx
.
incCount
();
}
else
{
newNodes
[
newNodes
.
length
-
1
].
incCount
();
}
for
(
int
i
=
newNodes
.
length
-
1
;
i
>=
0
;
i
--)
{
tx
=
newNodes
[
i
];
TaxonNode
result
=
nodes
.
get
(
tx
.
getTaxonId
());
TaxonNode
parent
=
nodes
.
get
(
newNodes
[
i
-
1
].
getTaxonId
());
if
(
parent
==
null
)
parent
=
newNodes
[
i
-
1
];
TaxonNode
parent
=
null
;
if
(
i
>
0
)
{
parent
=
nodes
.
get
(
newNodes
[
i
-
1
].
getTaxonId
());
if
(
parent
==
null
)
parent
=
newNodes
[
i
-
1
];
}
if
(
result
==
null
)
{
//if node is not found, add it
nodes
.
put
(
tx
.
getTaxonId
(),
tx
);
tx
.
setParent
(
parent
);
parent
.
addChild
(
tx
);
if
(
parent
!=
null
)
parent
.
addChild
(
tx
);
}
else
break
;
//stop loop if this node already exists in the tree
}
}
...
...
@@ -91,4 +126,11 @@ public class BioTree {
public
static
TaxonNode
getTaxonRecord
(
int
taxonId
)
{
return
nodes
.
get
(
taxonId
);
}
public
static
void
printTree
(
TaxonNode
tx
,
int
level
)
{
String
padd
=
new
String
(
new
char
[
level
*
4
]).
replace
(
'\0'
,
' '
);
System
.
out
.
format
(
padd
+
"%s %d\n"
,
tx
.
getName
(),
tx
.
getCount
());
for
(
TaxonNode
tx2:
tx
.
getChildren
())
printTree
(
tx2
,
level
+
1
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment